Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
describe profiles (2)
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed May 30, 2023
1 parent eea6192 commit b51c186
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strconv"
"strings"
"text/tabwriter"
"time"

pprof "github.com/google/pprof/profile"
Expand Down Expand Up @@ -443,9 +444,24 @@ func (desc *profileDescriptor) Format(w fmt.State, _ rune) {
}

fmt.Fprintf(w, "Samples: %d\n", len(desc.profile.Sample))
for _, sampleType := range desc.profile.SampleType {
fmt.Fprintf(w, "- %s (%s)\n", sampleType.Type, sampleType.Unit)
hasDefault := false
tw := tabwriter.NewWriter(w, 0, 4, 2, ' ', 0)
for i, sampleType := range desc.profile.SampleType {
if i != 0 {
fmt.Fprintf(tw, "\n")
}
fmt.Fprintf(w, "- %s\t%s", sampleType.Type, sampleType.Unit)
if sampleType.Type == desc.profile.DefaultSampleType {
hasDefault = true
fmt.Fprintf(tw, " (default)")
}
}
if !hasDefault {
fmt.Fprintf(tw, " (default)\n")
} else {
fmt.Fprintf(tw, "\n")
}
_ = tw.Flush()

if comments := desc.profile.Comments; len(comments) == 0 {
fmt.Fprintf(w, "Comments: (none)\n")
Expand Down
5 changes: 5 additions & 0 deletions internal/print/textprint/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type tableWriter[T any] struct {
orderBy func(T, T) bool
}

func (t *tableWriter[T]) WriteOne(value T) error {
_, err := t.Write([]T{value})
return err
}

func (t *tableWriter[T]) Write(values []T) (int, error) {
t.values = append(t.values, values...)
return len(values), nil
Expand Down

0 comments on commit b51c186

Please sign in to comment.