Commit 9a754439 authored by Russ Cox's avatar Russ Cox

runtime/pprof: merge internal/protopprof into pprof package

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 3a209281
......@@ -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.
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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"},
......
......@@ -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)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment