Skip to content

Instantly share code, notes, and snippets.

@brentp
Last active November 2, 2016 23:18
Show Gist options
  • Save brentp/7dbd7d71e93715049328496b4a957aaf to your computer and use it in GitHub Desktop.
Save brentp/7dbd7d71e93715049328496b4a957aaf to your computer and use it in GitHub Desktop.

compile

CFLAGS+=-fno-omit-frame-pointer -g

google-perftools

installed via sudo apt-get install libgoogle-perftools4

used as:

LD_PRELOAD=/usr/lib/libprofiler.so.0 CPUPROFILE=dump.txt  ./bin/executable args ...
google-pprof --text ./bin/executable dump.txt > profile.txt

output looks like:

brentp@x1$ head profile.txt
Total: 4600 samples
    1780  38.7%  38.7%     1780  38.7% uint_pair_sort_by_first_element_cmp
    1419  30.8%  69.5%     3570  77.6% msort_with_tmp.part.0
     393   8.5%  78.1%      393   8.5% memcpy
     271   5.9%  84.0%      271   5.9% b_search (inline)
      86   1.9%  85.8%       87   1.9% _int_malloc
      80   1.7%  87.6%       80   1.7% inflateBackEnd
      56   1.2%  88.8%       91   2.0% simple_cache_get
      53   1.2%  90.0%       53   1.2% __GI_____strtol_l_internal
      48   1.0%  91.0%       48   1.0% __write_nocancel

can also get a pdf call-graph with

google-pprof --pdf ./bin/executable dump.txt  > dump.pdf

perf

usage is like:

./bin/executable args ... &
sudo perf record -g -p `pidof executable` -o ./my.perf.data sleep 200
perf report --stdio -U  -i ./my.perf.data | c++filt > profile.txt

output looks like:

$ head -30 perf | tail -n+10
# ........  ........  .......  .............  .........................................
#
    44.39%    44.37%  giggle   giggle         [.] uint_pair_sort_by_first_element_cmp  
             |          
             |--42.75%-- uint_pair_sort_by_first_element_cmp
             |          |          
             |                     gen8_irq_handler
             |                     |          
             |                     |--0.02%-- gen8_gt_irq_handler
             |                     |          |          
             |                     |           --0.01%-- intel_lrc_irq_handler
             |                     |                     |          
             |                     |                     |--0.00%-- execlists_check_remove_request
             |                     |                     |          |          
             |                     |                     |           --0.00%-- i915_gem_obj_ggtt_offset_view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment