feat: add heap allocs to 'ipfs diag profile'

This commit is contained in:
Gus Eggert 2023-03-16 08:41:50 -04:00
parent 51eabd46da
commit 23b5abfb7a
3 changed files with 19 additions and 1 deletions

View File

@ -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,

View File

@ -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())
}

View File

@ -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",