Commit 512a7c7
committed
fix(profiling): remove unnecessary access to
We've been seeing a low number of crashes that have the following stack
traces.
```
PyFrame_FastToLocalsWithError
_PyObject_GenericGetAttrWithDict
__pyx_f_7ddtrace_9profiling_9collector_10_traceback__extract_class_name.constprop.0
__pyx_pw_7ddtrace_9profiling_9collector_10_traceback_5pyframe_to_frames
```
which corresponds to `value = frame.f_locals[argname]` in
`extract_class_name()` function.
Fore more details see notebook,
https://app.datadoghq.com/notebook/13515661/pyframe-to-frames-crashes
The reason this could lead to a crash is that the `frame` could be in an
invalid state, partially deallocated, or corrupted. And this doesn't
happen on our stack sampler (Echion) as it doesn't use it, and just use
`co_qualname` (Python 3.11+) or `co_name` (Python < 3.11)
This code is no longer needed as we don't use `class_name` field from
`DDFrame` named tuple. Memory profiler has been putting an empty string.
Lock profiler populated it but then it didn't export it in the sample.
More appropriate way to populate the class name for Python versions
3.11+ would be using `co_qualname` as Echion does. I'll follow up with
this in a separate PR. And this is why we see fully qualified name on
our CPU time view, but function name only on memory/lock views.
CPU time view
<img width="206" height="94" alt="Screenshot 2025-11-26 at 2 02 50 PM"
src="https://github.com/user-attachments/assets/a56efc8a-0dd2-41c2-8fab-5cc786d3a737"
/>
Memory view
<img width="141" height="94" alt="Screenshot 2025-11-26 at 2 02 35 PM"
src="https://github.com/user-attachments/assets/efa917f8-40c8-4818-88e7-9c157bdfd5cf"
/>
<!-- Provide an overview of the change and motivation for the change -->
<!-- Describe your testing strategy or note what tests are included -->
<!-- Note any risks associated with this change, or "None" if no risks
-->
<!-- Any other information that would be helpful for reviewers -->
(cherry picked from commit 124b19d)frame.f_locals (#15434)1 parent ea3cfae commit 512a7c7
File tree
8 files changed
+15
-56
lines changed- ddtrace/profiling
- collector
- releasenotes/notes
- tests/profiling/collector
8 files changed
+15
-56
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
135 | 133 | | |
136 | 134 | | |
137 | 135 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | 136 | | |
145 | 137 | | |
146 | 138 | | |
| |||
297 | 289 | | |
298 | 290 | | |
299 | 291 | | |
300 | | - | |
| 292 | + | |
301 | 293 | | |
302 | 294 | | |
303 | 295 | | |
| |||
306 | 298 | | |
307 | 299 | | |
308 | 300 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | 301 | | |
313 | 302 | | |
314 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 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 | 11 | | |
37 | 12 | | |
38 | 13 | | |
| |||
48 | 23 | | |
49 | 24 | | |
50 | 25 | | |
51 | | - | |
| 26 | + | |
52 | 27 | | |
53 | 28 | | |
54 | 29 | | |
| |||
92 | 67 | | |
93 | 68 | | |
94 | 69 | | |
95 | | - | |
| 70 | + | |
96 | 71 | | |
97 | 72 | | |
98 | 73 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | 320 | | |
322 | 321 | | |
323 | 322 | | |
| |||
330 | 329 | | |
331 | 330 | | |
332 | 331 | | |
333 | | - | |
334 | 332 | | |
335 | 333 | | |
336 | 334 | | |
| |||
346 | 344 | | |
347 | 345 | | |
348 | 346 | | |
349 | | - | |
350 | 347 | | |
351 | 348 | | |
352 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | | - | |
| 96 | + | |
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
| |||
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | | - | |
160 | 158 | | |
161 | 159 | | |
162 | 160 | | |
163 | 161 | | |
164 | | - | |
| 162 | + | |
165 | 163 | | |
166 | 164 | | |
167 | 165 | | |
| |||
205 | 203 | | |
206 | 204 | | |
207 | 205 | | |
208 | | - | |
209 | 206 | | |
210 | 207 | | |
211 | 208 | | |
| |||
229 | 226 | | |
230 | 227 | | |
231 | 228 | | |
232 | | - | |
233 | 229 | | |
234 | 230 | | |
235 | 231 | | |
| |||
258 | 254 | | |
259 | 255 | | |
260 | 256 | | |
261 | | - | |
262 | 257 | | |
263 | 258 | | |
264 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
| 119 | + | |
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
0 commit comments