$30 off During Our Annual Pro Sale. View Details »

Profiling PHP @ PHPCon Poland 2016

Profiling PHP @ PHPCon Poland 2016

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

Sebastian Grodzicki

October 01, 2016
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Technology

Transcript

  1. PROFILING PHP
    SEBASTIAN GRODZICKI

    View Slide

  2. WHO USES
    PHP?

    View Slide

  3. WHO USES
    PHP 7?

    View Slide

  4. WHO USES
    PHPUNIT?

    View Slide

  5. WHO USES
    XDEBUG?

    View Slide

  6. WHO USES
    BLACKFIRE?

    View Slide

  7. SEBASTIAN
    GRODZICKI
    CTO @ SHOWROOM

    View Slide

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

    View Slide

  9. 40% OF USERS

    ABANDON A WEBSITE

    THAT TAKES MORE THAN

    3 SECONDS TO LOAD
    Akamai
    STATISTICS

    View Slide

  10. PROFILING IS A WAY TO
    MEASURE WHERE A
    PROGRAM SPENDS TIME
    MathWorks
    DEFINITION

    View Slide

  11. MICROTIME

    View Slide

  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

    View Slide

  13. Xdebug

    View Slide

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

    View Slide

  15. KCACHEGRIND

    View Slide

  16. PROFILING PHP
    WEBGRIND

    View Slide

  17. XHProf

    View Slide

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

    View Slide

  19. XHPROF

    View Slide

  20. View Slide

  21. View Slide

  22. PROFILING PHP
    TIME
    Wall time I/O
    CPU
    Disk
    I/O Network
    =
    =
    +
    +

    View Slide

  23. PROFILING PHP
    INCLUSIVE VS EXCLUSIVE TIME
    function foo()

    {

    $str = bar();
    return $str;
    }
    function foo()

    {

    $str = bar();
    return $str;
    }

    View Slide

  24. BLACKFIRE
    CONTINUOUS PERFORMANCE TESTING

    View Slide

  25. BLACKFIRE
    CALLGRAPHS

    View Slide

  26. BLACKFIRE
    HOT PATHS

    View Slide

  27. DEMO
    CHROME COMPANION

    View Slide

  28. View Slide

  29. View Slide

  30. DEMO
    BLACKFIRE CURL

    View Slide

  31. View Slide

  32. DEMO
    BLACKFIRE RUN

    View Slide

  33. View Slide

  34. View Slide

  35. ASSERTIONS

    View Slide

  36. PROFILING PHP
    ASSERTIONS
    tests:
    "Application should never hit the DB":
    path: "/.*"
    assertions:
    - "metrics.sql.queries.count == 0"

    View Slide

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

    View Slide

  38. PROFILING PHP
    ASSERTIONS
    tests:
    "Pages should be fast enough":
    path: "/.*"
    assertions:
    - "main.wall_time < 100ms"

    View Slide

  39. View Slide

  40. BUILDS

    View Slide

  41. View Slide

  42. View Slide

  43. View Slide

  44. PHP SDK

    View Slide

  45. BLACKFIRE
    PHP SDK
    ▸ composer require blackfire/php-sdk
    ▸ $blackfire = new \Blackfire\Client();
    ▸ $probe = $blackfire->createProbe();
    ▸ $profile = $blackfire->endProbe($probe);

    View Slide

  46. PHPUNIT

    View Slide


  47. 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')

    ;

    }

    }

    View Slide

  48. blackfire.io/docs/24-days

    View Slide

  49. QUESTIONS?

    View Slide

  50. THANK YOU!

    View Slide