From a8630aee4ab9e36dfc54c2e0a4df49abb8345dbd Mon Sep 17 00:00:00 2001 From: Sanjay Ghemawat Date: Tue, 3 Sep 2024 08:56:34 -0700 Subject: [PATCH] Added doc link to profile header. (#892) Output looks something like: ``` % pprof -top ... File: ... Build ID: ... Type: cpu Doc: http://example.com/cpuprofile Duration: 6.71s, Total samples = 5.72s (85.30%) Showing nodes accounting for 5.17s, 90.38% of 5.72s total Dropped 326 nodes (cum <= 0.03s) ... ``` --- internal/report/report.go | 3 +++ internal/report/report_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/internal/report/report.go b/internal/report/report.go index 7035e231..5ab0da65 100644 --- a/internal/report/report.go +++ b/internal/report/report.go @@ -1169,6 +1169,9 @@ func ProfileLabels(rpt *Report) []string { if o.SampleType != "" { label = append(label, "Type: "+o.SampleType) } + if url := prof.DocURL; url != "" { + label = append(label, "Doc: "+url) + } if prof.TimeNanos != 0 { const layout = "Jan 2, 2006 at 3:04pm (MST)" label = append(label, "Time: "+time.Unix(0, prof.TimeNanos).Format(layout)) diff --git a/internal/report/report_test.go b/internal/report/report_test.go index 08ce9da1..845c3690 100644 --- a/internal/report/report_test.go +++ b/internal/report/report_test.go @@ -16,6 +16,7 @@ package report import ( "bytes" + "fmt" "os" "path/filepath" "regexp" @@ -576,3 +577,21 @@ func TestDocURL(t *testing.T) { }) } } + +func TestDocURLInLabels(t *testing.T) { + const url = "http://example.com/pprof-help" + profile := testProfile.Copy() + profile.DocURL = url + rpt := New(profile, &Options{ + OutputFormat: Text, + Symbol: regexp.MustCompile(`.`), + TrimPath: "/some/path", + SampleValue: func(v []int64) int64 { return v[1] }, + SampleUnit: testProfile.SampleType[1].Unit, + }) + + labels := fmt.Sprintf("%v", ProfileLabels(rpt)) + if !strings.Contains(labels, url) { + t.Errorf("expected URL %q not found in %s", url, labels) + } +}