Improve PerfettoTrace API
The old API was of the form: PerfettoTrace.instant(category, name, extra). This was not ideal for a few reasons: 1. Initializing the thread local extra was decoupled from the call to emit an event and could be error prone if people initialize an extra away from the point where it's emitted. 2. This call would ideally be wrapped around a check for isTraceEnabled to avoid paying the cost of initializing the method parameters. There was an alternative API that accepted a lambda, but that incurs an object allocation on each call which is bad for the GC. The new API is of the form: PerfettoTrace.instant(category, name) .addArg(String val, Object... args) .emit(). This addresses both problems mentioned above. When tracing is disabled, each intermediat call returns a NoOpBuilder that just returns 'this'. Also fixed use-after-free with JNI string extraction. Bug: 303199244 Flag: android.os.perfetto_sdk_tracing_v2 Test: atest PerfettoTraceTest Change-Id: I6e732c58275d6ee00bc7c492a804ac32e5bcb47c
Loading
Please register or sign in to comment
