diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go index c2b4a2787e..c88844e837 100644 --- a/src/runtime/pprof/pprof.go +++ b/src/runtime/pprof/pprof.go @@ -78,7 +78,6 @@ import ( "internal/pprof/profile" "io" "runtime" - "runtime/pprof/internal/protopprof" "sort" "strings" "sync" @@ -500,7 +499,7 @@ func writeHeap(w io.Writer, debug int) error { } if debug == 0 { - pp := protopprof.EncodeMemProfile(p, int64(runtime.MemProfileRate), time.Now()) + pp := encodeMemProfile(p, int64(runtime.MemProfileRate), time.Now()) return pp.Write(w) } @@ -709,7 +708,7 @@ func profileWriter(w io.Writer) { buf.Write(data) } - profile, err := protopprof.TranslateCPUProfile(buf.Bytes(), startTime) + profile, err := translateCPUProfile(buf.Bytes(), startTime) if err != nil { // The runtime should never produce an invalid or truncated profile. // It drops records that can't fit into its log buffers. diff --git a/src/runtime/pprof/internal/protopprof/protopprof.go b/src/runtime/pprof/proto.go similarity index 93% rename from src/runtime/pprof/internal/protopprof/protopprof.go rename to src/runtime/pprof/proto.go index 8a10716f0a..6fcfc72537 100644 --- a/src/runtime/pprof/internal/protopprof/protopprof.go +++ b/src/runtime/pprof/proto.go @@ -2,10 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package protopprof converts the runtime's raw profile logs -// to Profile structs containing a representation of the pprof -// protocol buffer profile format. -package protopprof +package pprof import ( "fmt" @@ -18,9 +15,9 @@ import ( "internal/pprof/profile" ) -// TranslateCPUProfile parses binary CPU profiling stack trace data +// translateCPUProfile parses binary CPU profiling stack trace data // generated by runtime.CPUProfile() into a profile struct. -func TranslateCPUProfile(b []byte, startTime time.Time) (*profile.Profile, error) { +func translateCPUProfile(b []byte, startTime time.Time) (*profile.Profile, error) { const wordSize = unsafe.Sizeof(uintptr(0)) const minRawProfile = 5 * wordSize // Need a minimum of 5 words. if uintptr(len(b)) < minRawProfile { diff --git a/src/runtime/pprof/internal/protopprof/protopprof_test.go b/src/runtime/pprof/proto_test.go similarity index 97% rename from src/runtime/pprof/internal/protopprof/protopprof_test.go rename to src/runtime/pprof/proto_test.go index 33d19d8566..ba145e4846 100644 --- a/src/runtime/pprof/internal/protopprof/protopprof_test.go +++ b/src/runtime/pprof/proto_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package protopprof +package pprof import ( "bytes" @@ -62,14 +62,14 @@ func createProfileWithTwoSamples(t *testing.T, periodMs uintptr, count1 uintptr, return *buf } -// Tests TranslateCPUProfile parses correct sampling period in an otherwise empty cpu profile. +// 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. var buf bytes.Buffer startTime := time.Now() b := createEmptyProfileWithPeriod(t, 2000) - p, err := TranslateCPUProfile(b.Bytes(), startTime) + p, err := translateCPUProfile(b.Bytes(), startTime) if err != nil { t.Fatalf("translate failed: %v", err) } @@ -108,7 +108,7 @@ func getSampleAsString(sample []*profile.Sample) string { return str } -// Tests TranslateCPUProfile parses a cpu profile with sample values present. +// Tests translateCPUProfile parses a cpu profile with sample values present. func TestTranslateCPUProfileWithSamples(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("test requires a system with /proc/self/maps") @@ -134,7 +134,7 @@ func TestTranslateCPUProfileWithSamples(t *testing.T) { startTime := time.Now() b := createProfileWithTwoSamples(t, 2000, 20, 40, uintptr(address1), uintptr(address2)) - p, err := TranslateCPUProfile(b.Bytes(), startTime) + p, err := translateCPUProfile(b.Bytes(), startTime) if err != nil { t.Fatalf("Could not parse Profile profile: %v", err) diff --git a/src/runtime/pprof/internal/protopprof/protomemprofile.go b/src/runtime/pprof/protomem.go similarity index 94% rename from src/runtime/pprof/internal/protopprof/protomemprofile.go rename to src/runtime/pprof/protomem.go index c2ab5b5702..4892b6deb1 100644 --- a/src/runtime/pprof/internal/protopprof/protomemprofile.go +++ b/src/runtime/pprof/protomem.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package protopprof +package pprof import ( "internal/pprof/profile" @@ -11,8 +11,8 @@ import ( "time" ) -// EncodeMemProfile converts MemProfileRecords to a Profile. -func EncodeMemProfile(mr []runtime.MemProfileRecord, rate int64, t time.Time) *profile.Profile { +// encodeMemProfile converts MemProfileRecords to a Profile. +func encodeMemProfile(mr []runtime.MemProfileRecord, rate int64, t time.Time) *profile.Profile { p := &profile.Profile{ Period: rate, PeriodType: &profile.ValueType{Type: "space", Unit: "bytes"}, diff --git a/src/runtime/pprof/internal/protopprof/protomemprofile_test.go b/src/runtime/pprof/protomem_test.go similarity index 98% rename from src/runtime/pprof/internal/protopprof/protomemprofile_test.go rename to src/runtime/pprof/protomem_test.go index a10fe772cc..a07f20bd25 100644 --- a/src/runtime/pprof/internal/protopprof/protomemprofile_test.go +++ b/src/runtime/pprof/protomem_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package protopprof +package pprof import ( "bytes" @@ -42,7 +42,7 @@ func TestSampledHeapAllocProfile(t *testing.T) { var buf bytes.Buffer rec, rate := testMemRecords(address1, address2) - p := EncodeMemProfile(rec, rate, time.Now()) + p := encodeMemProfile(rec, rate, time.Now()) if err := p.Write(&buf); err != nil { t.Fatalf("Failed to write profile: %v", err) }