build a call graph (json as a output) in python?

1.1k Views Asked by At

My problem statement is that i want a call graph of a code in JSON format. i went through through different packages of python like coverage , pycallgraph ,callgraph ,unittest but none of them were giving output as JSON. pycallgraph was close to my problem statement but not providing output as JSON.

Any good tools to do that (free tools) or any change in above module source to get JSON as output?

2

There are 2 best solutions below

3
On

I have seen a statement on pycallgraph docs, it says it can generate json outputs.

please take a look at it here.

0
On

From the documentation of python call graph:

It is able to generate different types ofoutputs and visualizations. Initially Python Call Graph was only used to generate DOT files for GraphViz, and as of version 1.0.0, it can also generate JSON files, and GDF files for Gephi. Creating custom outputsis fairly easy by subclassing the Outputclass.

and:

OUTPUT_MODE can be one of graphviz, gephi and json. python_file.py is a python script that will be traced andafterwards, a call graph visualization will be generated

so either set OUTPUT-MODE to json or write an own custom subclass