4

I have installed xhprof on debian 7 using php5-xhprof

This created a file /etc/php5/fpm/conf.d/20-xhprof.ini

In that ini file I added xhprof.output_dir="/tmp/xhprof"

I created the file /tmp/xhprof with 755 www-data:www-data

I can confirm that php has xhprof enabled with phpinfo(), although it doesn't give me the output_dir parameter.

I run a script that has the first line

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

There are no files created in /tmp/xhprof

I have restarted php5-fpm and still no luck.

DAB
  • 1,303
  • 14
  • 23

1 Answers1

3

xhprof.output_dir string

Directory used by the default implementation of the iXHProfRuns interface (namely, the XHProfRuns_Default class) for storing XHProf runs.

http://php.net/manual/en/xhprof.configuration.php

At the end of profiling (or script) you need to save data manually

$xhprof_data = xhprof_disable();

$XHPROF_ROOT = "/tools/xhprof/";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";

http://php.net/manual/en/xhprof.examples.php

If you don't want to control profiling in your application code you can make an auto loaded code snippet /path/to/xhprof/xhprof_enabler.php:

<?php

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

register_shutdown_function(function(){
    $xhprof_data = xhprof_disable();

    $XHPROF_ROOT = "/path/to/xhprof";
    include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
    include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

    $xhprof_runs = new XHProfRuns_Default();
    $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");

    echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing";
});

And then add

auto_prepend_file=/path/to/xhprof/xhprof_enabler.php

to /etc/php5/fpm/conf.d/20-xhprof.ini

Please note that you also need to setup a virtual host for profile viewing, or you can just symlink xhprof folder (which contains xhprof_html) to your default vhost root.

Restart php5-fpm and you should be done.

Community
  • 1
  • 1
vearutop
  • 3,924
  • 24
  • 41