diff options
| author | Michael Matloob <matloob@golang.org> | 2016-11-10 13:31:41 -0500 |
|---|---|---|
| committer | Michael Matloob <matloob@golang.org> | 2016-11-10 21:07:48 +0000 |
| commit | 76f12cdaa2be0b96d314762ff5b2e403d1359cd8 (patch) | |
| tree | 951799799bb57d41a3f767200f37088dfbeabe88 /src/runtime/pprof/internal | |
| parent | 7448eb4172bfc8f704b9ea39d77d0113a042b9dc (diff) | |
| download | go-76f12cdaa2be0b96d314762ff5b2e403d1359cd8.tar.xz | |
runtime/pprof: output CPU profiles in pprof protobuf format
This change buffers the entire profile and converts in one shot
in the profile writer, and could use more memory than necessary
to output protocol buffer formatted profiles. It should be
possible to convert each chunk in a stream (maybe maintaining
some minimal state to output in the end) which could save on
memory usage.
Fixes #16093
Change-Id: I946c6a2b044ae644c72c8bb2d3bd82c415b1a847
Reviewed-on: https://go-review.googlesource.com/33071
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/pprof/internal')
| -rw-r--r-- | src/runtime/pprof/internal/protopprof/protopprof.go | 1 | ||||
| -rw-r--r-- | src/runtime/pprof/internal/protopprof/protopprof_test.go | 38 |
2 files changed, 0 insertions, 39 deletions
diff --git a/src/runtime/pprof/internal/protopprof/protopprof.go b/src/runtime/pprof/internal/protopprof/protopprof.go index 6d799d921f..5d269c4f65 100644 --- a/src/runtime/pprof/internal/protopprof/protopprof.go +++ b/src/runtime/pprof/internal/protopprof/protopprof.go @@ -49,7 +49,6 @@ func TranslateCPUProfile(b []byte, startTime time.Time) (*profile.Profile, error } count := data[0] nstk := data[1] - fmt.Printf("count:%v nstk: %v\n", count, nstk) if uintptr(len(data)) < 2+nstk { return nil, fmt.Errorf("truncated profile") } diff --git a/src/runtime/pprof/internal/protopprof/protopprof_test.go b/src/runtime/pprof/internal/protopprof/protopprof_test.go index beecefe04c..ad8b04bd37 100644 --- a/src/runtime/pprof/internal/protopprof/protopprof_test.go +++ b/src/runtime/pprof/internal/protopprof/protopprof_test.go @@ -8,37 +8,14 @@ import ( "bytes" "fmt" "internal/pprof/profile" - "io" "io/ioutil" "reflect" "runtime" - "runtime/pprof" "testing" "time" "unsafe" ) -// Profile collects a CPU utilization profile and -// writes it to w as a compressed profile.proto. It's used by -// TestProfileParse. -func Profile(w io.Writer, seconds int) error { - var buf bytes.Buffer - // Collect the CPU profile in legacy format in buf. - startTime := time.Now() - if err := pprof.StartCPUProfile(&buf); err != nil { - return fmt.Errorf("Could not enable CPU profiling: %s\n", err) - } - time.Sleep(time.Duration(seconds) * time.Second) - pprof.StopCPUProfile() - - const untagged = false - p, err := TranslateCPUProfile(buf.Bytes(), startTime) - if err != nil { - return err - } - return p.Write(w) -} - // Helper function to initialize empty cpu profile with sampling period provided. func createEmptyProfileWithPeriod(t *testing.T, periodMs uint64) bytes.Buffer { // Mock the sample header produced by cpu profiler. Write a sample @@ -85,21 +62,6 @@ func createProfileWithTwoSamples(t *testing.T, periodMs uintptr, count1 uintptr, return *buf } -// Tests that server creates a cpu profile handler that outputs a parsable Profile profile. -func TestCPUProfileParse(t *testing.T) { - var before, after runtime.MemStats - runtime.ReadMemStats(&before) - var buf bytes.Buffer - if err := Profile(&buf, 30); err != nil { - t.Fatalf("Profile failed: %v", err) - } - runtime.ReadMemStats(&after) - _, err := profile.Parse(&buf) - if err != nil { - t.Fatalf("Could not parse Profile profile: %v", err) - } -} - // Tests TranslateCPUProfile parses correct sampling period in an otherwise empty cpu profile. func TestTranlateCPUProfileSamplingPeriod(t *testing.T) { // A test server with mock cpu profile data. |
