开发者

How can I "hook into" Python from C++ when it executes a function? My goal is to profile

I'm implementing a profiler in an开发者_如何学Python application and I'm a little flummoxed about how to implement Python profiling such that the results can be displayed in my existing tool. The application allows for Python scripting via communication with the python interpreter.

I was wondering if anyone has ideas on how to profile Python functions from C++

Thank you for your suggestions :)


Well not sure what your goal is, but I'd personally not start from zero but use the existing modules for profiling. The cprofile module was written in C and should be easily extensible if the documentation is to be believed: http://docs.python.org/release/3.2/library/profile.html#extensions-deriving-better-profilers


The usual technique for profiling already-existing functions that we use in Lua a lot is to overwrite the function with your own version that will start timing, call the original function, and stop timing, returning the value that the original function returned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜