Skip to content

Commit d0187b3

Browse files
mergify[bot]jd
andauthored
fix(profiling): compute number of allocation events correctly (#3393) (#3397)
(cherry picked from commit ec60e55) Co-authored-by: Julien Danjou <[email protected]>
1 parent 1aca997 commit d0187b3

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ddtrace/profiling/exporter/pprof.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ class _PprofConverter(object):
252252
),
253253
)
254254

255-
self._location_values[location_key]["alloc-samples"] = sum(event.nevents for event in events)
255+
self._location_values[location_key]["alloc-samples"] = round(
256+
sum(event.nevents * (event.capture_pct / 100.0) for event in events)
257+
)
256258
self._location_values[location_key]["alloc-space"] = round(
257259
sum(event.size / event.capture_pct * 100.0 for event in events)
258260
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes wrong numbers of memory allocation being reported in the memory profiler.

tests/profiling/exporter/test-pprof-exporter.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ sample {
152152
value: 0
153153
value: 0
154154
value: 0
155-
value: 3072
155+
value: 2294
156156
value: 104
157157
value: 58
158158
label {
@@ -414,7 +414,7 @@ sample {
414414
value: 0
415415
value: 0
416416
value: 0
417-
value: 1024
417+
value: 512
418418
value: 680
419419
value: 340
420420
label {
@@ -582,7 +582,7 @@ sample {
582582
value: 0
583583
value: 0
584584
value: 0
585-
value: 2048
585+
value: 1024
586586
value: 136
587587
value: 68
588588
label {
@@ -750,7 +750,7 @@ sample {
750750
value: 0
751751
value: 0
752752
value: 0
753-
value: 1024
753+
value: 338
754754
value: 133
755755
value: 44
756756
label {

0 commit comments

Comments
 (0)