johncorser johncorser - 1 month ago 11
PHP Question

qcachegrind error: Unknown file format. File generated from php xdebug

I am attempting to use xdebug to profile an application written in php7.

I've written a script that sets the follow

ini
settings:

ini_set('xdebug.trace_format',1); // Note: I tried 0 and 2 here as well
ini_set('xdebug.profiler_enable',1);
xdebug_start_trace('/tmp/cachegrind.out');
// RUN CODE HERE
xdebug_stop_trace();


Running the script created the cachegrind files as I would expect:

root@host:/# ls /tmp | grep cachegrind
cachegrind.out.0028fd.xt
cachegrind.out.0072ab.xt
cachegrind.out.009b09.xt
cachegrind.out.025ac3.xt


Here is the first few lines of a cachegrind file so that the format is visible:

Version: 2.4.1
File format: 4
TRACE START [2016-10-28 05:26:57]
2 3784 1 0.242945 2692856
2 3785 0 0.242955 2692800 DI\Container->set 1 /path/public/api/index.php 100
2 3785 1 0.242966 2692800
2 3786 0 0.242973 2692800 spl_autoload_call 0 /path/public/api/index.php 103
3 3787 0 0.242982 2692896 Fuel\Core\Autoloader::load 1 /path/public/api/index.php 103
4 3788 0 0.242990 2692896 strpos 0 /path/fuel/core/classes/autoloader.php 219


However, when I try to open this file in
qcachegrind
, it fails to open:

enter image description here

The error message reads: "Error loading
/path/to/cachegrind/file
: Unknown file format

Anyone know what's going on here? I'd like to be able to use a tool like this to profile my application.

I also shelled out $30 to try opening the file in MCG but that app crashes immediately upon opening any of these files.

As a side note, the file is fairly large, but not so large that I'd expect apps to be freaking out:

❯ ls -al /Users/johnpc/repos/cachegrind.out.094ffa.xt
-rw-r--r-- 1 johnpc staff 62744095 Oct 28 02:13 /Users/johnpc/repos/cachegrind.out.094ffa.xt

Answer

that file is a trace file not a callgrind file.

i seems you set trace_output_name and profiler_output_name in the ini to the same string or trying to open the wrong file. you need to set the profiling_* variables in the ini. see: "Profiling PHP Scripts" in the xdebug docs

a sample profiling output looks like this:

    version: 1
    creator: xdebug 2.1.1rc1
    cmd: /Users/foo/bar/test1.php
    part: 1
    positions: line

    events: Time

    fl=php:internal
    fn=php::microtime

when you get problems because of the file size, you could also try the app from profilingviewer.com