Optimise read time_in_state

Replace std::map that was used as cache for time in state. Triming the
map by selecting a random element in a loop was too slow. Instead keep a
fixed size vector and evict cache entries on hash collision.

Introduce additional check on ctime + stime from /proc/pid/stat before
reading time_in_state for all its threads. If cpu time does not change,
there is no need to check time_in_state. With this we can skip about 2/3
of processes.

With these optimisations, typical read should go from ~300 ms to ~100
ms. Except the very first one where all threads are scanned.

Bug: 155038236
Bug: 149734495
Test: perfetto_unittests
Test: take a trace with metatrace enabled and compare timings
Change-Id: Ia607d91702465992422929f7b43196b538fda4cd
3 files changed
tree: 57790f6d22fa993a2c92cd3ed85948a28d60740b
  1. bazel/
  2. build_overrides/
  3. buildtools/
  4. debian/
  5. docs/
  6. gn/
  7. include/
  8. infra/
  9. protos/
  10. src/
  11. test/
  12. tools/
  13. ui/
  14. .clang-format
  15. .gitignore
  16. .gn
  17. .style.yapf
  18. Android.bp
  19. Android.bp.extras
  20. BUILD
  21. BUILD.extras
  22. BUILD.gn
  23. codereview.settings
  24. heapprofd.rc
  25. LICENSE
  26. MODULE_LICENSE_APACHE2
  27. OWNERS
  28. perfetto.rc
  29. PRESUBMIT.py
  30. README.chromium
  31. README.md
  32. TEST_MAPPING
  33. traced_perf.rc
  34. WORKSPACE
README.md

Perfetto - Performance instrumentation and tracing

Perfetto is an open-source project for performance instrumentation and tracing of Linux/Android/Chrome platforms and user-space apps.

See www.perfetto.dev for docs.

Contributing

See /docs/contributing.md for instructions.

The source-of-truth repo is Android's Gerrit. The GitHub repo is a read-only mirror.

Bugs

  • For bugs affecting Android or the tracing internals use the internal bug tracker (go/perfetto-bugs).
  • For bugs affecting Chrome use http://crbug.com, Component:Speed>Tracing label:Perfetto.

Community

You can reach us on our Discord channel. If you prefer using IRC we have an experimental Discord <> IRC bridge synced with #perfetto-dev on Freenode.