Skip to content

profiling c functions while running python #92326

Closed
@vainaixr

Description

@vainaixr

current scenario -

  1. if one wants to profile the c functions that are called when running python code, then it is either not possible, or not well documented.
  2. in the documentation it specifies,
    https://docs.python.org/dev/using/configure.html#cmdoption-enable-profiling
    https://docs.python.org/dev/using/configure.html#cmdoption-with-valgrind

but there is no example how to use them (assuming they can be used to profile c functions while running python code)

  1. related discussions,
    https://stackoverflow.com/questions/375913/how-can-i-profile-c-code-running-on-linux/378024#378024
    https://discuss.python.org/t/easier-way-to-look-into-the-cpython-implementation/15247/8

but there appears to be no way to profile c functions while running python code.

  1. one can get the backtrace but it requires to use an external debugger like lldb or gdb.

expected scenario -

  1. if this is already possible then add an example to the documentation page
  2. if not then, there could be a build option to display the backtrace, profiling of the c functions, like,
./configure --with-backtrace --with-c-profiling
  1. ideally one would want something like this when running python in the console,
>>> x = 1

with backtrace enabled,

backtrace
function_1 at file_1.c
function_2 at file_2.c
function_3 at file_1.c
function_1 at file_1.c

with profiling enabled,

 file_name                           total number of times called                     total time
function_1 at file_1.c                  n1                                             t1 sec
function_2 at file_2.c                  n2                                             t2 sec
  1. no use of external debugger for this, one would want to do this while running python in the console.

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