]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: merge internal/protopprof into pprof package
authorRuss Cox <rsc@golang.org>
Thu, 9 Feb 2017 21:01:11 +0000 (16:01 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 10 Feb 2017 13:09:19 +0000 (13:09 +0000)
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>
src/runtime/pprof/pprof.go
src/runtime/pprof/proto.go [moved from src/runtime/pprof/internal/protopprof/protopprof.go with 93% similarity]
src/runtime/pprof/proto_test.go [moved from src/runtime/pprof/internal/protopprof/protopprof_test.go with 97% similarity]
src/runtime/pprof/protomem.go [moved from src/runtime/pprof/internal/protopprof/protomemprofile.go with 94% similarity]
src/runtime/pprof/protomem_test.go [moved from src/runtime/pprof/internal/protopprof/protomemprofile_test.go with 98% similarity]

index c2b4a2787eabcf95723b65e43d5a051e88da9ae7..c88844e83724fa637f150157f9264cf5e19343c4 100644 (file)
@@ -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.
similarity index 93%
rename from src/runtime/pprof/internal/protopprof/protopprof.go
rename to src/runtime/pprof/proto.go
index 8a10716f0ac3ee193ce4a691d82ba9be368c27d5..6fcfc725374f621fe75d3492f345569e83851363 100644 (file)
@@ -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 {
similarity index 97%
rename from src/runtime/pprof/internal/protopprof/protopprof_test.go
rename to src/runtime/pprof/proto_test.go
index 33d19d85660519bd80301deb8811abd081e72fbc..ba145e484606031669bd460124e4ddc946e6b2c6 100644 (file)
@@ -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)
similarity index 94%
rename from src/runtime/pprof/internal/protopprof/protomemprofile.go
rename to src/runtime/pprof/protomem.go
index c2ab5b57025021398a1e176388be41d8065250b7..4892b6deb12c4bfd49cabe5e71b9bb2a1653afbc 100644 (file)
@@ -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"},
similarity index 98%
rename from src/runtime/pprof/internal/protopprof/protomemprofile_test.go
rename to src/runtime/pprof/protomem_test.go
index a10fe772ccfbccc09301d900454ff7e04332e662..a07f20bd25fe7dd5c62b47f16d9ca6415efc14ff 100644 (file)
@@ -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)
        }