analyzer

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package analyzer defines the core analyzer interfaces.

Index

Constants

View Source
const (
	// ProfileQuick provides fast analysis with minimal overhead.
	ProfileQuick = libanalyzer.ProfileQuick
	// ProfileStandard provides balanced analysis (default).
	ProfileStandard = libanalyzer.ProfileStandard
	// ProfileDetailed provides comprehensive analysis for deep investigation.
	ProfileDetailed = libanalyzer.ProfileDetailed
)

Profile constants — aliases to perflib/analyzer.

View Source
const (
	ModeJavaCPU        = libanalyzer.ModeJavaCPU
	ModeJavaAlloc      = libanalyzer.ModeJavaAlloc
	ModeJavaWall       = libanalyzer.ModeJavaWall
	ModeJavaLock       = libanalyzer.ModeJavaLock
	ModeJavaHeap       = libanalyzer.ModeJavaHeap
	ModeCPU            = libanalyzer.ModeCPU
	ModePProfCPU       = libanalyzer.ModePProfCPU
	ModePProfHeap      = libanalyzer.ModePProfHeap
	ModePProfGoroutine = libanalyzer.ModePProfGoroutine
	ModePProfBlock     = libanalyzer.ModePProfBlock
	ModePProfMutex     = libanalyzer.ModePProfMutex
	ModePProfAll       = libanalyzer.ModePProfAll
	ModeJeprof         = libanalyzer.ModeJeprof
)

Mode constants — aliases to perflib/analyzer.

Variables

View Source
var (
	// ErrUnsupportedMode is returned when an unknown analysis mode is specified.
	ErrUnsupportedMode = libanalyzer.ErrUnsupportedMode

	// ErrParseError is returned when parsing profiling data fails.
	ErrParseError = libanalyzer.ErrParseError

	// ErrEmptyData is returned when profiling data is empty.
	ErrEmptyData = libanalyzer.ErrEmptyData

	// ErrAnalysisFailed is returned when analysis fails.
	ErrAnalysisFailed = libanalyzer.ErrAnalysisFailed

	// ErrContextCanceled is returned when the context is canceled.
	ErrContextCanceled = libanalyzer.ErrContextCanceled
)

Error variables are aliases to perflib/analyzer errors, ensuring error identity (errors.Is) works correctly across layers.

Functions

func SortClassesByCount

func SortClassesByCount(classes []*hprof.ClassStats)

SortClassesByCount sorts classes by instance count in descending order.

func SortClassesBySize

func SortClassesBySize(classes []*hprof.ClassStats)

SortClassesBySize sorts classes by total size in descending order.

func ValidModes

func ValidModes() string

ValidModes returns a comma-separated list of valid mode names.

Types

type AnalysisMode

type AnalysisMode = libanalyzer.AnalysisMode

AnalysisMode represents a user-friendly analysis mode. It maps directly to the model.AnalysisMode("{profiler}-{event}") composite key.

func ParseMode

func ParseMode(s string) (AnalysisMode, error)

ParseMode parses a mode string into AnalysisMode.

type AnalysisProfile

type AnalysisProfile = libanalyzer.AnalysisProfile

AnalysisProfile defines preset analysis configurations for different use cases. It is a type alias to the perflib analyzer AnalysisProfile.

type Analyzer

type Analyzer interface {
	// Analyze performs the analysis on the given request.
	Analyze(ctx context.Context, req *model.AnalysisRequest) (*model.AnalysisResponse, error)

	// AnalyzeFromReader performs the analysis using a reader.
	AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

	// Name returns the name of this analyzer.
	Name() string
}

Analyzer is the interface for all profiling data analyzers.

type AnalyzerConstructor

type AnalyzerConstructor func(config *BaseAnalyzerConfig) Analyzer

AnalyzerConstructor is a function that creates an Analyzer from config.

type BaseAnalyzer

type BaseAnalyzer struct {
	*libanalyzer.BaseAnalyzer
	// contains filtered or unexported fields
}

BaseAnalyzer provides common functionality for all analyzers. It embeds the perflib BaseAnalyzer engine and delegates all pure analysis methods. Business-specific methods (EnsureOutputDir with taskUUID) are kept locally.

func NewBaseAnalyzer

func NewBaseAnalyzer(config *BaseAnalyzerConfig) *BaseAnalyzer

NewBaseAnalyzer creates a new base analyzer.

func (*BaseAnalyzer) EnsureOutputDir

func (a *BaseAnalyzer) EnsureOutputDir(taskUUID string) (string, error)

EnsureOutputDir ensures the output directory exists. This is a business-specific method that uses taskUUID as the subdirectory name. The perflib version uses a descriptive subDir name (e.g., "cpu-analysis").

type BaseAnalyzerConfig

type BaseAnalyzerConfig struct {
	// OutputDir is the directory for output files.
	OutputDir string

	// FlameGraphOptions configures flame graph generation.
	FlameGraphOptions *flamegraph.GeneratorOptions

	// CallGraphOptions configures call graph generation.
	CallGraphOptions *callgraph.GeneratorOptions

	// TopFuncsN configures top functions calculation.
	TopFuncsN int

	// IncludeSwapper includes swapper thread in statistics.
	IncludeSwapper bool

	// Logger is used for debug logging. If nil, debug logs are suppressed.
	Logger utils.Logger

	// Verbose enables verbose debug output including detailed analysis.
	// This is typically enabled via the -v command line flag.
	Verbose bool

	// AnalysisProfile selects preset analysis configuration.
	AnalysisProfile AnalysisProfile
}

BaseAnalyzerConfig holds configuration for the base analyzer. It uses utils.Logger (business layer) instead of perflib.Logger.

func DefaultBaseAnalyzerConfig

func DefaultBaseAnalyzerConfig() *BaseAnalyzerConfig

DefaultBaseAnalyzerConfig returns default configuration.

type BatchAnalysisResult

type BatchAnalysisResult struct {
	BaseDir      string                             `json:"base_dir"`
	OutputDir    string                             `json:"output_dir"`
	AnalyzedAt   time.Time                          `json:"analyzed_at"`
	ProfileSets  map[string]*ProfileSetResult       `json:"profile_sets"`
	LeakReports  map[string]*pprofparser.LeakReport `json:"leak_reports,omitempty"`
	TotalSamples int64                              `json:"total_samples"`
}

BatchAnalysisResult represents the complete batch analysis result. Retained for backward compatibility.

type ClassHistogram

type ClassHistogram struct {
	TotalClasses   int                 `json:"total_classes"`
	TotalInstances int64               `json:"total_instances"`
	TotalSize      int64               `json:"total_size"`
	Classes        []*hprof.ClassStats `json:"classes"`
}

ClassHistogram represents a class histogram report.

type DominatorNode

type DominatorNode struct {
	ClassName    string           `json:"class_name"`
	ObjectID     uint64           `json:"object_id,omitempty"`
	ShallowSize  int64            `json:"shallow_size"`
	RetainedSize int64            `json:"retained_size"`
	Children     []*DominatorNode `json:"children,omitempty"`
}

DominatorNode represents a node in the dominator tree.

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory creates analyzers based on analysis mode using a registry of constructors.

func NewFactory

func NewFactory(config *BaseAnalyzerConfig) *Factory

NewFactory creates a new analyzer factory with built-in constructors.

func (*Factory) CreateAnalyzerForMode

func (f *Factory) CreateAnalyzerForMode(mode AnalysisMode) (Analyzer, error)

CreateAnalyzerForMode creates an analyzer for the given analysis mode.

func (*Factory) RegisterConstructor

func (f *Factory) RegisterConstructor(mode AnalysisMode, ctor AnalyzerConstructor)

RegisterConstructor registers a custom constructor for a mode. This can be used to override built-in constructors or add new modes at runtime.

type HeapAnalysisReport

type HeapAnalysisReport struct {
	Summary       *model.HeapAnalysisData `json:"summary"`
	TopClasses    []*hprof.ClassStats     `json:"top_classes"`
	Suggestions   []model.SuggestionItem  `json:"suggestions"`
	DominatorTree *HeapDominatorTree      `json:"dominator_tree,omitempty"`
}

HeapAnalysisReport represents the complete heap analysis report.

type HeapDominatorTree

type HeapDominatorTree struct {
	Roots []*DominatorNode `json:"roots"`
}

HeapDominatorTree represents a dominator tree for retained size analysis.

type JavaCPUAnalyzer

type JavaCPUAnalyzer struct {
	// contains filtered or unexported fields
}

JavaCPUAnalyzer analyzes Java async-profiler CPU data. It delegates to the perflib engine and adapts the business model.

func NewJavaCPUAnalyzer

func NewJavaCPUAnalyzer(config *BaseAnalyzerConfig) *JavaCPUAnalyzer

NewJavaCPUAnalyzer creates a new Java CPU analyzer.

func (*JavaCPUAnalyzer) Analyze

Analyze performs Java CPU profiling analysis using an input file.

func (*JavaCPUAnalyzer) AnalyzeFromReader

func (a *JavaCPUAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs Java CPU profiling analysis from a reader.

func (*JavaCPUAnalyzer) GetOutputFiles

func (a *JavaCPUAnalyzer) GetOutputFiles(taskUUID, taskDir string) []model.OutputFile

GetOutputFiles returns the list of output files generated by the analyzer. This is a business-only method that constructs COSKey from TaskUUID.

func (*JavaCPUAnalyzer) Name

func (a *JavaCPUAnalyzer) Name() string

Name returns the analyzer name.

type JavaHeapAnalyzer

type JavaHeapAnalyzer struct {
	// contains filtered or unexported fields
}

JavaHeapAnalyzer analyzes Java heap dump (HPROF) files. It delegates to the perflib engine and adapts the business model.

func NewJavaHeapAnalyzer

func NewJavaHeapAnalyzer(config *BaseAnalyzerConfig, opts ...JavaHeapAnalyzerOption) *JavaHeapAnalyzer

NewJavaHeapAnalyzer creates a new Java heap analyzer.

func (*JavaHeapAnalyzer) Analyze

Analyze performs Java heap dump analysis using an input file.

func (*JavaHeapAnalyzer) AnalyzeFromReader

func (a *JavaHeapAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs Java heap dump analysis from a reader.

func (*JavaHeapAnalyzer) GetOutputFiles

func (a *JavaHeapAnalyzer) GetOutputFiles(taskUUID, taskDir string) []model.OutputFile

GetOutputFiles returns the list of output files generated by the analyzer. This is a business-only method that constructs COSKey from TaskUUID.

func (*JavaHeapAnalyzer) Name

func (a *JavaHeapAnalyzer) Name() string

Name returns the analyzer name.

type JavaHeapAnalyzerOption

type JavaHeapAnalyzerOption func(*JavaHeapAnalyzer)

JavaHeapAnalyzerOption configures the JavaHeapAnalyzer.

type JavaMemAnalyzer

type JavaMemAnalyzer struct {
	// contains filtered or unexported fields
}

JavaMemAnalyzer analyzes Java async-profiler allocation/memory data. It delegates to the perflib engine and adapts the business model.

func NewJavaMemAnalyzer

func NewJavaMemAnalyzer(config *BaseAnalyzerConfig) *JavaMemAnalyzer

NewJavaMemAnalyzer creates a new Java memory analyzer.

func (*JavaMemAnalyzer) Analyze

Analyze performs Java memory profiling analysis using an input file.

func (*JavaMemAnalyzer) AnalyzeFromReader

func (a *JavaMemAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs Java memory profiling analysis from a reader.

func (*JavaMemAnalyzer) GetOutputFiles

func (a *JavaMemAnalyzer) GetOutputFiles(taskUUID, taskDir string) []model.OutputFile

GetOutputFiles returns the list of output files generated by the analyzer. This is a business-only method that constructs COSKey from TaskUUID.

func (*JavaMemAnalyzer) Name

func (a *JavaMemAnalyzer) Name() string

Name returns the analyzer name.

type ModeInfo

type ModeInfo struct {
	Mode        AnalysisMode
	Description string
	InputFormat string
	Profiler    model.Profiler
	Event       model.EventType
	Resource    model.ResourceType
}

ModeInfo describes an analysis mode for help, validation, and dispatch.

func AllModes

func AllModes() []*ModeInfo

AllModes returns all registered mode information.

func GetModeInfo

func GetModeInfo(mode AnalysisMode) (*ModeInfo, bool)

GetModeInfo returns the metadata for a mode. It delegates to perflib and converts the result to the local ModeInfo type.

type PProfBatchAnalyzer

type PProfBatchAnalyzer struct {
	// contains filtered or unexported fields
}

PProfBatchAnalyzer analyzes a directory of pprof files. It delegates to the perflib engine and adapts the business model.

func NewPProfBatchAnalyzer

func NewPProfBatchAnalyzer(config *BaseAnalyzerConfig) *PProfBatchAnalyzer

NewPProfBatchAnalyzer creates a new PProfBatchAnalyzer.

func (*PProfBatchAnalyzer) Analyze

Analyze performs batch analysis on a pprof directory.

func (*PProfBatchAnalyzer) AnalyzeFromReader

AnalyzeFromReader is not supported for batch analysis.

func (*PProfBatchAnalyzer) Name

func (a *PProfBatchAnalyzer) Name() string

Name returns the name of this analyzer.

type PProfCPUAnalyzer

type PProfCPUAnalyzer struct {
	// contains filtered or unexported fields
}

PProfCPUAnalyzer analyzes Go pprof CPU profile data. It delegates to the perflib engine and adapts the business model.

func NewPProfCPUAnalyzer

func NewPProfCPUAnalyzer(config *BaseAnalyzerConfig) *PProfCPUAnalyzer

NewPProfCPUAnalyzer creates a new pprof CPU analyzer.

func (*PProfCPUAnalyzer) Analyze

Analyze performs pprof CPU analysis using an input file.

func (*PProfCPUAnalyzer) AnalyzeFromReader

func (a *PProfCPUAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs pprof CPU analysis from a reader.

func (*PProfCPUAnalyzer) Name

func (a *PProfCPUAnalyzer) Name() string

Name returns the analyzer name.

type PProfContentionAnalyzer

type PProfContentionAnalyzer struct {
	// contains filtered or unexported fields
}

PProfContentionAnalyzer analyzes Go pprof Block/Mutex profile data. It handles both block and mutex profiles as they have similar structure. It delegates to the perflib engine and adapts the business model.

func NewPProfBlockAnalyzer

func NewPProfBlockAnalyzer(config *BaseAnalyzerConfig) *PProfContentionAnalyzer

NewPProfBlockAnalyzer creates a new pprof Block analyzer.

func NewPProfMutexAnalyzer

func NewPProfMutexAnalyzer(config *BaseAnalyzerConfig) *PProfContentionAnalyzer

NewPProfMutexAnalyzer creates a new pprof Mutex analyzer.

func (*PProfContentionAnalyzer) Analyze

Analyze performs pprof Block/Mutex analysis using an input file.

func (*PProfContentionAnalyzer) AnalyzeFromReader

func (a *PProfContentionAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs pprof Block/Mutex analysis from a reader.

func (*PProfContentionAnalyzer) Name

func (a *PProfContentionAnalyzer) Name() string

Name returns the analyzer name.

type PProfGoroutineAnalyzer

type PProfGoroutineAnalyzer struct {
	// contains filtered or unexported fields
}

PProfGoroutineAnalyzer analyzes Go pprof Goroutine profile data. It delegates to the perflib engine and adapts the business model.

func NewPProfGoroutineAnalyzer

func NewPProfGoroutineAnalyzer(config *BaseAnalyzerConfig) *PProfGoroutineAnalyzer

NewPProfGoroutineAnalyzer creates a new pprof Goroutine analyzer.

func (*PProfGoroutineAnalyzer) Analyze

Analyze performs pprof Goroutine analysis using an input file.

func (*PProfGoroutineAnalyzer) AnalyzeFromReader

func (a *PProfGoroutineAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs pprof Goroutine analysis from a reader.

func (*PProfGoroutineAnalyzer) Name

func (a *PProfGoroutineAnalyzer) Name() string

Name returns the analyzer name.

type PProfHeapAnalyzer

type PProfHeapAnalyzer struct {
	// contains filtered or unexported fields
}

PProfHeapAnalyzer analyzes Go pprof Heap profile data. It delegates to the perflib engine and adapts the business model.

func NewPProfHeapAnalyzer

func NewPProfHeapAnalyzer(config *BaseAnalyzerConfig) *PProfHeapAnalyzer

NewPProfHeapAnalyzer creates a new pprof Heap analyzer.

func (*PProfHeapAnalyzer) Analyze

Analyze performs pprof Heap analysis using an input file.

func (*PProfHeapAnalyzer) AnalyzeFromReader

func (a *PProfHeapAnalyzer) AnalyzeFromReader(ctx context.Context, req *model.AnalysisRequest, dataReader io.Reader) (*model.AnalysisResponse, error)

AnalyzeFromReader performs pprof Heap analysis from a reader.

func (*PProfHeapAnalyzer) Name

func (a *PProfHeapAnalyzer) Name() string

Name returns the analyzer name.

type ProfileSetResult

type ProfileSetResult struct {
	ProfileType  string                  `json:"profile_type"`
	FileCount    int                     `json:"file_count"`
	Files        []string                `json:"files"`
	LatestFile   string                  `json:"latest_file"`
	TotalSamples int64                   `json:"total_samples"`
	OutputFiles  []string                `json:"output_files"`
	LeakReport   *pprofparser.LeakReport `json:"leak_report,omitempty"`
}

ProfileSetResult represents analysis results for a set of profiles. Retained for backward compatibility.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL