10

Click here to load reader

Profiling with Xhprof

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Profiling with Xhprof

Profiling with XHProf

Page 2: 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...

Page 3: Profiling with Xhprof

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.

Page 4: Profiling with Xhprof

Collecting profile data

● Enable:

○ xhprof_enable($flags);

● Collect:

○ $data = xhprof_disable();

Page 5: Profiling with Xhprof

● Globally:

○ .htaccess &/or php.ini

○ auto_prepend_file = “header.php”;

○ auto_append_file = “footer.php”;

Collecting profile data

Page 6: Profiling with Xhprof

<?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');

Page 7: Profiling with Xhprof

Interpreting data

● Gui tool Xhprof UI:

○ Looks dated.

○ “Interesting” code.

○ Works well!

● Others:

○ xhprof.io

○ xhgui

Page 8: Profiling with Xhprof

Demo time

● Siege.

● Hardest hit, most expensive.

● Plot over time.

● Compare two runs.

● Call graphs!!!

Page 9: Profiling with Xhprof

Disclaimer

● Siege isn’t really profiling the “real”

world.

● Be careful not to DOS production...

● xhprof can be run in production (I haven’

t).

Page 10: Profiling with Xhprof

@_massey

Questions?