Skip to content

Commit

Permalink
feat: add heap allocs to 'ipfs diag profile'
Browse files Browse the repository at this point in the history
  • Loading branch information
guseggert authored and galargh committed Mar 20, 2023
1 parent 3c35a0c commit 010e22b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/commands/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ The output file includes:
- A list of running goroutines.
- A CPU profile.
- A heap profile.
- A heap inuse profile.
- A heap allocation profile.
- A mutex profile.
- A block profile.
- Your copy of go-ipfs.
Expand Down Expand Up @@ -79,6 +80,7 @@ However, it could reveal:
profile.CollectorGoroutinesPprof,
profile.CollectorVersion,
profile.CollectorHeap,
profile.CollectorAllocs,
profile.CollectorBin,
profile.CollectorCPU,
profile.CollectorMutex,
Expand Down
10 changes: 10 additions & 0 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
CollectorGoroutinesPprof = "goroutines-pprof"
CollectorVersion = "version"
CollectorHeap = "heap"
CollectorAllocs = "allocs"
CollectorBin = "bin"
CollectorCPU = "cpu"
CollectorMutex = "mutex"
Expand Down Expand Up @@ -71,6 +72,11 @@ var collectors = map[string]collector{
collectFunc: heapProfile,
enabledFunc: func(opts Options) bool { return true },
},
CollectorAllocs: {
outputFile: "allocs.pprof",
collectFunc: allocsProfile,
enabledFunc: func(opts Options) bool { return true },
},
CollectorBin: {
outputFile: "ipfs",
isExecutable: true,
Expand Down Expand Up @@ -197,6 +203,10 @@ func heapProfile(ctx context.Context, _ Options, w io.Writer) error {
return pprof.Lookup("heap").WriteTo(w, 0)
}

func allocsProfile(ctx context.Context, _ Options, w io.Writer) error {
return pprof.Lookup("allocs").WriteTo(w, 0)
}

func versionInfo(ctx context.Context, _ Options, w io.Writer) error {
return json.NewEncoder(w).Encode(version.GetVersionInfo())
}
Expand Down
6 changes: 6 additions & 0 deletions profile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestProfiler(t *testing.T) {
CollectorGoroutinesPprof,
CollectorVersion,
CollectorHeap,
CollectorAllocs,
CollectorBin,
CollectorCPU,
CollectorMutex,
Expand All @@ -43,6 +44,7 @@ func TestProfiler(t *testing.T) {
"goroutines.pprof",
"version.json",
"heap.pprof",
"allocs.pprof",
"ipfs",
"cpu.pprof",
"mutex.pprof",
Expand All @@ -63,6 +65,7 @@ func TestProfiler(t *testing.T) {
"goroutines.pprof",
"version.json",
"heap.pprof",
"allocs.pprof",
"ipfs.exe",
"cpu.pprof",
"mutex.pprof",
Expand All @@ -81,6 +84,7 @@ func TestProfiler(t *testing.T) {
"goroutines.pprof",
"version.json",
"heap.pprof",
"allocs.pprof",
"ipfs",
},
},
Expand All @@ -96,6 +100,7 @@ func TestProfiler(t *testing.T) {
"goroutines.pprof",
"version.json",
"heap.pprof",
"allocs.pprof",
"ipfs",
"cpu.pprof",
"block.pprof",
Expand All @@ -114,6 +119,7 @@ func TestProfiler(t *testing.T) {
"goroutines.pprof",
"version.json",
"heap.pprof",
"allocs.pprof",
"ipfs",
"cpu.pprof",
"mutex.pprof",
Expand Down

0 comments on commit 010e22b

Please sign in to comment.