github.com/GuanceCloud/cliutils@v1.1.21/pprofparser/service/parsing/parser.go (about) 1 package parsing 2 3 import ( 4 "fmt" 5 "github.com/GuanceCloud/cliutils/pprofparser/domain/events" 6 "github.com/GuanceCloud/cliutils/pprofparser/domain/languages" 7 "github.com/GuanceCloud/cliutils/pprofparser/domain/parameter" 8 "github.com/GuanceCloud/cliutils/pprofparser/domain/pprof" 9 "github.com/GuanceCloud/cliutils/pprofparser/domain/tracing" 10 "github.com/GuanceCloud/cliutils/pprofparser/tools/logtoolkit" 11 ) 12 13 type Parser interface { 14 Summary() (map[events.Type]*EventSummary, int64, error) 15 ResolveFlameGraph(eventType events.Type) (*pprof.Frame, AggregatorSelectSlice, error) 16 } 17 18 type SummaryValueType = pprof.SummaryValueType 19 type EventSummary = pprof.EventSummary 20 type SummaryCollection = pprof.SummaryCollection 21 22 func GetSummary(param parameter.SummaryParam, filterBySpan bool, spanIDSet *tracing.SpanIDSet) (map[events.Type]*EventSummary, int64, error) { 23 24 isCollapseProfile := false 25 meta, err := ReadMetaData(param.Profiles[0], param.WorkspaceUUID) 26 if err != nil { 27 logtoolkit.Warnf("unable to read profile metadata: %s", err) 28 } else { 29 if meta.Format == RawFlameGraph || meta.Format == Collapsed { 30 isCollapseProfile = true 31 } 32 } 33 34 if isCollapseProfile { 35 return NewCollapse(param.WorkspaceUUID, param.Profiles, filterBySpan, spanIDSet).Summary() 36 } 37 38 lang, err := parameter.VerifyLanguage(param.Profiles) 39 if err != nil { 40 return nil, 0, fmt.Errorf("invalid language: %w", err) 41 } 42 var ctl DisplayCtl 43 if meta != nil && meta.Profiler == Pyroscope && lang == languages.NodeJS { 44 ctl = new(PyroscopeNodejs) 45 } else { 46 ctl = new(DDTrace) 47 } 48 49 parser := NewPProfParser(param.From, param.WorkspaceUUID, param.Profiles, 50 filterBySpan, ¶m.Span, spanIDSet, ctl) 51 return parser.Summary() 52 }