title: How to get useful information from pycallgraph tracing?
body: <p>In my <a href="https://stackoverflow.com/questions/29871822/execution-code-tracking-how-to-know-which-code-has-been-executed-in-project">question</a> about tracking the python execution I was recommended to use <a href="https://pycallgraph.readthedocs.org/en/master/" rel="nofollow noreferrer">pycallgraph</a> so I decided to give it a try on following code:</p>
  
  <pre><code>#!/bin/env python
  
  import matplotlib.pyplot as plt
  import numpy as np
  
  x = np.linspace(0, 2, 100)
  
  # The first call to plt.plot will automatically create
  # the necessary figure and axes to achieve the desired plot.
  plt.plot(x, x, label='linear')
  
  # Subsequent calls to plt.plot re-use
  # the current axes and each add another line.
  plt.plot(x, x**2, label='quadratic')
  plt.plot(x, x**3, label='cubic')
  
  # Setting the title, legend, and axis labels also automatically
  # use the current axes and set the title,
  # create the legend, and label the axis respectively.
  plt.xlabel('x label')
  plt.ylabel('y label')
  
  plt.title("Simple Plot")
  
  plt.legend()
  
  plt.show()
  </code></pre>
  
  <p>This code is from my another <a href="https://stackoverflow.com/questions/30755249/hierarchy-in-matplotlib">question</a> where I've been asking about hierarchy in matplotlib, and I get the following answer:</p>
  
  <blockquote>
    <p>If you're really keen to see how the auto creation is done - it's all
    open source. You can see the call to plot() creates an Axes instance
    by a call to gca() in the code here. This in turn calls gcf(), which
    looks for a FigureManager (which is what actually maintains the
    state). If one exists, it returns the figure it's managing, otherwise
    it creates a new one using plt.figure(). Again, this process to some
    degree inherits from matlab, where the initial call is usually figure
    before any plotting operation.</p>
  </blockquote>
  
  <p>First, I was trying pycallgraph with graphviz option, but it gives me following error:</p>
  
  <pre><code>$ pycallgraph graphviz -- matplotlib.py
  libpath/shortest.c:324: triangulation failed
  libpath/shortest.c:192: source point not in any triangle
  Error: in routesplines, Pshortestpath failed
  Segmentation fault
  Traceback (most recent call last):
    File "/usr/local/bin/pycallgraph", line 26, in &lt;module&gt;
      exec(__file_content)
    File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", line 38, in __exit__
      self.done()
    File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", line 81, in done
      self.stop()
    File "/usr/local/lib/python2.7/dist-packages/pycallgraph/pycallgraph.py", line 90, in generate
      output.done()
    File "/usr/local/lib/python2.7/dist-packages/pycallgraph/output/graphviz.py", line 112, in done
      'code %(ret)i.' % locals())
  pycallgraph.exceptions.PyCallGraphException: The command "dot -Tpng -opycallgraph.png /tmp/tmpObsZGK" failed with error code 35584.
  </code></pre>
  
  <p>Second I've tried to generate <a href="http://gephi.github.io/" rel="nofollow noreferrer">gephi</a> format and it worked:</p>
  
  <pre><code>$ pycallgraph gephi -- matplotlib.py
  </code></pre>
  
  <p>When I've opened this in gephi I get huge graph (Nodes: 1062, Edges: 1362) which was almost useless and I cannot saw anything useful here. So I've tried limit the output:</p>
  
  <pre><code>$ pycallgraph --max-depth 5 gephi -- traceme.py
  </code></pre>
  
  <p>This gives me graph with 254 nodes and 251 edges which was basically also useless because I still cannot saw nothing useful here. So, I've decided to try following:</p>
  
  <pre><code>egrep -i 'gcf|gca|plot' pycallgraph.gdf
  </code></pre>
  
  <p>But it returns me nothing. Then I've started wondering what exactly is pycallgraph tracing and I've made this hello world:</p>
  
  <pre><code>#!/bin/env python
  print "This line will be printed."
  </code></pre>
  
  <p>And I've run it with (graphviz):</p>
  
  <pre><code>pycallgraph graphviz -- hello_world.py
  </code></pre>
  
  <p>The output (read from png file that was generated) was:</p>
  
  <pre><code>__main__ ---&gt; &lt;module&gt;
  </code></pre>
  
  <ol>
  <li>What tool can I use to get similar answer as I've referred? In another words, how can I know that this is the order of calling the functions: plot() -> gca() -> gcf()?</li>
  <li>What is pycallgraph actually tracing?</li>
  <li>Why hello world example is working with graphviz option but more complex example is working only with gephi option?</li>
  <li>How to preserve the DOT format which is pycallgraph generating and passing to graphviz?</li>
  </ol>