Commit 031905b
authored
fix(profiling): always report CPU time regardless of Thread running state (#16273)
## Description
This PR updates the Python Profiler logic to always report CPU Time for
sampled Threads, regardless of whether they were running when we
computed their spent CPU time.
### Why?
In [Incident 48491](https://app.datadoghq.com/incidents/48491), we
investigated an issue where following a `ddtrace` upgrade, one of our
Python services suddenly started reporting near zero CPU Time and no
Frames at all/empty flame graphs.
The investigation showed that this changed if we removed the check on
`is_running` and always reported CPU Time for each sampled Thread.
Originally, this check was introduced to avoid reporting CPU Time on
Stacks that were in fact idle states; however it also means it the
Thread runs between two Samples but then does not run when we "check
whether it is running", then we are blind to what it did during that
time.
On top of that, there is no reliable way to check whether a Thread is
running – checking this is by definition racy, and although there are
potential ways around it, we could never guarantee that the running
state we determined matched the one that the Thread was in when we
captured its Stack, meaning we could have discrepancies anyway.
Finally, several other Datadog Profilers have this bias and accept it,
so we should probably match that behaviour.
**Note** the performance difference will probably be negligible, but
this change may actually slightly improve our CPU usage as we will now
make one less system call.1 parent 4ce99ef commit 031905b
File tree
3 files changed
+8
-28
lines changed- ddtrace/internal/datadog/profiling/stack
- echion/echion
- src/echion
- releasenotes/notes
3 files changed
+8
-28
lines changedLines changed: 0 additions & 2 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 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
| |||
Lines changed: 4 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
| 587 | + | |
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | | - | |
644 | | - | |
| 643 | + | |
| 644 | + | |
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | | - | |
649 | 648 | | |
650 | 649 | | |
651 | 650 | | |
652 | 651 | | |
653 | 652 | | |
654 | 653 | | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
| 654 | + | |
666 | 655 | | |
667 | 656 | | |
668 | 657 | | |
| |||
673 | 662 | | |
674 | 663 | | |
675 | 664 | | |
676 | | - | |
677 | 665 | | |
678 | 666 | | |
679 | 667 | | |
680 | 668 | | |
681 | 669 | | |
682 | 670 | | |
683 | 671 | | |
684 | | - | |
685 | 672 | | |
686 | 673 | | |
687 | 674 | | |
688 | 675 | | |
689 | | - | |
690 | | - | |
691 | 676 | | |
692 | 677 | | |
693 | 678 | | |
694 | 679 | | |
695 | 680 | | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | 681 | | |
704 | 682 | | |
705 | 683 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments