Click here to load reader
Upload
tim-massey
View
1.511
Download
0
Embed Size (px)
DESCRIPTION
Video online: http://www.youtube.com/watch?v=PY1RgLRfatw&feature=youtu.be
Citation preview
Profiling with XHProf
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...
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.
Collecting profile data
● Enable:
○ xhprof_enable($flags);
● Collect:
○ $data = xhprof_disable();
● Globally:
○ .htaccess &/or php.ini
○ auto_prepend_file = “header.php”;
○ auto_append_file = “footer.php”;
Collecting profile data
<?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');
Interpreting data
● Gui tool Xhprof UI:
○ Looks dated.
○ “Interesting” code.
○ Works well!
● Others:
○ xhprof.io
○ xhgui
Demo time
● Siege.
● Hardest hit, most expensive.
● Plot over time.
● Compare two runs.
● Call graphs!!!
Disclaimer
● Siege isn’t really profiling the “real”
world.
● Be careful not to DOS production...
● xhprof can be run in production (I haven’
t).
@_massey
Questions?