tp: run dataframe table filters on the executor

**Why**

The dataframe module runs every SQLite query through the interpreter.

**Changes**

- A query which only filters a finalized table, with no sort, distinct
  or limit, now runs as a pipeline. Everything else still uses the
  interpreter.
- The plan is built once per table and query string and shared by every
  cursor. Each `xFilter` binds SQLite's arguments as the plan's bound
  params and starts a run.
- Cells are read through the cursor's column views. The first row read
  picks how each column is passed to SQLite.
- `xFilter` prefetches the cells of every column SQLite reads, so their
  cache misses overlap.
- New `Wide_*` connection benchmarks for scans and joins on the id, an
  index and a sorted column.

**Benchmarks**

Joins up the slice parent chain, with `trace_processor_shell` on two
real traces, median of 5 runs:

| Query | Trace | main | This PR |
|---|---|---:|---:|
| 3 levels | chrome | 79 ms | 71 ms |
| 4 levels | chrome | 94 ms | 83 ms |
| 4 levels, more columns | chrome | 176 ms | 142 ms |
| 3 levels | startup | 64 ms | 58 ms |
| 4 levels | startup | 74 ms | 65 ms |
| 4 levels, more columns | startup | 133 ms | 108 ms |

Joins which find rows in id order, where the cache already hides the
misses, are the same as main.

These numbers are from before the batch offset was dropped from the
previous PR and binding moved into `RunParams`. Neither changes the
work done per row, and the `Wide_*` join benchmarks were the same with
and without the offset.

**Testing**

`perfetto_unittests` and all diff tests pass.

6 files changed
tree: c973c0ee27d450f27a759f42050057cfbd3c352b
  1. .github/
  2. ai/
  3. bazel/
  4. build_overrides/
  5. buildtools/
  6. contrib/
  7. docs/
  8. examples/
  9. gn/
  10. include/
  11. infra/
  12. protos/
  13. python/
  14. sdk/
  15. src/
  16. test/
  17. third_party/
  18. tools/
  19. ui/
  20. .bazelignore
  21. .bazelrc
  22. .bazelversion
  23. .clang-format
  24. .clang-tidy
  25. .git-blame-ignore-revs
  26. .gitallowed
  27. .gitattributes
  28. .gitignore
  29. .gn
  30. .style.yapf
  31. Android.bp
  32. Android.bp.extras
  33. BUILD
  34. BUILD.extras
  35. BUILD.gn
  36. CHANGELOG
  37. CONTRIBUTORS.txt
  38. DIR_METADATA
  39. heapprofd.rc
  40. LICENSE
  41. meson.build
  42. METADATA
  43. MODULE.bazel
  44. MODULE.bazel.lock
  45. MODULE_LICENSE_APACHE2
  46. OWNERS
  47. OWNERS.github
  48. perfetto.rc
  49. perfetto_flags.aconfig
  50. PerfettoIntegrationTests.xml
  51. persistent_cfg.pbtxt
  52. README.chromium
  53. README.md
  54. TEST_MAPPING
  55. traced_perf.rc
  56. WORKSPACE
README.md

What is Perfetto?

Perfetto is an open-source suite of tools for recording, visualizing and analyzing traces: timelines of what software and the system under it were doing. It is the default tracing system for Android and Chromium. System-wide recording works on Android and Linux. The tracing SDK, the UI and Trace Processor also run on macOS and Windows.

  • Record the whole system. Scheduling, CPU frequency, memory, syscalls and any kernel tracepoint on Android and Linux, plus Android framework events, callstack sampling and Java and native heap profiles.
  • Instrument your own code. Add trace points with the C++ or Rust SDKs and see them next to everything else.
  • Open traces from other tools. Chrome JSON, Linux perf, Firefox Profiler, macOS Instruments, pprof, systrace, Fuchsia and more.
  • Explore multi-GB traces in the browser. The Perfetto UI needs no install and runs fully locally: traces are not uploaded anywhere.
  • Query everything with SQL. Trace Processor turns any trace into tables, with a standard library for common analyses. Use it from the command line, Python or C++.
  • Bring your AI agent. The Perfetto AI skill teaches coding agents to record and analyze traces.

Try it in your browser

Open an example Android trace without installing anything, or drag your own trace file onto ui.perfetto.dev.

The Perfetto UI on an Android trace: a binder transaction selected in SurfaceFlinger, with its call stack and frame timelines on the timeline, and its details, binder reply and arguments below

Quick start

Record a trace

On Android, with a device connected over adb:

curl -O https://raw.githubusercontent.com/google/perfetto/main/tools/record_android_trace
python3 record_android_trace -o trace.pftrace -t 10s sched freq gfx view am wm

The trace opens in the Perfetto UI when recording finishes.

On Linux, record scheduling activity with tracebox:

curl -LO https://get.perfetto.dev/tracebox && chmod +x tracebox
curl -LO https://raw.githubusercontent.com/google/perfetto/main/test/configs/scheduling.cfg
sudo ./tracebox -o trace.pftrace --txt -c scheduling.cfg

For Chrome, use the recording page in the UI. To trace your own app, see in-app tracing.

Query it with SQL

curl -LO https://get.perfetto.dev/trace_processor && chmod +x trace_processor
./trace_processor query trace.pftrace \
  "SELECT name, COUNT(*) AS cnt FROM slice GROUP BY name ORDER BY cnt DESC LIMIT 10"

Or from Python:

pip install perfetto
from perfetto.trace_processor import TraceProcessor

tp = TraceProcessor(trace='trace.pftrace')
print(tp.query('SELECT ts, dur, name FROM slice LIMIT 10').as_pandas_dataframe())

What can you do with it?

  • Android app and platform developers: root-cause slow startups, jank, ANRs and low memory kills, and profile Java/Kotlin and native memory. (Android guides)
  • C, C++ and Rust developers: instrument your code to see where time goes across threads and processes. (In-app tracing)
  • Linux kernel and systems developers: visualize scheduling, syscalls, interrupts and custom tracepoints. Perfetto is an efficient userspace daemon for ftrace. (Linux cookbook)
  • Chromium developers: Perfetto is the tracing backend behind chrome://tracing, for debugging the browser, V8 and Blink. (Chrome tracing)
  • Performance engineers: analyze traces from many tools in one place and automate the analysis with SQL across thousands of traces. (Trace analysis)

Not sure where to start? How do I start using Perfetto? picks a path based on what you want to do.

How it fits together

Perfetto's components: tracing daemons and SDKs that record traces, and the UI and Trace Processor that analyze them

Perfetto is a collection of components that work together:

  • Tracing daemons (traced, traced_probes) collect data from many processes and the kernel into a single trace file.
  • The tracing SDK writes your app's trace points with low overhead.
  • The Perfetto UI visualizes traces on a timeline.
  • Trace Processor parses traces into a SQL database for analysis.

See the documentation for the full picture.

Community and Support

See Community and getting help for more. We follow Google's Open Source Community Guidelines.

Contributing

Contributions are welcome. The contributor guide covers building, testing and sending pull requests.

Packages

The Debian packaging of Perfetto is maintained in the Debian Perfetto Salsa repository.

License

Apache 2.0. See LICENSE for details.