TomNomNom.com

Blogging since 2008 until 2010

WinCacheGrind timing fix

There is a reasonably well known bug with WinCacheGrind; when using cachegrind.out files produced by XDebug the times are out by a factor of ten. While it's pretty easy to mentally multiply the times by ten, times below 0.1ms aren't displayed; meaning you don't actually see the times for anything that took less than 1ms to execute.

I originally intended to modify the source code for WinCacheGrind and host a fixed version, but it would seem there is a file missing from the source code - and I don't know enough about Delphi to hack around it.

My alternate fix is a little PHP shell script that I've put in /usr/bin/wcgfix on my development box. It just multiplies all the times by ten.

#!/usr/bin/php
<?php
if (!isSet($argv[1])) die ("Usage {$argv[0]} <filename>\\n");
$file = $argv[1];
$fh = fopen($file'r');
if (!$fhdie("Could not open file");

while (!feof($fh)){
  $l = fgets($fh);
  if (is_numeric($l[0])){
    $p = explode(' '$l);
    $p[1] = $p[1] * 10;
    $p[] = "\\n";
    $l = implode(' '$p);
  }
  echo $l;
}
fclose($fh);

The timing lines in cachegrind.out files are in the format <line number> <execution time> <unknown>. None of the other lines in the file start with a number, which makes them pretty damn easy to dig out.

Typical usage would be something like:

# wcgfix cachegrind.out.borked > cachegrind.out.fixed

I admit, it's still a little bit of a pain. But until I manage to get this damn Delphi thing sorted, it will have to do!

First posted: Sat, 26 Sep 2009 16:41:27 +0000