|
@@ -3,6 +3,8 @@ package graph
|
3
|
3
|
import (
|
4
|
4
|
"fmt"
|
5
|
5
|
"testing"
|
|
6
|
+
|
|
7
|
+ "github.com/google/pprof/profile"
|
6
|
8
|
)
|
7
|
9
|
|
8
|
10
|
func edgeDebugString(edge *Edge) string {
|
|
@@ -312,3 +314,87 @@ func TestTrimTree(t *testing.T) {
|
312
|
314
|
}
|
313
|
315
|
}
|
314
|
316
|
}
|
|
317
|
+
|
|
318
|
+func nodeTestProfile() *profile.Profile {
|
|
319
|
+ mappings := []*profile.Mapping{
|
|
320
|
+ {
|
|
321
|
+ ID: 1,
|
|
322
|
+ File: "symbolized_binary",
|
|
323
|
+ },
|
|
324
|
+ {
|
|
325
|
+ ID: 2,
|
|
326
|
+ File: "unsymbolized_library_1",
|
|
327
|
+ },
|
|
328
|
+ {
|
|
329
|
+ ID: 3,
|
|
330
|
+ File: "unsymbolized_library_2",
|
|
331
|
+ },
|
|
332
|
+ }
|
|
333
|
+ functions := []*profile.Function{
|
|
334
|
+ {ID: 1, Name: "symname"},
|
|
335
|
+ {ID: 2},
|
|
336
|
+ }
|
|
337
|
+ locations := []*profile.Location{
|
|
338
|
+ {
|
|
339
|
+ ID: 1,
|
|
340
|
+ Mapping: mappings[0],
|
|
341
|
+ Line: []profile.Line{
|
|
342
|
+ {Function: functions[0]},
|
|
343
|
+ },
|
|
344
|
+ },
|
|
345
|
+ {
|
|
346
|
+ ID: 2,
|
|
347
|
+ Mapping: mappings[1],
|
|
348
|
+ Line: []profile.Line{
|
|
349
|
+ {Function: functions[1]},
|
|
350
|
+ },
|
|
351
|
+ },
|
|
352
|
+ {
|
|
353
|
+ ID: 3,
|
|
354
|
+ Mapping: mappings[2],
|
|
355
|
+ },
|
|
356
|
+ }
|
|
357
|
+ return &profile.Profile{
|
|
358
|
+ PeriodType: &profile.ValueType{Type: "cpu", Unit: "milliseconds"},
|
|
359
|
+ SampleType: []*profile.ValueType{
|
|
360
|
+ {Type: "type", Unit: "unit"},
|
|
361
|
+ },
|
|
362
|
+ Sample: []*profile.Sample{
|
|
363
|
+ {
|
|
364
|
+ Location: []*profile.Location{locations[0]},
|
|
365
|
+ Value: []int64{1},
|
|
366
|
+ },
|
|
367
|
+ {
|
|
368
|
+ Location: []*profile.Location{locations[1]},
|
|
369
|
+ Value: []int64{1},
|
|
370
|
+ },
|
|
371
|
+ {
|
|
372
|
+ Location: []*profile.Location{locations[2]},
|
|
373
|
+ Value: []int64{1},
|
|
374
|
+ },
|
|
375
|
+ },
|
|
376
|
+ Location: locations,
|
|
377
|
+ Function: functions,
|
|
378
|
+ Mapping: mappings,
|
|
379
|
+ }
|
|
380
|
+}
|
|
381
|
+
|
|
382
|
+// Check that nodes are properly created for a simple profile.
|
|
383
|
+func TestCreateNodes(t *testing.T) {
|
|
384
|
+ testProfile := nodeTestProfile()
|
|
385
|
+ wantNodeSet := NodeSet{
|
|
386
|
+ {Name: "symname"}: true,
|
|
387
|
+ {Objfile: "unsymbolized_library_1"}: true,
|
|
388
|
+ {Objfile: "unsymbolized_library_2"}: true,
|
|
389
|
+ }
|
|
390
|
+
|
|
391
|
+ nodes, _ := CreateNodes(testProfile, &Options{})
|
|
392
|
+ if len(nodes) != len(wantNodeSet) {
|
|
393
|
+ t.Errorf("got %d nodes, want %d", len(nodes), len(wantNodeSet))
|
|
394
|
+ }
|
|
395
|
+ for _, node := range nodes {
|
|
396
|
+ if !wantNodeSet[node.Info] {
|
|
397
|
+ t.Errorf("unexpected node %v", node.Info)
|
|
398
|
+ }
|
|
399
|
+ }
|
|
400
|
+}
|