Skip to content

Commit

Permalink
feat: add lock profiling support in jfr parser. (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeaumont authored Apr 8, 2022
1 parent c8d92a3 commit 10baacd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/pyroscope-io/client v0.0.0-20211206204731-3fd0a4b8239c
github.com/pyroscope-io/dotnetdiag v1.2.1
github.com/pyroscope-io/goldga v0.4.2-0.20220218190441-817afcc3a7f1
github.com/pyroscope-io/jfr-parser v0.3.0
github.com/pyroscope-io/jfr-parser v0.4.0
github.com/rlmcpherson/s3gof3r v0.5.0
github.com/shirou/gopsutil v3.21.4+incompatible
github.com/sirupsen/logrus v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ github.com/pyroscope-io/dotnetdiag v1.2.1 h1:3XEMrfFJnZ87BiEhozyQKmCUAuMd/Spq7KC
github.com/pyroscope-io/dotnetdiag v1.2.1/go.mod h1:eFUEHCp4eD1TgcXMlJihC+R4MrqGf7nTRdWxNADbDHA=
github.com/pyroscope-io/goldga v0.4.2-0.20220218190441-817afcc3a7f1 h1:T1fDdt3E3UpaGZ7tRF2IYrUFwNyuPlIWGeCOjfINp1s=
github.com/pyroscope-io/goldga v0.4.2-0.20220218190441-817afcc3a7f1/go.mod h1:PbX5bxlj/WxyKIEAxYgNMNWUpXP4rt9GqtjfvTf8m+I=
github.com/pyroscope-io/jfr-parser v0.3.0 h1:d37SB6tW5h45kFpglfT/YRflWXDZTo9wjWKoSLdspGM=
github.com/pyroscope-io/jfr-parser v0.3.0/go.mod h1:ZMcbJjfDkOwElEK8CvUJbpetztRWRXszCmf5WU0erV8=
github.com/pyroscope-io/jfr-parser v0.4.0 h1:K5daiLhW4XP2miyCAlw67hqpd7WSo4ROVc/DXSfpECk=
github.com/pyroscope-io/jfr-parser v0.4.0/go.mod h1:ZMcbJjfDkOwElEK8CvUJbpetztRWRXszCmf5WU0erV8=
github.com/pyroscope-io/revive v1.0.6-0.20210330033039-4a71146f9dc1 h1:0v9lBNgdmVtpyyk9PP/DfpJlOHkXriu5YgNlrhQw5YE=
github.com/pyroscope-io/revive v1.0.6-0.20210330033039-4a71146f9dc1/go.mod h1:tSw34BaGZ0iF+oVKDOjq1/LuxGifgW7shaJ6+dBYFXg=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
36 changes: 35 additions & 1 deletion pkg/convert/jfr/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ func ParseJFR(ctx context.Context, r io.Reader, s storage.Putter, pi *storage.Pu
}

func parse(ctx context.Context, c parser.Chunk, s storage.Putter, pi *storage.PutInput) (err error) {
var event, alloc string
var event, alloc, lock string
cpu := tree.New()
wall := tree.New()
inTLABObjects := tree.New()
inTLABBytes := tree.New()
outTLABObjects := tree.New()
outTLABBytes := tree.New()
lockSamples := tree.New()
lockDuration := tree.New()
for _, e := range c.Events {
switch e.(type) {
case *parser.ExecutionSample:
Expand All @@ -57,13 +59,27 @@ func parse(ctx context.Context, c parser.Chunk, s storage.Putter, pi *storage.Pu
outTLABObjects.InsertStackString(fs, 1)
outTLABBytes.InsertStackString(fs, uint64(oa.AllocationSize))
}
case *parser.JavaMonitorEnter:
jme := e.(*parser.JavaMonitorEnter)
if fs := frames(jme.StackTrace); fs != nil {
lockSamples.InsertStackString(fs, 1)
lockDuration.InsertStackString(fs, uint64(jme.Duration))
}
case *parser.ThreadPark:
tp := e.(*parser.ThreadPark)
if fs := frames(tp.StackTrace); fs != nil {
lockSamples.InsertStackString(fs, 1)
lockDuration.InsertStackString(fs, uint64(tp.Duration))
}
case *parser.ActiveSetting:
as := e.(*parser.ActiveSetting)
switch as.Name {
case "event":
event = as.Value
case "alloc":
alloc = as.Value
case "lock":
lock = as.Value
}
}
}
Expand Down Expand Up @@ -127,6 +143,24 @@ func parse(ctx context.Context, c parser.Chunk, s storage.Putter, pi *storage.Pu
err = multierror.Append(err, putErr)
}
}
if lock != "" {
labels["__name__"] = prefix + ".lock_samples"
pi.Key = segment.NewKey(labels)
pi.Val = lockSamples
pi.Units = "samples"
pi.AggregationType = "sum"
if putErr := s.Put(ctx, pi); err != nil {
err = multierror.Append(err, putErr)
}
labels["__name__"] = prefix + ".lock_nanoseconds"
pi.Key = segment.NewKey(labels)
pi.Val = lockDuration
pi.Units = "nanoseconds"
pi.AggregationType = "sum"
if putErr := s.Put(ctx, pi); err != nil {
err = multierror.Append(err, putErr)
}
}
return err
}

Expand Down

0 comments on commit 10baacd

Please sign in to comment.