diff --git a/core/commands/profile.go b/core/commands/profile.go index 3875cfdcb..d25711dac 100644 --- a/core/commands/profile.go +++ b/core/commands/profile.go @@ -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. @@ -79,6 +80,7 @@ However, it could reveal: profile.CollectorGoroutinesPprof, profile.CollectorVersion, profile.CollectorHeap, + profile.CollectorAllocs, profile.CollectorBin, profile.CollectorCPU, profile.CollectorMutex, diff --git a/profile/profile.go b/profile/profile.go index d15d51251..b9ad86d2f 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -22,6 +22,7 @@ const ( CollectorGoroutinesPprof = "goroutines-pprof" CollectorVersion = "version" CollectorHeap = "heap" + CollectorAllocs = "allocs" CollectorBin = "bin" CollectorCPU = "cpu" CollectorMutex = "mutex" @@ -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, @@ -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()) } diff --git a/profile/profile_test.go b/profile/profile_test.go index 8da00d018..a2fe0b51d 100644 --- a/profile/profile_test.go +++ b/profile/profile_test.go @@ -17,6 +17,7 @@ func TestProfiler(t *testing.T) { CollectorGoroutinesPprof, CollectorVersion, CollectorHeap, + CollectorAllocs, CollectorBin, CollectorCPU, CollectorMutex, @@ -43,6 +44,7 @@ func TestProfiler(t *testing.T) { "goroutines.pprof", "version.json", "heap.pprof", + "allocs.pprof", "ipfs", "cpu.pprof", "mutex.pprof", @@ -63,6 +65,7 @@ func TestProfiler(t *testing.T) { "goroutines.pprof", "version.json", "heap.pprof", + "allocs.pprof", "ipfs.exe", "cpu.pprof", "mutex.pprof", @@ -81,6 +84,7 @@ func TestProfiler(t *testing.T) { "goroutines.pprof", "version.json", "heap.pprof", + "allocs.pprof", "ipfs", }, }, @@ -96,6 +100,7 @@ func TestProfiler(t *testing.T) { "goroutines.pprof", "version.json", "heap.pprof", + "allocs.pprof", "ipfs", "cpu.pprof", "block.pprof", @@ -114,6 +119,7 @@ func TestProfiler(t *testing.T) { "goroutines.pprof", "version.json", "heap.pprof", + "allocs.pprof", "ipfs", "cpu.pprof", "mutex.pprof",