Profiling PHP @ PHPCon Poland 2016

Profiling PHP @ PHPCon Poland 2016

PHPCon Poland 2016
http://www.phpcon.pl/2016/pl/

9a328142924c93e5e148c75356ba6d42?s=128

Sebastian Grodzicki

October 01, 2016
Tweet

Transcript

  1. PROFILING PHP SEBASTIAN GRODZICKI

  2. WHO USES PHP?

  3. WHO USES PHP 7?

  4. WHO USES PHPUNIT?

  5. WHO USES XDEBUG?

  6. WHO USES BLACKFIRE?

  7. SEBASTIAN GRODZICKI CTO @ SHOWROOM

  8. I’M NOT HIRED BY BLACKFIRE. Sebastian Grodzicki DISCLAIMER

  9. 40% OF USERS
 ABANDON A WEBSITE
 THAT TAKES MORE THAN


    3 SECONDS TO LOAD Akamai STATISTICS
  10. PROFILING IS A WAY TO MEASURE WHERE A PROGRAM SPENDS

    TIME MathWorks DEFINITION
  11. MICROTIME

  12. log_format foobar '$remote_addr ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"

    ' '$request_time $upstream_response_time’; access_log /var/log/nginx/access.log foobar; NGINX
  13. Xdebug

  14. xdebug.profiler_enable_trigger = 1 http://url?XDEBUG_PROFILE=1

  15. KCACHEGRIND

  16. PROFILING PHP WEBGRIND

  17. XHProf

  18. <?php xhprof_enable(); # do some stuff $xhprof_data = xhprof_disable();

  19. XHPROF

  20. None
  21. None
  22. PROFILING PHP TIME Wall time I/O CPU Disk I/O Network

    = = + +
  23. PROFILING PHP INCLUSIVE VS EXCLUSIVE TIME function foo()
 {
 $str

    = bar(); return $str; } function foo()
 {
 $str = bar(); return $str; }
  24. BLACKFIRE CONTINUOUS PERFORMANCE TESTING

  25. BLACKFIRE CALLGRAPHS

  26. BLACKFIRE HOT PATHS

  27. DEMO CHROME COMPANION

  28. None
  29. None
  30. DEMO BLACKFIRE CURL

  31. None
  32. DEMO BLACKFIRE RUN

  33. None
  34. None
  35. ASSERTIONS

  36. PROFILING PHP ASSERTIONS tests: "Application should never hit the DB":

    path: "/.*" assertions: - "metrics.sql.queries.count == 0"
  37. PROFILING PHP ASSERTIONS tests: "Homepage should never call the API":

    path: "/" assertions: - "metrics.http.requests.count == 0"
  38. PROFILING PHP ASSERTIONS tests: "Pages should be fast enough": path:

    "/.*" assertions: - "main.wall_time < 100ms"
  39. None
  40. BUILDS

  41. None
  42. None
  43. None
  44. PHP SDK

  45. BLACKFIRE PHP SDK ▸ composer require blackfire/php-sdk ▸ $blackfire =

    new \Blackfire\Client(); ▸ $probe = $blackfire->createProbe(); ▸ $profile = $blackfire->endProbe($probe);
  46. PHPUNIT

  47. <?php
 
 use Blackfire\Bridge\PhpUnit\TestCaseTrait;
 use Blackfire\Profile;
 
 class IntegrationTest extends

    \PHPUnit_Framework_TestCase {
 use TestCaseTrait;
 /**
 * @requires extension blackfire
 */
 public function testSomething() {
 $config = new Profile\Configuration();
 $config
 ->assert('metrics.sql.queries.count < 5', 'SQL queries')
 ->assert('metrics.twig.render.count < 3', 'Rendered Twig templates')
 ->assert('metrics.twig.compile.count == 0', 'Twig compilation')
 ;
 }
 }
  48. blackfire.io/docs/24-days

  49. QUESTIONS?

  50. THANK YOU!