-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprofiles_test.go
More file actions
67 lines (60 loc) · 1.64 KB
/
profiles_test.go
File metadata and controls
67 lines (60 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2025 The Cockroach Authors.
//
// Use of this software is governed by the CockroachDB Software License
// included in the /LICENSE file.
package main
import (
"os"
"testing"
"github.com/google/pprof/profile"
)
func TestMergeProfilesByName(t *testing.T) {
dir := t.TempDir()
bs := benchSuite{artDir: dir}
if err := bs.ensureProfileDirs(); err != nil {
t.Fatalf("ensure profile dirs: %v", err)
}
runMem := bs.profileRunPath(memProfileName)
runExtra := bs.profileRunPath("mem_BenchmarkFoo.pb.gz")
mergedMem := bs.profileMergedPath(memProfileName)
mergedExtra := bs.profileMergedPath("mem_BenchmarkFoo.pb.gz")
if err := writeTestProfile(runMem, 1); err != nil {
t.Fatalf("write run mem profile: %v", err)
}
if err := writeTestProfile(runExtra, 2); err != nil {
t.Fatalf("write run extra profile: %v", err)
}
if err := writeTestProfile(mergedMem, 3); err != nil {
t.Fatalf("write merged mem profile: %v", err)
}
if err := bs.mergeProfiles(false, true, false); err != nil {
t.Fatalf("merge profiles: %v", err)
}
if _, err := os.Stat(mergedMem); err != nil {
t.Fatalf("expected merged mem profile: %v", err)
}
if _, err := os.Stat(mergedExtra); err != nil {
t.Fatalf("expected merged extra profile: %v", err)
}
}
func writeTestProfile(path string, value int64) error {
p := &profile.Profile{
TimeNanos: 1,
DurationNanos: 1,
SampleType: []*profile.ValueType{
{Type: "alloc_objects", Unit: "count"},
},
Sample: []*profile.Sample{
{Value: []int64{value}},
},
}
f, err := os.Create(path)
if err != nil {
return err
}
if err := p.Write(f); err != nil {
_ = f.Close()
return err
}
return f.Close()
}