7 Feb 2009 knipknap   » (Journeyer)

Using Federico’s plot-timeline Script With PHP

I am currently trying to profile a PHP application, so I tried to find a way to create a call graph. Since I didn’t want to strace() the entire Apache process (which probably wouldn’t have worked anyway) I remembered a posting that showed how to do it with Mono. So this still depended on strace, but since I liked the plot-timeline.py script from Federico’s performance-tools, I decided to simply fake some strace output.

If you need to do the same, try the following:

  • Add this file to your PHP application.
  • Add some code similar to this:
    $tracer = new CallTracer('/tmp/trace.log');
    function trace($_comment = '') {
      global $tracer;
  • Sprincle trace() calls accross your source code.
  • Pass the resulting file to plot-timeline like this:
    python plot-timeline.py -o graph.png /tmp/trace.log
  • The result looks something like this:

    Syndicated 2009-02-07 23:02:49 from Debain.org

    Latest blog entries     Older blog entries

    New Advogato Features

    New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

    Keep up with the latest Advogato features by reading the Advogato status blog.

    If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!