Skip to content

Commit

Permalink
Added doc link to profile header. (#892)
Browse files Browse the repository at this point in the history
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)
...
```
  • Loading branch information
ghemawat authored Sep 3, 2024
1 parent da1f7e9 commit a8630ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
19 changes: 19 additions & 0 deletions internal/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package report

import (
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit a8630ae

Please sign in to comment.