@@ -46,12 +46,9 @@ func Transform(dic pprofile.ProfilesDictionary, resource pcommon.Resource, scope
4646// and mixing profiles will make profiling information unusable.
4747func checkProfileType (dic pprofile.ProfilesDictionary , profile pprofile.Profile ) error {
4848 sampleType := profile .SampleType ()
49- if sampleType .Len () != 1 {
50- return fmt .Errorf ("expected 1 sample type but got %d" , sampleType .Len ())
51- }
5249
53- sType := getString (dic , int (sampleType .At ( 0 ). TypeStrindex ()))
54- sUnit := getString (dic , int (sampleType .At ( 0 ). UnitStrindex ()))
50+ sType := getString (dic , int (sampleType .TypeStrindex ()))
51+ sUnit := getString (dic , int (sampleType .UnitStrindex ()))
5552
5653 // Make sure only on-CPU profiling data is accepted at the moment.
5754 // This needs to match with
@@ -94,7 +91,7 @@ func stackPayloads(dic pprofile.ProfilesDictionary, resource pcommon.Resource, s
9491 }
9592
9693 for _ , sample := range profile .Sample ().All () {
97- frames , frameTypes , leafFrame , err := stackFrames (dic , profile , sample )
94+ frames , frameTypes , leafFrame , err := stackFrames (dic , sample )
9895 if err != nil {
9996 return nil , fmt .Errorf ("failed to create stackframes: %w" , err )
10097 }
@@ -141,8 +138,8 @@ func stackPayloads(dic pprofile.ProfilesDictionary, resource pcommon.Resource, s
141138 event .TimeStamp = newUnixTime64 (t )
142139
143140 count := 1
144- if j < sample .Value ().Len () {
145- count = int (sample .Value ().At (j ))
141+ if j < sample .Values ().Len () {
142+ count = int (sample .Values ().At (j ))
146143 }
147144 for range count {
148145 stackPayload = append (stackPayload , StackPayload {
@@ -234,8 +231,9 @@ func stackTraceEvent(dic pprofile.ProfilesDictionary, traceID string, sample ppr
234231 continue
235232 }
236233 attr := dic .AttributeTable ().At (int (idx ))
234+ key := dic .StringTable ().At (int (attr .KeyStrindex ()))
237235
238- switch attribute .Key (attr . Key () ) {
236+ switch attribute .Key (key ) {
239237 case semconv .ThreadNameKey :
240238 event .ThreadName = attr .Value ().AsString ()
241239 case semconv .ProcessExecutableNameKey :
@@ -270,10 +268,11 @@ func stackTrace(stackTraceID string, frames []StackFrame, frameTypes []libpf.Fra
270268 }
271269}
272270
273- func stackFrames (dic pprofile.ProfilesDictionary , profile pprofile.Profile , sample pprofile.Sample ) ([]StackFrame , []libpf.FrameType , * frameID , error ) {
274- frames := make ([]StackFrame , 0 , sample .LocationsLength ())
271+ func stackFrames (dic pprofile.ProfilesDictionary , sample pprofile.Sample ) ([]StackFrame , []libpf.FrameType , * frameID , error ) {
272+ stack := dic .StackTable ().At (int (sample .StackIndex ()))
273+ frames := make ([]StackFrame , 0 , stack .LocationIndices ().Len ())
275274
276- locations := getLocations (dic , profile , sample )
275+ locations := getLocations (dic , stack )
277276 totalFrames := 0
278277 for _ , location := range locations {
279278 totalFrames += location .Line ().Len ()
@@ -328,7 +327,8 @@ func stackFrames(dic pprofile.ProfilesDictionary, profile pprofile.Profile, samp
328327func getFrameID (dic pprofile.ProfilesDictionary , location pprofile.Location ) * frameID {
329328 // The MappingIndex is known to be valid.
330329 fileID := libpf.FileID {}
331- if location .HasMappingIndex () {
330+
331+ if location .MappingIndex () > 0 {
332332 mapping := dic .MappingTable ().At (int (location .MappingIndex ()))
333333 fileID , _ = getBuildID (dic , mapping )
334334 }
@@ -377,7 +377,9 @@ func getStringFromAttribute(dic pprofile.ProfilesDictionary, record attributable
377377 return "" , fmt .Errorf ("requested attribute index (%d) " +
378378 "exceeds size of attribute table (%d)" , idx , lenAttrTable )
379379 }
380- if dic .AttributeTable ().At (idx ).Key () == attrKey {
380+
381+ key := dic .StringTable ().At (int (dic .AttributeTable ().At (idx ).KeyStrindex ()))
382+ if key == attrKey {
381383 return dic .AttributeTable ().At (idx ).Value ().AsString (), nil
382384 }
383385 }
@@ -405,7 +407,11 @@ func executables(dic pprofile.ProfilesDictionary, mappings pprofile.MappingSlice
405407 metadata := make ([]ExeMetadata , 0 , mappings .Len ())
406408 lastSeen := GetStartOfWeekFromTime (time .Now ())
407409
408- for _ , mapping := range mappings .All () {
410+ for i , mapping := range mappings .All () {
411+ if i == 0 {
412+ continue
413+ }
414+
409415 filename := dic .StringTable ().At (int (mapping .FilenameStrindex ()))
410416 if filename == "" {
411417 // This is true for interpreted languages like Python.
@@ -460,18 +466,13 @@ func stackTraceID(frames []StackFrame) (string, error) {
460466 return traceHash .Base64 (), nil
461467}
462468
463- func getLocations (dic pprofile.ProfilesDictionary , profile pprofile.Profile , sample pprofile. Sample ) []pprofile.Location {
464- locations := make ([]pprofile.Location , 0 , sample . LocationsLength ())
469+ func getLocations (dic pprofile.ProfilesDictionary , stack pprofile.Stack ) []pprofile.Location {
470+ locations := make ([]pprofile.Location , 0 , stack . LocationIndices (). Len ())
465471
466- firstIndexPos := int (sample .LocationsStartIndex ())
467- lastIndexPos := int (sample .LocationsStartIndex () + sample .LocationsLength ())
468- lastIndexPos = min (lastIndexPos , profile .LocationIndices ().Len ())
469- for i := firstIndexPos ; i < lastIndexPos ; i ++ {
470- locationIndex := int (profile .LocationIndices ().At (i ))
471- if locationIndex < dic .LocationTable ().Len () {
472- locations = append (locations , dic .LocationTable ().At (locationIndex ))
473- }
472+ for i := range stack .LocationIndices ().All () {
473+ locations = append (locations , dic .LocationTable ().At (i ))
474474 }
475+
475476 return locations
476477}
477478
@@ -498,7 +499,7 @@ func newHostMetadata(dic pprofile.ProfilesDictionary, resource pcommon.Resource,
498499
499500 addEventHostData (attrs , resource .Attributes ())
500501 addEventHostData (attrs , scope .Attributes ())
501- addEventHostData (attrs , pprofile .FromAttributeIndices (dic .AttributeTable (), profile ))
502+ addEventHostData (attrs , pprofile .FromAttributeIndices (dic .AttributeTable (), profile , dic ))
502503
503504 if len (attrs ) == 0 {
504505 return nil
0 commit comments