phacility / xhprof

XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface.
http://pecl.php.net/package/xhprof
Apache License 2.0
2.6k stars 924 forks source link

Configurable sampling interval and call-stack tracing depth #80

Open janpapenbrock opened 8 years ago

janpapenbrock commented 8 years ago

This is basically just a rebase of #34. All implementation credit goes to @turchanov.

Reason for this rebase: The original PR contained some additional, unrelated changes.

This PR adds two options to configure xhprof_sample_* functions behavior:

  1. xhprof.sampling_interval - Configure the sampling interval in microseconds, i.e. the time between two samples being taken. Defaults to the current hard-coded default of 100 miliseconds (=100,000 microseconds).
  2. xhprof.sampling_depth - Configure the call stack depth being sampled, i.e. when set to 10, only the 10 deepest method calls are recorded. Defaults to INT_MAX.

Both additions are great for in-depth performance analysis of requests with short response times, where the original sampling interval of 100 miliseconds is not useful at all.

Exemplary usage in the wild:

    ini_set('xhprof.sampling_interval', 50000); // sample twice as often
    ini_set('xhprof.sampling_depth', 50);
    xhprof_sample_enable();