|
From: Josef W. <Jos...@gm...> - 2008-02-11 18:01:40
|
Hi Sébastien, On Monday 11 February 2008, Sébastien Sablé wrote: > I have been able to push Python calls on the stack according to what you > explained and I can now correctly see them with Kcachegrind, which makes > profiling my application much easier. Cool. > I added a --python-mode option to callgrind, which will activate the > detection of PyEval_EvalFrameEx and use this function to get the python > context. > > The reason why I prefer to use callgrind instead of > hotshot/cProfile/profile is that my application mixes C and Python > (about 30% python, 15% C generated by Pyrex and 55% legacy C); so > hotshot gives me some very superficial results. Ah, I did not think about this use case of mixing C/Python. Good that this matches your requirements! The question now is if there is a possibility to integrate this with callgrind somehow. I understand that quite some people could find this useful. But to be true, the current solution looks quite "hacky" to me. To use it, one has to modify things in the python interpreter, and there is this special case for python in callgrind. Up to now, callgrind is independent from the language used, as long as there exists debug information for the binary. So, one way would be to add the patch as user contribution into a contrib/ directory. And if there is enough pressure for a distribution, it could provide the patched callgrind. Or I try to refactor most parts of callgrind to make it available as modules for other tools. And callgrind itself would shrink dramatically in code size. Not really realistic. Another way would be to try to achieve the same/similar result with a more general solution not specific for python, but for any type of interpreter. E.g. using client requests, which allow to specify function calls/returns happening in a high-level call-graph. I suppose that your PyEval_EvalFrameEx function would be the ideal place to notify callgrind about these events. Hmm... this would add another dimension to the code position such as (high-level function, low-level function), and thus to some "explosion" of positions. In fact, it is quite similar to another dimension I wanted to add since quite some time: accessed data. I just wonder if there is an easy extension of the format and visualization, or if it is not really worth it... Josef |