Skip to content

sys.setprofile and equivalent C API don't track all callable C code #126056

@itamarst

Description

@itamarst

Bug report

Bug description:

import sys
import mmap

def prof(frame, event, arg):
    print(event, arg)

sys.setprofile(prof)

x = mmap.mmap(-1, 10_000)
open("/dev/null")

When run with Python 3.13 on Linux:

c_call <built-in function open>
call None
call None
return None
return None
c_return <built-in function open>
return None

No mention of mmap.mmap(), perhaps because it's a constructor of a type object.

(This is really an issue with the underlying C API, PyTrace_C_CALL is similarly not happening.)

As someone doing profiling, this means that any code running inside C type constructors is invisible, which is problematic and means I'm going to have to change how one of my profilers works.

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions