@cryptotaxi247 / kubo / commits / 23b5abfb7

feat: add heap allocs to 'ipfs diag profile'

Gus Eggert committed Mar 16, 2023 at 08:41 UTC 23b5abfb7abcf5775640e72df327fc25f06482ac
3 files changed +19 -1
core/commands/profile.go
+3 -1
@@ -49,7 +49,8 @@ The output file includes:
49
50 - A list of running goroutines.
51 - A CPU profile.
52 -- A heap profile.
52 +- A heap inuse profile.
53 +- A heap allocation profile.
54 - A mutex profile.
55 - A block profile.
56 - Your copy of go-ipfs.
@@ -79,6 +80,7 @@ However, it could reveal:
80 profile.CollectorGoroutinesPprof,
81 profile.CollectorVersion,
82 profile.CollectorHeap,
83 + profile.CollectorAllocs,
84 profile.CollectorBin,
85 profile.CollectorCPU,
86 profile.CollectorMutex,
profile/profile.go
+10
@@ -22,6 +22,7 @@ const (
22 CollectorGoroutinesPprof = "goroutines-pprof"
23 CollectorVersion = "version"
24 CollectorHeap = "heap"
25 + CollectorAllocs = "allocs"
26 CollectorBin = "bin"
27 CollectorCPU = "cpu"
28 CollectorMutex = "mutex"
@@ -71,6 +72,11 @@ var collectors = map[string]collector{
72 collectFunc: heapProfile,
73 enabledFunc: func(opts Options) bool { return true },
74 },
75 + CollectorAllocs: {
76 + outputFile: "allocs.pprof",
77 + collectFunc: allocsProfile,
78 + enabledFunc: func(opts Options) bool { return true },
79 + },
80 CollectorBin: {
81 outputFile: "ipfs",
82 isExecutable: true,
@@ -197,6 +203,10 @@ func heapProfile(ctx context.Context, _ Options, w io.Writer) error {
203 return pprof.Lookup("heap").WriteTo(w, 0)
204 }
205
206 +func allocsProfile(ctx context.Context, _ Options, w io.Writer) error {
207 + return pprof.Lookup("allocs").WriteTo(w, 0)
208 +}
209 +
210 func versionInfo(ctx context.Context, _ Options, w io.Writer) error {
211 return json.NewEncoder(w).Encode(version.GetVersionInfo())
212 }
profile/profile_test.go
+6
@@ -17,6 +17,7 @@ func TestProfiler(t *testing.T) {
17 CollectorGoroutinesPprof,
18 CollectorVersion,
19 CollectorHeap,
20 + CollectorAllocs,
21 CollectorBin,
22 CollectorCPU,
23 CollectorMutex,
@@ -43,6 +44,7 @@ func TestProfiler(t *testing.T) {
44 "goroutines.pprof",
45 "version.json",
46 "heap.pprof",
47 + "allocs.pprof",
48 "ipfs",
49 "cpu.pprof",
50 "mutex.pprof",
@@ -63,6 +65,7 @@ func TestProfiler(t *testing.T) {
65 "goroutines.pprof",
66 "version.json",
67 "heap.pprof",
68 + "allocs.pprof",
69 "ipfs.exe",
70 "cpu.pprof",
71 "mutex.pprof",
@@ -81,6 +84,7 @@ func TestProfiler(t *testing.T) {
84 "goroutines.pprof",
85 "version.json",
86 "heap.pprof",
87 + "allocs.pprof",
88 "ipfs",
89 },
90 },
@@ -96,6 +100,7 @@ func TestProfiler(t *testing.T) {
100 "goroutines.pprof",
101 "version.json",
102 "heap.pprof",
103 + "allocs.pprof",
104 "ipfs",
105 "cpu.pprof",
106 "block.pprof",
@@ -114,6 +119,7 @@ func TestProfiler(t *testing.T) {
119 "goroutines.pprof",
120 "version.json",
121 "heap.pprof",
122 + "allocs.pprof",
123 "ipfs",
124 "cpu.pprof",
125 "mutex.pprof",