Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Code profiling with Xdebug and Kcachegrind

Code profiling with Xdebug and Kcachegrind

Slides for an uncon talk I gave at phpbnl17

robertbasic

January 28, 2017
Tweet

More Decks by robertbasic

Other Decks in Programming

Transcript

  1. Robert Basic ~ phpbenelux17
    Code profiling with
    Xdebug and KCachegrind
    Robert Basic
    https://robertbasic.com/
    @robertbasic

    View full-size slide

  2. Robert Basic ~ phpbenelux17
    Tools of the trade
    Xdebug
    ● Not just for debugging
    KCachegrind
    ● Visualizing profiling data

    View full-size slide

  3. Robert Basic ~ phpbenelux17
    What’s the fastest code?

    View full-size slide

  4. Robert Basic ~ phpbenelux17
    The code that’s not called!

    View full-size slide

  5. Robert Basic ~ phpbenelux17
    Number of calls

    View full-size slide

  6. Robert Basic ~ phpbenelux17
    Who’s to blame?

    View full-size slide

  7. Robert Basic ~ phpbenelux17
    Which was called by another method

    View full-size slide

  8. Robert Basic ~ phpbenelux17
    Which was called by another method

    View full-size slide

  9. Robert Basic ~ phpbenelux17
    So many callers!

    View full-size slide

  10. Robert Basic ~ phpbenelux17
    A graph to see it

    View full-size slide

  11. Robert Basic ~ phpbenelux17
    Context to understand it

    View full-size slide

  12. Robert Basic ~ phpbenelux17
    Fix it
    This is really up to you

    View full-size slide

  13. Robert Basic ~ phpbenelux17
    Tips for fixing performance issues
    ● Biggest impact, least effort
    ● Profile after every change
    ● Avoid over-optimizing
    ● Learn to EXPLAIN

    View full-size slide

  14. Robert Basic ~ phpbenelux17
    Tips for using Xdebug and KCachegrind
    ● Xdebug
    – xdebug.profiler_output_dir
    – xdebug.profiler_output_name
    – cachegrind.out.%t.%R
    – Xdebug lies!
    ● KCachegrind
    – Install graphviz
    – Use % relative
    – Turn on Cycle detection
    – Settings > Configure KCachegrind > Annotations > Add source folder

    View full-size slide

  15. Robert Basic ~ phpbenelux17
    Other tools
    ● WinCacheGrind, Webgrind
    ● XHProf
    ● Blackfire.io

    View full-size slide

  16. Robert Basic ~ phpbenelux17
    Thanks!
    Questions?

    View full-size slide