@@ -133,6 +133,12 @@ type ParcaReporter struct {
133133 debuginfoUploadRequestBytes prometheus.Counter
134134 emptySamples prometheus.Counter
135135
136+ // Pre-created sample counters by type (avoid WithLabelValues allocations)
137+ cpuSamples prometheus.Counter
138+ gpuSamples prometheus.Counter
139+ offcpuSamples prometheus.Counter
140+ memorySamples prometheus.Counter
141+
136142 offlineModeConfig * OfflineModeConfig
137143
138144 // Protects the log file,
@@ -260,12 +266,12 @@ func (r *ParcaReporter) ReportTraceEvent(trace *libpf.Trace,
260266 case support .TraceOriginSampling :
261267 writeSample (1 , time .Second .Nanoseconds (), 1e9 / int64 (r .samplesPerSecond ), "parca_agent" , "samples" , "count" , "cpu" , "nanoseconds" )
262268 r .sampleWriter .Temporality .AppendString ("delta" )
269+ r .cpuSamples .Inc ()
263270 case support .TraceOriginOffCPU :
264271 writeSample (meta .OffTime , time .Second .Nanoseconds (), 1e9 / int64 (r .samplesPerSecond ), "parca_agent" , "wallclock" , "nanoseconds" , "samples" , "count" )
265272 r .sampleWriter .Temporality .AppendString ("delta" )
273+ r .offcpuSamples .Inc ()
266274 case support .TraceOriginMemory :
267- // This shouldn't happen too much so an info log is fine, revisit when we do continuous memory profiling.
268- log .Infof ("Received memory trace event for TID %d, PID %d, comm %s" , meta .TID , meta .PID , meta .Comm )
269275 // TODO: this isn't necessarily correct and should be extracted from the Go process somehow.
270276 memPeriod := int64 (512 * 1024 ) // 512 KiB
271277 // Write 4 memory samples
@@ -287,9 +293,11 @@ func (r *ParcaReporter) ReportTraceEvent(trace *libpf.Trace,
287293 r .sampleWriter .Temporality .AppendNull ()
288294 writeSample (int64 (meta .AllocBytes ), 0 , memPeriod , "memory" , "alloc_space" , "bytes" , "space" , "bytes" )
289295 }
296+ r .memorySamples .Inc ()
290297 case support .TraceOriginCuda :
291298 writeSample (meta .OffTime , time .Second .Nanoseconds (), 1e9 / int64 (r .samplesPerSecond ), "parca_agent" , "cuda" , "nanoseconds" , "cuda" , "nanoseconds" )
292299 r .sampleWriter .Temporality .AppendString ("delta" )
300+ r .gpuSamples .Inc ()
293301 }
294302
295303 return nil
@@ -480,36 +488,32 @@ func (r *ParcaReporter) ReportMetrics(_ uint32, ids []uint32, values []int64) {
480488 continue
481489 }
482490 f := strings .Replace (field .Field , "." , "_" , - 1 )
483- m , ok := r .otelLibraryMetrics [f ]
484- if ! ok {
485- switch field .Type {
486- case metrics .MetricTypeGauge :
487- g := prometheus .NewGauge (prometheus.GaugeOpts {
491+
492+ switch field .Type {
493+ case metrics .MetricTypeGauge :
494+ m , ok := r .otelLibraryMetrics [f ]
495+ if ! ok {
496+ m = prometheus .NewGauge (prometheus.GaugeOpts {
488497 Name : f ,
489498 Help : field .Desc ,
490499 })
491- r .reg .MustRegister (g )
492- m = g
493- case metrics .MetricTypeCounter :
494- c := prometheus .NewCounter (prometheus.CounterOpts {
500+ r .reg .MustRegister (m .(prometheus.Gauge ))
501+ r .otelLibraryMetrics [f ] = m
502+ }
503+ m .(prometheus.Gauge ).Set (float64 (val ))
504+ case metrics .MetricTypeCounter :
505+ m , ok := r .otelLibraryMetrics [f ]
506+ if ! ok {
507+ m = prometheus .NewCounter (prometheus.CounterOpts {
495508 Name : f ,
496509 Help : field .Desc ,
497510 })
498- r .reg .MustRegister (c )
499- m = c
500-
501- default :
502- log .Warnf ("Unknown metric type: %d" , field .Type )
503- continue
511+ r .reg .MustRegister (m .(prometheus.Counter ))
512+ r .otelLibraryMetrics [f ] = m
504513 }
505- r .otelLibraryMetrics [f ] = m
506- }
507- if counter , ok := m .(prometheus.Counter ); ok {
508- counter .Add (float64 (val ))
509- } else if gauge , ok := m .(prometheus.Gauge ); ok {
510- gauge .Set (float64 (val ))
511- } else {
512- log .Errorf ("Bad metric type (this should never happen): %v" , m )
514+ m .(prometheus.Counter ).Add (float64 (val ))
515+ default :
516+ log .Warnf ("Unknown metric type: %d" , field .Type )
513517 }
514518 }
515519}
@@ -629,11 +633,17 @@ func New(
629633 Help : "The number of empty samples reported to the Parca reporter" ,
630634 })
631635
636+ samplesByType := prometheus .NewCounterVec (prometheus.CounterOpts {
637+ Name : "parca_reporter_samples_total" ,
638+ Help : "Total number of samples by type" ,
639+ }, []string {"type" })
640+
632641 reg .MustRegister (sampleWriteRequestBytes )
633642 reg .MustRegister (sampleWrites )
634643 reg .MustRegister (stacktraceWriteRequestBytes )
635644 reg .MustRegister (debuginfoUploadRequestBytes )
636645 reg .MustRegister (emptySamples )
646+ reg .MustRegister (samplesByType )
637647
638648 r := & ParcaReporter {
639649 stopSignal : make (chan libpf.Void ),
@@ -663,6 +673,10 @@ func New(
663673 emptySamples : emptySamples ,
664674 stacktraceWriteRequestBytes : stacktraceWriteRequestBytes ,
665675 debuginfoUploadRequestBytes : debuginfoUploadRequestBytes ,
676+ cpuSamples : samplesByType .WithLabelValues ("cpu" ),
677+ gpuSamples : samplesByType .WithLabelValues ("gpu" ),
678+ offcpuSamples : samplesByType .WithLabelValues ("offcpu" ),
679+ memorySamples : samplesByType .WithLabelValues ("memory" ),
666680 offlineModeConfig : offlineModeConfig ,
667681 offlineModeLoggedStacks : loggedStacks ,
668682 }
@@ -1067,7 +1081,7 @@ func (r *ParcaReporter) reportDataToBackend(ctx context.Context, buf *bytes.Buff
10671081 return err
10681082 }
10691083
1070- log .Infof ( "[reporter] sending %d samples (%d bytes) to server " , record .NumRows (), buf .Len ())
1084+ log .Debugf ( "Sending profile with %d samples (%d bytes)" , record .NumRows (), buf .Len ())
10711085
10721086 client , err := r .client .Write (ctx )
10731087 if err != nil {
0 commit comments