Tool it Up! - Session #1 - Xhprof

673 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
673
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Tool it Up! - Session #1 - Xhprof

  1. 1. Date: 2013-08-01 By: gabe.
  2. 2. Xhprof - • "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil” - Knuth – err, Hoare – err, no idea.
  3. 3. History • Developed at “the facebook” • Code still maintained: https://github.com/facebook/xhprof • Docs, not so much: http://web.archive.org/web/20110514095512 /http://mirror.facebook.net/facebook/xhprof/ doc.html
  4. 4. Install • wget https://github.com/facebook/xhprof/archive/master.zip unzip master.zip cd xhprof-master/extension phpize ./configure make sudo make install •
  5. 5. Enable in PHP ● To use xhprof, you need to tell your php code that you want to profile it: php.ini is the easiest: php_value auto_prepend_file "../../xhprof/external/header.php" php_value auto_append_file "../../xhprof/external/footer.php"
  6. 6. Or... you can enable on a case by case basis using: <?php xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); for ($i = 0; $i <= 1000; $i++) { $a = $i * $i; } $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_testingn";
  7. 7. Basic Usage • Just load a page • Small link will appear on bottom • Click!
  8. 8. What the output means • Inclusive Time: Time spent in this function + called functions • Exclusive Time: Time spent in this function only • Wall Time: Time between when something started + finished as measured by the clock on the wall • CPU Time: Time spent in user space + kernel space (doesn't include IO)
  9. 9. What the output means • Inclusive Time: Time spent in this function + called functions • Exclusive Time: Time spent in this function only • Wall Time: Time between when something started + finished as measured by the clock on the wall • CPU Time: Time spent in user space + kernel space (doesn't include IO)
  10. 10. Contrived Examples • sleep(10); • http://gguzman.gamma.net/rsrc/sleep.txt • High wall time • Low CPU time
  11. 11. Contrived Examples (cont) • fib(30); • http://gguzman.gamma.net/rsrc/fibonacci.txt • High wall time • High CPU time
  12. 12. Real Example • Td3x.com http://gguzman.gamma.net/rsrc/xhprofio/?xhprof[tem
  13. 13. Trends • Xhprof.io
  14. 14. Caveats • Can get resource intensive, especially on VM. • Don't use with XDEBUG • OK to use in production, but maybe not all the time... flag to enable, or enable on a per server basis to collect data sometimes.
  15. 15. Questions
  16. 16. Thanks

×