Commit f7999ce
authored
feat(profiling): add sample count to internal payload (#15177)
## Description
This PR adds data to the `internal` payload we send to `libdatadog`. In
this `internal` payload, we can push custom metrics (that are not
exposed to customers) but that we can access for analytics.
For the time being, I only added the number of Samples taken (one per
thread) and Sampling Events (one for each time we run `for_each_interp`)
for the current Profile. We may want to add more in the short term (e.g.
number of times adaptive sampling was adjusted, history of adaptive
sampling intervals, etc.)
In order to implement this feature in a way that keeps clear semantics
around locking the Profile object, I refactored the code not to `borrow`
only the single `Profile` but instead both the `Profile` and the
`ProfilerStats` (in which we store our metrics). To keep locking clear
and explicit, locking returns a `ProfileBorrow` objects which allows to
access both the `Profile` and the `ProfilerStats` and that is
RAII-compatible (automatically unlocks when it goes out of scope).
Note the PR does add some "lock contention" because we now need to take
the Profile lock in two new places (one for each metric we increment) –
it should be the same order of magnitude as what we already do though
(in number of lock acquisitions).
We plan to refactor Stack V2 in the short to avoid having to hold the
Profile / ProfilerStats lock during the upload, by using double
buffering or by releasing earlier (after the Profile data has been
serialised). This should improve the performance and reduce lost
Samples.
The PR also adds an integration test, ensuring that the generated JSON
string is correct (we can't guarantee exact numbers, but we can check
the numbers we have are meaningful).
**Note** I marked the PR as `no-changelog` as this feature isn't
public/visible by customers.
Open questions:
* What other metrics do we want to add?
This is an example of querying through the Events UI.
<img width="886" height="604" alt="image"
src="https://github.com/user-attachments/assets/53c3eae0-d29a-4446-9f1b-72ac29a75d60"
/>1 parent 73f2611 commit f7999ce
File tree
19 files changed
+372
-64
lines changed- ddtrace/internal/datadog/profiling
- dd_wrapper
- include
- src
- stack_v2
- include
- src
- tests
- profiling_v2/collector
- profiling/collector
19 files changed
+372
-64
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
| 10 | + | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| |||
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
| |||
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
| |||
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
56 | | - | |
57 | | - | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
8 | 6 | | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
| 29 | + | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
Lines changed: 23 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | | - | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
304 | 303 | | |
305 | 304 | | |
306 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
307 | 320 | | |
308 | 321 | | |
309 | 322 | | |
| |||
351 | 364 | | |
352 | 365 | | |
353 | 366 | | |
354 | | - | |
355 | | - | |
356 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
357 | 371 | | |
358 | 372 | | |
359 | 373 | | |
360 | 374 | | |
361 | 375 | | |
362 | 376 | | |
363 | 377 | | |
364 | | - | |
| 378 | + | |
| 379 | + | |
365 | 380 | | |
366 | 381 | | |
367 | 382 | | |
| |||
375 | 390 | | |
376 | 391 | | |
377 | 392 | | |
378 | | - | |
379 | 393 | | |
380 | 394 | | |
381 | 395 | | |
382 | 396 | | |
383 | 397 | | |
384 | 398 | | |
385 | | - | |
| 399 | + | |
| 400 | + | |
386 | 401 | | |
387 | 402 | | |
388 | 403 | | |
| |||
396 | 411 | | |
397 | 412 | | |
398 | 413 | | |
399 | | - | |
400 | 414 | | |
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
130 | 140 | | |
131 | | - | |
| 141 | + | |
132 | 142 | | |
133 | | - | |
134 | | - | |
| 143 | + | |
135 | 144 | | |
136 | 145 | | |
137 | 146 | | |
| |||
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| 231 | + | |
222 | 232 | | |
223 | 233 | | |
0 commit comments