Skip to content

Commit

Permalink
pyroscope: cleanse java syms to group frames
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershafir committed Feb 12, 2024
1 parent b214ae3 commit 52d577d
Show file tree
Hide file tree
Showing 5 changed files with 567 additions and 524 deletions.
4 changes: 1 addition & 3 deletions receiver/pyroscopereceiver/jfrparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (pa *jfrPprofParser) Parse(jfr *bytes.Buffer, md profile_types.Metadata) ([
values = [2]int64{1, 0}
)

pa.jfrParser = jfr_parser.NewParser(jfr.Bytes(), jfr_parser.Options{SymbolProcessor: nopSymbolProcessor})
pa.jfrParser = jfr_parser.NewParser(jfr.Bytes(), jfr_parser.Options{SymbolProcessor: processSyms})

if md.SampleRateHertz == 0 {
period = 1
Expand Down Expand Up @@ -128,8 +128,6 @@ func (pa *jfrPprofParser) Parse(jfr *bytes.Buffer, md profile_types.Metadata) ([
return ps, nil
}

func nopSymbolProcessor(ref *jfr_types.SymbolList) {}

// TODO: hash location lists, merge-sort similar samples and free unused pprof objects
func (pa *jfrPprofParser) addStacktrace(sampleType sampleType, ref jfr_types.StackTraceRef, values []int64) {
pr := pa.getProfile(sampleType)
Expand Down
45 changes: 45 additions & 0 deletions receiver/pyroscopereceiver/jfrparser/syms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package jfrparser

import (
"regexp"

"github.com/grafana/jfr-parser/parser/types"
)

// reference: https://github.com/grafana/jfr-parser/blob/main/pprof/symbols.go

var (
// jdk/internal/reflect/GeneratedMethodAccessor31
generatedMethodAccessor = regexp.MustCompile(`^(jdk/internal/reflect/GeneratedMethodAccessor)(\d+)$`)

// org/example/rideshare/OrderService$$Lambda$669.0x0000000800fd7318.run
// Fib$$Lambda.0x00007ffa600c4da0.run
lambda = regexp.MustCompile(`^(.+\$\$Lambda)(\$?\d*[./](0x)?[\da-f]+|\d+)$`)

// libzstd-jni-1.5.1-16931311898282279136.so.Java_com_github_luben_zstd_ZstdInputStreamNoFinalizer_decompressStream
libzstd = regexp.MustCompile(`^(\.?/tmp/)?(libzstd-jni-\d+\.\d+\.\d+-)(\d+)(\.so)( \(deleted\))?$`)

// ./tmp/libamazonCorrettoCryptoProvider109b39cf33c563eb.so
// ./tmp/amazonCorrettoCryptoProviderNativeLibraries.7382c2f79097f415/libcrypto.so (deleted)
libcrypto = regexp.MustCompile(`^(\.?/tmp/)?(lib)?(amazonCorrettoCryptoProvider)(NativeLibraries\.)?([0-9a-f]{16})(/libcrypto|/libamazonCorrettoCryptoProvider)?(\.so)( \(deleted\))?$`)

// libasyncProfiler-linux-arm64-17b9a1d8156277a98ccc871afa9a8f69215f92.so
libasyncProfiler = regexp.MustCompile(`^(\.?/tmp/)?(libasyncProfiler)-(linux-arm64|linux-musl-x64|linux-x64|macos)-(17b9a1d8156277a98ccc871afa9a8f69215f92)(\.so)( \(deleted\))?$`)

// TODO: ./tmp/snappy-1.1.8-6fb9393a-3093-4706-a7e4-837efe01d078-libsnappyjava.so
)

func cleanse(frame string) string {
frame = generatedMethodAccessor.ReplaceAllString(frame, "${1}_")
frame = lambda.ReplaceAllString(frame, "${1}_")
frame = libzstd.ReplaceAllString(frame, "libzstd-jni-_.so")
frame = libcrypto.ReplaceAllString(frame, "libamazonCorrettoCryptoProvider_.so")
frame = libasyncProfiler.ReplaceAllString(frame, "libasyncProfiler-_.so")
return frame
}

func processSyms(ref *types.SymbolList) {
for i := range ref.Symbol {
ref.Symbol[i].String = cleanse(ref.Symbol[i].String)
}
}

Large diffs are not rendered by default.

519 changes: 260 additions & 259 deletions receiver/pyroscopereceiver/testdata/memory_example_alloc_in_new_tlab.pb

Large diffs are not rendered by default.

521 changes: 260 additions & 261 deletions receiver/pyroscopereceiver/testdata/memory_example_live_object.pb

Large diffs are not rendered by default.

0 comments on commit 52d577d

Please sign in to comment.