From 3704c8d23324a3fc0771ad2c1cef0aa4e9459f6f Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Fri, 12 Jun 2020 20:28:58 +1000 Subject: [PATCH] Fix MemProfileAllocs and MemProfileHeap options Fixes #55 --- example_test.go | 10 ++++++++++ profile.go | 16 ++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/example_test.go b/example_test.go index 98a54b5..11d8943 100644 --- a/example_test.go +++ b/example_test.go @@ -29,6 +29,16 @@ func ExampleMemProfileRate() { defer profile.Start(profile.MemProfileRate(2048)).Stop() } +func ExampleMemProfileHeap() { + // use heap memory profiling. + defer profile.Start(profile.MemProfileHeap).Stop() +} + +func ExampleMemProfileAllocs() { + // use allocs memory profiling. + defer profile.Start(profile.MemProfileAllocs).Stop() +} + func ExampleProfilePath() { // set the location that the profile will be written to defer profile.Start(profile.ProfilePath(os.Getenv("HOME"))).Stop() diff --git a/profile.go b/profile.go index bc3a0d6..ec66e30 100644 --- a/profile.go +++ b/profile.go @@ -90,20 +90,16 @@ func MemProfileRate(rate int) func(*Profile) { // MemProfileHeap changes which type of memory profiling to profile // the heap. -func MemProfileHeap() func(*Profile) { - return func(p *Profile) { - p.memProfileType = "heap" - p.mode = memMode - } +func MemProfileHeap(p *Profile) { + p.memProfileType = "heap" + p.mode = memMode } // MemProfileAllocs changes which type of memory to profile // allocations. -func MemProfileAllocs() func(*Profile) { - return func(p *Profile) { - p.memProfileType = "allocs" - p.mode = memMode - } +func MemProfileAllocs(p *Profile) { + p.memProfileType = "allocs" + p.mode = memMode } // MutexProfile enables mutex profiling.