perfetto: Add high-performance Java data source and ProtoWriter Add a zero-allocation Java data source API for writing custom trace data from performance-critical code paths (e.g., frame rendering). The core of this is ProtoWriter, a pure Java protobuf encoder that writes directly to a pre-allocated thread-local byte buffer using the same 4-byte redundant varint trick as C protozero for nested message length fields. This enables single-pass encoding without size pre-computation. Architecture: - ProtoWriter: zero-alloc proto encoder (varint, fixed, string, nested messages). ASCII fast path for strings. UTF-8 fallback with pre-allocated scratch buffer. - PerfettoDataSource: base class with volatile enabled flag (~1ns disabled check) and ThreadLocal TraceContext. - TraceContext: per-thread writer + optional InternPool. Single JNI call (nativeWritePacketToAllInstances) writes encoded bytes to all active tracing session instances via the C SDK stream writer, which handles chunk boundaries and patching. - InternPool: optional string interning with lazy incremental state checking (no JNI overhead when interning is unused). The JNI layer correctly handles: - Multi-instance: iterates all active sessions, writes to each. - Enabled flag: uses native enabled_ptr to avoid disabling when other instances remain active. - Incremental state: tracks per-instance clear flags for interning. - Large packets: delegates to PerfettoStreamWriterAppendBytes which handles cross-chunk writes and size field patching. Benchmarks (Java program, real JNI, real Perfetto shmem, Linux): Full E2E encode + JNI + shmem (basic): ~112 ns/op Full E2E encode + JNI + shmem (+ arg): ~123 ns/op ProtoWriter encode only: ~14 ns/op JNI + shmem only (pre-encoded): ~95 ns/op vs C SDK raw data source (same-size pkt): ~77 ns/op (1.45x) vs C SDK track event LL: ~192 ns/op vs existing Java track event HL: ~179 ns/op Bug: N/A Test: perfetto_integrationtests --gtest_filter="JavaDataSourceTest.*" Test: ProtoWriterTest, InternPoolTest, FullTraceE2ETest (JUnit4) Change-Id: I0000000000000000000000000000000000000000
Perfetto is an open-source suite of SDKs, daemons and tools which use tracing to help developers understand the behaviour of complex systems and root-cause functional and performance issues on client and embedded systems.
It is a production-grade tool that is the default tracing system for the Android operating system and the Chromium browser.
Perfetto is not a single tool, but a collection of components that work together:
Perfetto was designed to be a versatile and powerful tracing system for a wide range of use cases.
ftrace, allowing you to visualize scheduling, syscalls, interrupts, and custom kernel tracepoints on a timeline.chrome://tracing. Use it to debug and root-cause issues in the browser, V8, and Blink.We‘ve designed our documentation to guide you to the right information as quickly as possible, whether you’re a newcomer to performance analysis or an experienced developer.
New to tracing? If you're unfamiliar with concepts like tracing and profiling, start here:
Ready to dive in? Our “Getting Started” guide is the main entry point for all users. It will help you find the right tutorials and documentation for your specific needs:
Want the full overview? For a comprehensive look at what Perfetto is, why it's useful, and who uses it, see our main documentation page:
For users interested in the Debian distribution of Perfetto, the official source of truth and packaging efforts are maintained at Debian Perfetto Salsa Repository
Have questions? Need help?
We follow Google's Open Source Community Guidelines.