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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

  5. Robert Basic ~ phpbenelux17
    Number of calls

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  9. Robert Basic ~ phpbenelux17
    So many callers!

    View Slide

  10. Robert Basic ~ phpbenelux17
    A graph to see it

    View Slide

  11. Robert Basic ~ phpbenelux17
    Context to understand it

    View Slide

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

    View 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 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 Slide

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

    View Slide

  16. Robert Basic ~ phpbenelux17
    Thanks!
    Questions?

    View Slide