-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kemal Akkoyun <[email protected]>
- Loading branch information
Showing
6 changed files
with
25 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ issues: | |
- gosec | ||
- musttag | ||
- perfsprint | ||
- dupl | ||
- path: pkg/elfwriter | ||
linters: | ||
- dupl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,7 @@ | |
package integration | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
pprofprofile "github.com/google/pprof/profile" | ||
|
@@ -92,76 +87,6 @@ func aggregateStacks(profile *pprofprofile.Profile) ([][]string, error) { | |
return aggregatedStacks, nil | ||
} | ||
|
||
type convertConfig struct { | ||
lineNumbers, sampleTypes bool | ||
} | ||
|
||
func convertToFolded(profile *pprofprofile.Profile, cfgs ...*convertConfig) (string, error) { | ||
// Original code: https://github.com/felixge/pprofutils/blob/4ab5689918f23a12d358a09e89bd206b4e1dcb26/internal/legacy/protobuf.go | ||
// The MIT License (MIT) | ||
// Copyright © 2021 Felix Geisendörfer <[email protected]> | ||
|
||
if len(cfgs) == 0 { | ||
cfgs = append(cfgs, &convertConfig{}) | ||
} | ||
cfg := cfgs[0] | ||
|
||
var ( | ||
in bytes.Buffer | ||
out bytes.Buffer | ||
) | ||
if err := profile.Write(&in); err != nil { | ||
return "", err | ||
} | ||
|
||
w := bufio.NewWriter(&out) | ||
if cfg.sampleTypes { | ||
var sampleTypes []string | ||
for _, sampleType := range profile.SampleType { | ||
sampleTypes = append(sampleTypes, sampleType.Type+"/"+sampleType.Unit) | ||
} | ||
w.WriteString(strings.Join(sampleTypes, " ") + "\n") | ||
} | ||
if err := profile.Aggregate(true, true, false, cfg.lineNumbers, false, false); err != nil { | ||
return "", err | ||
} | ||
profile = profile.Compact() | ||
sort.Slice(profile.Sample, func(i, j int) bool { | ||
return profile.Sample[i].Value[0] > profile.Sample[j].Value[0] | ||
}) | ||
for _, sample := range profile.Sample { | ||
var frames []string | ||
for i := range sample.Location { | ||
loc := sample.Location[len(sample.Location)-i-1] | ||
for j := range loc.Line { | ||
line := loc.Line[len(loc.Line)-j-1] | ||
name := line.Function.Name | ||
if cfg.lineNumbers { | ||
name = name + ":" + strconv.FormatInt(line.Line, 10) | ||
} | ||
frames = append(frames, name) | ||
} | ||
} | ||
var values []string | ||
for _, val := range sample.Value { | ||
values = append(values, fmt.Sprintf("%d", val)) | ||
if !cfg.sampleTypes { | ||
break | ||
} | ||
} | ||
fmt.Fprintf( | ||
w, | ||
"%s %s\n", | ||
strings.Join(frames, ";"), | ||
strings.Join(values, " "), | ||
) | ||
} | ||
if err := w.Flush(); err != nil { | ||
return "", err | ||
} | ||
return out.String(), nil | ||
} | ||
|
||
func TestAnyStackContains(t *testing.T) { | ||
// Edge cases. | ||
require.True(t, anyStackContains([][]string{{"a", "b"}}, []string{})) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters