Debian Codegraph @

internal/driver/tagroot.go

raw symbols SCIP
1 package driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/
2
3 import (
4 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
5
6 "github.com/google/pprof/internal/measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/"
7 "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/"
8 )
9
10 // addLabelNodes adds pseudo stack frames "label:value" to each Sample with
11 // labels matching the supplied keys.
12 //
13 // rootKeys adds frames at the root of the callgraph (first key becomes new root).
14 // leafKeys adds frames at the leaf of the callgraph (last key becomes new leaf).
15 //
16 // Returns whether there were matches found for the label keys.
17 func addLabelNodesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/addLabelNodes().(p *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, rootKeys, leafKeys []string, outputUnit string) (rootm, leafm bool) {
18 // Find where to insert the new locations and functions at the end of
19 // their ID spaces.
20 var maxLocID uint64
21 var maxFunctionID uint64
22 for _, loc := range p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. {
23 if loc.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID. > maxLocID {
24 maxLocID = loc.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.
25 }
26 }
27 for _, f := range p.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. {
28 if f.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID. > maxFunctionID {
29 maxFunctionID = f.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.
30 }
31 }
32 nextLocID := maxLocID + 1
33 nextFuncID := maxFunctionID + 1
34
35 // Intern the new locations and functions we are generating.
36 type locKey struct {
37 functionName, fileName string
38 }
39 locs := map[locKey]*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{}
40
41 internLoc := func(locKey locKey) *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# {
42 loc, found := locs[locKey]
43 if found {
44 return loc
45 }
46
47 function := &profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#{
48 IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID.: nextFuncID,
49 Namescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Name.: locKey.functionName,
50 Filenamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#Filename.: locKey.fileName,
51 }
52 nextFuncID++
53 p.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. = append(p.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function., function)
54
55 loc = &profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{
56 IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID.: nextLocID,
57 Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line.: []profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#{
58 {
59 Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function.: function,
60 },
61 },
62 }
63 nextLocID++
64 p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., loc)
65 locs[locKey] = loc
66 return loc
67 }
68
69 makeLabelLocs := func(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#, keys []string) ([]*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, bool) {
70 var locs []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#
71 var match bool
72 for i := range keys {
73 // Loop backwards, ensuring the first tag is closest to the root,
74 // and the last tag is closest to the leaves.
75 k := keys[len(keys)-1-i]
76 values := formatLabelValuesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/formatLabelValues().(s, k, outputUnit)
77 if len(values) > 0 {
78 match = true
79 }
80 locKey := locKey{
81 functionName: stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().(values, ","),
82 fileName: k,
83 }
84 loc := internLoc(locKey)
85 locs = append(locs, loc)
86 }
87 return locs, match
88 }
89
90 for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. {
91 rootsToAdd, sampleMatchedRoot := makeLabelLocs(s, rootKeys)
92 if sampleMatchedRoot {
93 rootm = true
94 }
95 leavesToAdd, sampleMatchedLeaf := makeLabelLocs(s, leafKeys)
96 if sampleMatchedLeaf {
97 leafm = true
98 }
99
100 if len(leavesToAdd)+len(rootsToAdd) == 0 {
101 continue
102 }
103
104 var newLocs []*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#
105 newLocs = append(newLocs, leavesToAdd...)
106 newLocs = append(newLocs, s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location....)
107 newLocs = append(newLocs, rootsToAdd...)
108 s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. = newLocs
109 }
110 return
111 }
112
113 // formatLabelValues returns all the string and numeric labels in Sample, with
114 // the numeric labels formatted according to outputUnit.
115 func formatLabelValuesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/formatLabelValues().(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#, k string, outputUnit string) []string {
116 var values []string
117 values = append(values, s.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.[k]...)
118 numLabels := s.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.[k]
119 numUnits := s.NumUnitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumUnit.[k]
120 if len(numLabels) != len(numUnits) && len(numUnits) != 0 {
121 return values
122 }
123 for i, numLabel := range numLabels {
124 var value string
125 if len(numUnits) != 0 {
126 value = measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.ScaledLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/ScaledLabel().(numLabel, numUnits[i], outputUnit)
127 } else {
128 value = measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.ScaledLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/ScaledLabel().(numLabel, "", "")
129 }
130 values = append(values, value)
131 }
132 return values
133 }