|
@@ -309,7 +309,10 @@ func printTopProto(w io.Writer, rpt *Report) error {
|
309
|
309
|
}
|
310
|
310
|
functionMap := make(functionMap)
|
311
|
311
|
for i, n := range g.Nodes {
|
312
|
|
- f := functionMap.FindOrAdd(n.Info)
|
|
312
|
+ f, added := functionMap.findOrAdd(n.Info)
|
|
313
|
+ if added {
|
|
314
|
+ out.Function = append(out.Function, f)
|
|
315
|
+ }
|
313
|
316
|
flat, cum := n.FlatValue(), n.CumValue()
|
314
|
317
|
l := &profile.Location{
|
315
|
318
|
ID: uint64(i + 1),
|
|
@@ -328,7 +331,6 @@ func printTopProto(w io.Writer, rpt *Report) error {
|
328
|
331
|
Location: []*profile.Location{l},
|
329
|
332
|
Value: []int64{int64(cv), int64(fv)},
|
330
|
333
|
}
|
331
|
|
- out.Function = append(out.Function, f)
|
332
|
334
|
out.Location = append(out.Location, l)
|
333
|
335
|
out.Sample = append(out.Sample, s)
|
334
|
336
|
}
|
|
@@ -338,11 +340,15 @@ func printTopProto(w io.Writer, rpt *Report) error {
|
338
|
340
|
|
339
|
341
|
type functionMap map[string]*profile.Function
|
340
|
342
|
|
341
|
|
-func (fm functionMap) FindOrAdd(ni graph.NodeInfo) *profile.Function {
|
|
343
|
+// findOrAdd takes a node representing a function, adds the function
|
|
344
|
+// represented by the node to the map if the function is not already present,
|
|
345
|
+// and returns the function the node represents. This also returns a boolean,
|
|
346
|
+// which is true if the function was added and false otherwise.
|
|
347
|
+func (fm functionMap) findOrAdd(ni graph.NodeInfo) (*profile.Function, bool) {
|
342
|
348
|
fName := fmt.Sprintf("%q%q%q%d", ni.Name, ni.OrigName, ni.File, ni.StartLine)
|
343
|
349
|
|
344
|
350
|
if f := fm[fName]; f != nil {
|
345
|
|
- return f
|
|
351
|
+ return f, false
|
346
|
352
|
}
|
347
|
353
|
|
348
|
354
|
f := &profile.Function{
|
|
@@ -353,7 +359,7 @@ func (fm functionMap) FindOrAdd(ni graph.NodeInfo) *profile.Function {
|
353
|
359
|
StartLine: int64(ni.StartLine),
|
354
|
360
|
}
|
355
|
361
|
fm[fName] = f
|
356
|
|
- return f
|
|
362
|
+ return f, true
|
357
|
363
|
}
|
358
|
364
|
|
359
|
365
|
// printAssembly prints an annotated assembly listing.
|