@@ -289,26 +289,31 @@ func (r *ParcaReporter) ReportTraceEvent(trace *libpf.Trace,
289289 r .sampleWriter .Temporality .AppendString ("delta" )
290290 r .offcpuSamples .Inc ()
291291 case support .TraceOriginMemory :
292+ mod , ok := meta .OriginData .(* oomprof.Sample )
293+ if ! ok {
294+ log .Warnf ("memory trace event missing OriginData (got %T)" , meta .OriginData )
295+ break
296+ }
292297 // TODO: this isn't necessarily correct and should be extracted from the Go process somehow.
293298 memPeriod := int64 (512 * 1024 ) // 512 KiB
294299 // Write 4 memory samples
295300 // 1. inuse_objects (Allocs - Frees)
296- if meta .Allocs != meta .Frees {
301+ if mod .Allocs != mod .Frees {
297302 r .sampleWriter .Temporality .AppendNull ()
298- writeSample (int64 (meta .Allocs - meta .Frees ), 0 , memPeriod , "memory" , "inuse_objects" , "count" , "space" , "bytes" )
303+ writeSample (int64 (mod .Allocs - mod .Frees ), 0 , memPeriod , "memory" , "inuse_objects" , "count" , "space" , "bytes" )
299304 }
300305 // 2. inuse_space (AllocBytes - FreeBytes)
301- if meta .AllocBytes != meta .FreeBytes {
306+ if mod .AllocBytes != mod .FreeBytes {
302307 r .sampleWriter .Temporality .AppendNull ()
303- writeSample (int64 (meta .AllocBytes - meta .FreeBytes ), 0 , memPeriod , "memory" , "inuse_space" , "bytes" , "space" , "bytes" )
308+ writeSample (int64 (mod .AllocBytes - mod .FreeBytes ), 0 , memPeriod , "memory" , "inuse_space" , "bytes" , "space" , "bytes" )
304309 }
305310 if r .reportAllocs {
306311 // 3. alloc_objects
307312 r .sampleWriter .Temporality .AppendNull ()
308- writeSample (int64 (meta .Allocs ), 0 , memPeriod , "memory" , "alloc_objects" , "count" , "space" , "bytes" )
313+ writeSample (int64 (mod .Allocs ), 0 , memPeriod , "memory" , "alloc_objects" , "count" , "space" , "bytes" )
309314 // 4. alloc_space
310315 r .sampleWriter .Temporality .AppendNull ()
311- writeSample (int64 (meta .AllocBytes ), 0 , memPeriod , "memory" , "alloc_space" , "bytes" , "space" , "bytes" )
316+ writeSample (int64 (mod .AllocBytes ), 0 , memPeriod , "memory" , "alloc_space" , "bytes" , "space" , "bytes" )
312317 }
313318 r .memorySamples .Inc ()
314319 case support .TraceOriginCuda :
@@ -333,17 +338,22 @@ func (r *ParcaReporter) reportTraceEventV2(trace *libpf.Trace,
333338 case support .TraceOriginOffCPU :
334339 r .writeSampleV2 (trace , meta , labelResult , meta .OffTime , uint64 (time .Second .Nanoseconds ()), 0 , true , "parca_agent" , "wallclock" , "nanoseconds" , "samples" , "count" )
335340 case support .TraceOriginMemory :
341+ mod , ok := meta .OriginData .(* oomprof.Sample )
342+ if ! ok {
343+ log .Warnf ("memory trace event missing OriginData (got %T)" , meta .OriginData )
344+ break
345+ }
336346 log .Infof ("Received memory trace event for TID %d, PID %d, comm %s" , meta .TID , meta .PID , meta .Comm )
337347 memPeriod := int64 (512 * 1024 ) // 512 KiB
338- if meta .Allocs != meta .Frees {
339- r .writeSampleV2 (trace , meta , labelResult , int64 (meta .Allocs - meta .Frees ), 0 , memPeriod , false , "memory" , "inuse_objects" , "count" , "space" , "bytes" )
348+ if mod .Allocs != mod .Frees {
349+ r .writeSampleV2 (trace , meta , labelResult , int64 (mod .Allocs - mod .Frees ), 0 , memPeriod , false , "memory" , "inuse_objects" , "count" , "space" , "bytes" )
340350 }
341- if meta .AllocBytes != meta .FreeBytes {
342- r .writeSampleV2 (trace , meta , labelResult , int64 (meta .AllocBytes - meta .FreeBytes ), 0 , memPeriod , false , "memory" , "inuse_space" , "bytes" , "space" , "bytes" )
351+ if mod .AllocBytes != mod .FreeBytes {
352+ r .writeSampleV2 (trace , meta , labelResult , int64 (mod .AllocBytes - mod .FreeBytes ), 0 , memPeriod , false , "memory" , "inuse_space" , "bytes" , "space" , "bytes" )
343353 }
344354 if r .reportAllocs {
345- r .writeSampleV2 (trace , meta , labelResult , int64 (meta .Allocs ), 0 , memPeriod , false , "memory" , "alloc_objects" , "count" , "space" , "bytes" )
346- r .writeSampleV2 (trace , meta , labelResult , int64 (meta .AllocBytes ), 0 , memPeriod , false , "memory" , "alloc_space" , "bytes" , "space" , "bytes" )
355+ r .writeSampleV2 (trace , meta , labelResult , int64 (mod .Allocs ), 0 , memPeriod , false , "memory" , "alloc_objects" , "count" , "space" , "bytes" )
356+ r .writeSampleV2 (trace , meta , labelResult , int64 (mod .AllocBytes ), 0 , memPeriod , false , "memory" , "alloc_space" , "bytes" , "space" , "bytes" )
347357 }
348358 case support .TraceOriginCuda :
349359 r .writeSampleV2 (trace , meta , labelResult , meta .OffTime , uint64 (time .Second .Nanoseconds ()), 1 , true , "parca_agent" , "cuda" , "nanoseconds" , "cuda" , "nanoseconds" )
@@ -734,10 +744,7 @@ func (r *ParcaReporter) SampleEvents(oomprofSamples []oomprof.Sample, meta oompr
734744 }
735745 }
736746
737- traceEventMeta .AllocBytes = sample .AllocBytes
738- traceEventMeta .Allocs = sample .Allocs
739- traceEventMeta .FreeBytes = sample .FreeBytes
740- traceEventMeta .Frees = sample .Frees
747+ traceEventMeta .OriginData = & sample
741748
742749 // Report the trace event
743750 if err := r .ReportTraceEvent (t , traceEventMeta ); err != nil {
0 commit comments