Skip to content

Commit e321ef8

Browse files
committed
Add synthetic frame for queue.get(block=True)
Whenever some python code is waiting for an item to arrive in a queue, the current flame grpah will only show the function where the queue.get is called, the rest of the stack is not showing. This is unfortunate because we would need to remap those stacks into WAITING state. This change adds another synthetic frame for this specific frame when the source code at the end of the sampled stack has `.get(block=True` This looks like it could trigger a lot of false positives but it will only happen when this is the leaf of the stack so we would need this code to call some native code that does not appear in the stack but where we spend a lot of time.
1 parent 77960a2 commit e321ef8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

codeguru_profiler_agent/sampling_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
TIME_SLEEP_FRAME = Frame(name="<Sleep>")
1313
LXML_SCHEMA_FRAME = Frame(name="lxml.etree:XMLSchema:__init__")
14+
QUEUE_BLOCKING_GET_FRAME = Frame(name="<queue.get>")
1415

1516

1617
def get_stacks(threads_to_sample, excluded_threads, max_depth):
@@ -78,6 +79,8 @@ def _maybe_append_synthetic_frame(result, frame, line_no):
7879
line = linecache.getline(frame.f_code.co_filename, line_no).strip()
7980
if "sleep(" in line:
8081
result.append(TIME_SLEEP_FRAME)
82+
elif ".get(block=True" in line:
83+
result.append(QUEUE_BLOCKING_GET_FRAME)
8184
elif "etree.XMLSchema(" in line:
8285
result.append(LXML_SCHEMA_FRAME)
8386

0 commit comments

Comments
 (0)