Skip to content

Disjoint stacks with embedded Python interpreter #779

@emptyVoid

Description

@emptyVoid

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Profiling native applications employing embedded Python interpreter instances with native tracking enabled (--native) yields disjoint Python stacks.

Reporters are unable to match native stack frames against Python frames, since the following check doesn't work as designed:

if pidx >= 0 and "_PyEval_EvalFrameDefault" in symbol:

At least with our libpython3.11.so frame _PyEval_EvalFrameDefault is missing from the native stacks, instead only _PyEval_EvalFrame is present

The check should actually look like this:

    for nidx, native_frame in enumerate(native_stack):
        symbol = native_frame[0]
        if pidx >= 0 and ("_PyEval_EvalFrameDefault" in symbol
                          or ("_PyEval_EvalFrame" in symbol
                              and (nidx == len(native_stack) - 1
                                   or "_PyEval_EvalFrameDefault" not in native_stack[nidx + 1][0]))):

it additionally tries to guard against a nested call to _PyEval_EvalFrameDefault.

Expected Behavior

Python stacks are shown embedded in native stacks.

Steps To Reproduce

Too complicated to provide a small repro.

Memray Version

1.17.2

Python Version

3.11

Operating System

Linux

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions