tree: 3aac51fe07794595db92e4a761cd564659551942 [path history] [tgz]
  1. meta/
  2. samples_to_pprof/
  3. tests/
  4. BUILD.gn
  5. component.cc
  6. component.h
  7. component_watcher.cc
  8. component_watcher.h
  9. job_watcher.cc
  10. job_watcher.h
  11. main.cc
  12. process_watcher.cc
  13. process_watcher.h
  14. profiler_controller_impl.cc
  15. profiler_controller_impl.h
  16. README.md
  17. sampler.cc
  18. sampler.h
  19. symbolization_context.cc
  20. symbolization_context.h
  21. symbolizer_markup.cc
  22. symbolizer_markup.h
  23. targets.cc
  24. targets.h
  25. taskfinder.cc
  26. taskfinder.h
  27. unowned_component.cc
  28. unowned_component.h
src/performance/experimental/profiler/README.md

CPU Profiler

This is an experimental cpu profiler aimed at sampling stack traces and presenting them as pprof graphs. It does not have kernel assisted sample yet, though that is an eventual goal after which it will move out of experimental.

In the mean time, it uses the root resource to suspend the target threads periodically, zx_process_read_memory and the fuchsia unwinder to read stack traces from the target, then exfiltrates them.

Due to this, there is some overhead when sampling stacks. About 300us per sample when using frame pointers, 3000us for reading Dwarf CFI frames[^1]. This can make the current implementation impractical for use cases require demand less perturbation.

[^1]: Numbers measured on core.x64-qemu

Usage:

You'll need to add the profiler component and its core shard to the build as well as the host tool.

fx set <product>.<board> --with-base //src/performance/experimental/profiler --with-host //src/performance/experimental/profiler/samples_to_pprof:install --args='core_realm_shards += [ "//src/performance/experimental/profiler:profiler_core_shard" ]'

The easiest way to interact with the profiler is through the ffx plugin:

ffx profiler start --pid <target pid> --duration 5

This will place a profile.out file in your current directory. You'll need to symbolize it and export it to pprof format.

ffx debug symbolize < profile.out > profile.out.sym; fx samples_to_pprof profile.out.sym

This will output the file profile.out.sym.pb which can be handed to pprof.

$ pprof -top profile.out.sym.pb
Main binary filename not available.
Type: location
Showing nodes accounting for 272, 100% of 272 total
      flat  flat%   sum%        cum   cum%
       243 89.34% 89.34%        243 89.34%   count(int)
        17  6.25% 95.59%        157 57.72%   main()
         4  1.47% 97.06%          4  1.47%   collatz(uint64_t*)
         3  1.10% 98.16%          3  1.10%   add(uint64_t*)
         3  1.10% 99.26%          3  1.10%   sub(uint64_t*)
         1  0.37% 99.63%          1  0.37%   rand()
         1  0.37%   100%          1  0.37%  <unknown>
         0     0%   100%        157 57.72%   __libc_start_main(zx_handle_t, int (*)(int, char**, char**))
         0     0%   100%        154 56.62%   _start(zx_handle_t)
         0     0%   100%        160 58.82%   start_main(const start_params*)