-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pprof parser formatting for rbspy (#1454)
* fix: pprof parser formatting for rbspy * revert some changes * linter * fix build * pass formatter explicitly to parser constructor
- Loading branch information
1 parent
90a5bb6
commit ca93c31
Showing
3 changed files
with
71 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pprof | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pyroscope-io/pyroscope/pkg/storage/tree" | ||
"reflect" | ||
"unsafe" | ||
) | ||
|
||
type StackFrameFormatter interface { | ||
format(x *tree.Profile, fn *tree.Function, line *tree.Line) []byte | ||
} | ||
|
||
func unsafeStrToSlice(s string) []byte { | ||
return (*[0x7fff0000]byte)(unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data))[:len(s):len(s)] | ||
} | ||
|
||
type UnsafeFunctionNameFormatter struct { | ||
} | ||
|
||
func (UnsafeFunctionNameFormatter) format(x *tree.Profile, fn *tree.Function, _ *tree.Line) []byte { | ||
return unsafeStrToSlice(x.StringTable[fn.Name]) | ||
} | ||
|
||
type RbspyFormatter struct { | ||
} | ||
|
||
func (RbspyFormatter) format(x *tree.Profile, fn *tree.Function, line *tree.Line) []byte { | ||
return []byte(fmt.Sprintf("%s:%d - %s", | ||
x.StringTable[fn.Filename], | ||
line.Line, | ||
x.StringTable[fn.Name])) | ||
} | ||
|
||
func StackFrameFormatterForSpyName(spyName string) StackFrameFormatter { | ||
if spyName == "rbspy" { | ||
return RbspyFormatter{} | ||
} | ||
return UnsafeFunctionNameFormatter{} | ||
} |
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