-1

Let say that I have open source project from which I would like to borrow some functionality. Can I get some sort of report generated during execution and/or interaction of this project?

Report should contain e.g.:

  • which functions has been called,
  • in which order,
  • which classes has been instantiated etc.?

Would be nice to have some graphic output for that... you know, if else tree and highlighted the executed branch etc.

I am mostly interested in python and C (perl would be fine too) but if there is any universal tool that cover multiple languages (or one tool per language) for that, it would be very nice.

PS: I am familiar with debuggers but I do not want to step every singe line of code and check if this is the correct instruction. I'm assuming that if functions/methods/classes etc. are properly named then one can get some hints about where to find desired piece of code. But only naming is not enough because you do not know (from brief overview of code) if hopefully looking function foo() does not require some data that was generated by obscure function bar() etc. For that reason I am looking for something that can visualize relations between running code.

PS: Do not know if this is question for SO or programmers.stackexchange. Feel free to move if you wish. PS: I've noticed that tags that I've used are not recommended but execution flow tracking is the best phrase to describe this process

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Wakan Tanka
  • 7,542
  • 16
  • 69
  • 122

1 Answers1

1

Check out Ned Batchelder's coverage and perhaps the graphviz/dot library called pycallgraph. May not be exactly what you need and also (python-only) but in the ballpark.

Pycallgraph is actually likelier to be of interest because it shows the execution path, not just what codelines got executed. It only renders to PDF normally, but it wasn't too difficult to get it to do SVG instead (dot/graphviz supports svg and other formats, pycallgraph was hardcoding pdf rendering).

Neither will do exactly what you want but they are a start.

JL Peyret
  • 10,917
  • 2
  • 54
  • 73
  • Thank you for reply. Maybe me google fu is not enought but "Ned Bs coverage" did not return anything useful, can you post link? I've read (not used) about pycallgraphs but it seems as a lightweight version for what I am looking, and I suppose graph is generated from static code analysis (maybe I am wrong) – Wakan Tanka Apr 27 '15 at 21:03
  • Yeah, sorry, was on iPad for this one, so cut some corners. Will edit. – JL Peyret Apr 27 '15 at 21:48
  • and, no pycallgraph is from dynamic code analysis, maybe even by leveraging coverage.py. In my case, it was computing the seconds spent as well as the number of calls. I guess you could infer the classes instantiated by looking for \__init__ calls by class. But if you need to further process pycallgraph results, you definitely want to render to svg or some other text format. – JL Peyret Apr 27 '15 at 21:59