Profiling with Xhprof

2,326 views

Published on

Video online: http://www.youtube.com/watch?v=PY1RgLRfatw&feature=youtu.be

Published in: Technology

Profiling with Xhprof

  1. 1. Profiling with XHProf
  2. 2. Installing ● sudo pear upgrade pear ● sudo pecl install -f xhprof ● extension=xhprof.so (in php.ini) ● sudo /etc/init.d/apache2 restart ● Also install graphviz...
  3. 3. Completing install with XHprof UI ● Clone the repo! ● Create database. ● Create table (look in the code). ● Adjust the config.php ● Tell your PHP scripts to profile.
  4. 4. Collecting profile data ● Enable: ○ xhprof_enable($flags); ● Collect: ○ $data = xhprof_disable();
  5. 5. ● Globally: ○ .htaccess &/or php.ini ○ auto_prepend_file = “header.php”; ○ auto_append_file = “footer.php”; Collecting profile data
  6. 6. <?php // header.php xhprof_enable(XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY); <?php // footer.php require_once '/home/tim/Clones/xhprof/xhprof_lib/config.php'; include_once '/home/tim/Clones/xhprof/xhprof_lib/utils/xhprof_lib.php'; include_once '/home/tim/Clones/xhprof/xhprof_lib/utils/xhprof_runs.php'; public function record() { global $_xhprof; // This wasn’t my idea $profile = xhprof_disable(); $xhprof = new XHProfRuns_Default(); $xhprof->save_run($profile, $_xhprof['namespace'], null, $_xhprof); } register_shutdown_function('record');
  7. 7. Interpreting data ● Gui tool Xhprof UI: ○ Looks dated. ○ “Interesting” code. ○ Works well! ● Others: ○ xhprof.io ○ xhgui
  8. 8. Demo time ● Siege. ● Hardest hit, most expensive. ● Plot over time. ● Compare two runs. ● Call graphs!!!
  9. 9. Disclaimer ● Siege isn’t really profiling the “real” world. ● Be careful not to DOS production... ● xhprof can be run in production (I haven’ t).
  10. 10. @_massey Questions?

×