Profiling python C extensions

后端 未结 5 1633
無奈伤痛
無奈伤痛 2020-12-12 19:24

I have developed a python C-extension that receives data from python and compute some cpu intensive calculations. It\'s possible to profile the C-extension?

The prob

5条回答
  •  孤城傲影
    2020-12-12 19:55

    With gprof, you can profile any program that was properly compiled and linked (gcc -pg etc, in gprof's case). If you're using a Python version not built with gcc (e.g., the Windows precompiled version the PSF distributes), you'll need to research what equivalent tools exist for that platform and toolchain (in the Windows PSF case, maybe mingw can help). There may be "irrelevant" data there (internal C functions in the Python runtime), and, if so, the percentages shown by gprof may not be applicable -- but the absolute numbers (of calls, and durations thereof) are still valid, and you can post-process gprof's output (e.g., with a little Python script;-) to exclude the irrelevant data and compute the percentages you want.

提交回复
热议问题