@@ -14,8 +14,8 @@ import (
14
14
"github.com/pyroscope-io/pyroscope/pkg/storage/tree"
15
15
)
16
16
17
- func ParseJFR (ctx context.Context , r io. Reader , s storage. Putter , pi * storage.PutInput ) (err error ) {
18
- chunks , err := parser .Parse (r )
17
+ func ParseJFR (ctx context.Context , s storage. Putter , body io. Reader , pi * storage.PutInput ) (err error ) {
18
+ chunks , err := parser .Parse (body )
19
19
if err != nil {
20
20
return fmt .Errorf ("unable to parse JFR format: %w" , err )
21
21
}
@@ -24,11 +24,10 @@ func ParseJFR(ctx context.Context, r io.Reader, s storage.Putter, pi *storage.Pu
24
24
err = multierror .Append (err , pErr )
25
25
}
26
26
}
27
- pi .Val = nil
28
27
return err
29
28
}
30
29
31
- func parse (ctx context.Context , c parser.Chunk , s storage.Putter , pi * storage.PutInput ) (err error ) {
30
+ func parse (ctx context.Context , c parser.Chunk , s storage.Putter , piOriginal * storage.PutInput ) (err error ) {
32
31
var event , alloc , lock string
33
32
cpu := tree .New ()
34
33
wall := tree .New ()
@@ -84,83 +83,50 @@ func parse(ctx context.Context, c parser.Chunk, s storage.Putter, pi *storage.Pu
84
83
}
85
84
}
86
85
}
87
- labels := pi .Key .Labels ()
88
- prefix := labels ["__name__" ]
86
+
87
+ labelsOriginal := piOriginal .Key .Labels ()
88
+ prefix := labelsOriginal ["__name__" ]
89
+
90
+ cb := func (n string , t * tree.Tree , u metadata.Units ) {
91
+ labels := map [string ]string {}
92
+ for k , v := range labelsOriginal {
93
+ labels [k ] = v
94
+ }
95
+ labels ["__name__" ] = prefix + "." + n
96
+ pi := & storage.PutInput {
97
+ StartTime : piOriginal .StartTime ,
98
+ EndTime : piOriginal .EndTime ,
99
+ Key : segment .NewKey (labels ),
100
+ Val : t ,
101
+ SpyName : piOriginal .SpyName ,
102
+ SampleRate : piOriginal .SampleRate ,
103
+ Units : u ,
104
+ AggregationType : metadata .SumAggregationType ,
105
+ }
106
+ if putErr := s .Put (ctx , pi ); putErr != nil {
107
+ err = multierror .Append (err , putErr )
108
+ }
109
+ }
110
+
89
111
if event == "cpu" || event == "itimer" || event == "wall" {
90
112
profile := event
91
113
if event == "wall" {
92
114
profile = "cpu"
93
115
}
94
- labels ["__name__" ] = prefix + "." + profile
95
- pi .Key = segment .NewKey (labels )
96
- pi .Val = cpu
97
- pi .Units = metadata .SamplesUnits
98
- pi .AggregationType = metadata .SumAggregationType
99
- if putErr := s .Put (ctx , pi ); putErr != nil {
100
- err = multierror .Append (err , putErr )
101
- }
116
+ cb (profile , cpu , metadata .SamplesUnits )
102
117
}
103
118
if event == "wall" {
104
- labels ["__name__" ] = prefix + "." + event
105
- pi .Key = segment .NewKey (labels )
106
- pi .Val = wall
107
- pi .Units = metadata .SamplesUnits
108
- pi .AggregationType = metadata .SumAggregationType
109
- if putErr := s .Put (ctx , pi ); putErr != nil {
110
- err = multierror .Append (err , putErr )
111
- }
119
+ cb (event , wall , metadata .SamplesUnits )
112
120
}
113
121
if alloc != "" {
114
- labels ["__name__" ] = prefix + ".alloc_in_new_tlab_objects"
115
- pi .Key = segment .NewKey (labels )
116
- pi .Val = inTLABObjects
117
- pi .Units = metadata .ObjectsUnits
118
- pi .AggregationType = metadata .SumAggregationType
119
- if putErr := s .Put (ctx , pi ); putErr != nil {
120
- err = multierror .Append (err , putErr )
121
- }
122
- labels ["__name__" ] = prefix + ".alloc_in_new_tlab_bytes"
123
- pi .Key = segment .NewKey (labels )
124
- pi .Val = inTLABBytes
125
- pi .Units = metadata .BytesUnits
126
- pi .AggregationType = metadata .SumAggregationType
127
- if putErr := s .Put (ctx , pi ); putErr != nil {
128
- err = multierror .Append (err , putErr )
129
- }
130
- labels ["__name__" ] = prefix + ".alloc_outside_tlab_objects"
131
- pi .Key = segment .NewKey (labels )
132
- pi .Val = outTLABObjects
133
- pi .Units = metadata .ObjectsUnits
134
- pi .AggregationType = metadata .SumAggregationType
135
- if putErr := s .Put (ctx , pi ); putErr != nil {
136
- err = multierror .Append (err , putErr )
137
- }
138
- labels ["__name__" ] = prefix + ".alloc_outside_tlab_bytes"
139
- pi .Key = segment .NewKey (labels )
140
- pi .Val = outTLABBytes
141
- pi .Units = metadata .BytesUnits
142
- pi .AggregationType = metadata .SumAggregationType
143
- if putErr := s .Put (ctx , pi ); putErr != nil {
144
- err = multierror .Append (err , putErr )
145
- }
122
+ cb ("alloc_in_new_tlab_objects" , inTLABObjects , metadata .ObjectsUnits )
123
+ cb ("alloc_in_new_tlab_bytes" , inTLABBytes , metadata .BytesUnits )
124
+ cb ("alloc_outside_tlab_objects" , outTLABObjects , metadata .ObjectsUnits )
125
+ cb ("alloc_outside_tlab_bytes" , outTLABBytes , metadata .BytesUnits )
146
126
}
147
127
if lock != "" {
148
- labels ["__name__" ] = prefix + ".lock_count"
149
- pi .Key = segment .NewKey (labels )
150
- pi .Val = lockSamples
151
- pi .Units = metadata .LockSamplesUnits
152
- pi .AggregationType = metadata .SumAggregationType
153
- if putErr := s .Put (ctx , pi ); putErr != nil {
154
- err = multierror .Append (err , putErr )
155
- }
156
- labels ["__name__" ] = prefix + ".lock_duration"
157
- pi .Key = segment .NewKey (labels )
158
- pi .Val = lockDuration
159
- pi .Units = metadata .LockNanosecondsUnits
160
- pi .AggregationType = metadata .SumAggregationType
161
- if putErr := s .Put (ctx , pi ); putErr != nil {
162
- err = multierror .Append (err , putErr )
163
- }
128
+ cb ("lock_count" , lockSamples , metadata .LockSamplesUnits )
129
+ cb ("lock_duration" , lockDuration , metadata .LockNanosecondsUnits )
164
130
}
165
131
return err
166
132
}
0 commit comments