These are very tightly coupled, and internal/protopprof is small.
There's no point to having a separate package.
Change-Id: I2c8aa49c9e18a7128657bf2b05323860151b5606
Reviewed-on: https://go-review.googlesource.com/36711
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
"internal/pprof/profile"
"io"
"runtime"
- "runtime/pprof/internal/protopprof"
"sort"
"strings"
"sync"
}
if debug == 0 {
- pp := protopprof.EncodeMemProfile(p, int64(runtime.MemProfileRate), time.Now())
+ pp := encodeMemProfile(p, int64(runtime.MemProfileRate), time.Now())
return pp.Write(w)
}
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.
// 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"
"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 {
// 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"
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)
}
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")
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)
// 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"
"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"},
// 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"
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)
}