traceWithArgs

inline fun <T> traceWithArgs(nameProvider: () -> String, argsProvider: (ComponentsSystrace.TraceScope) -> Unit, tracingBlock: () -> T): T

A convenience Kotlin API for tracing a section with structured metadata arguments.

The section name should follow the <phase>:<componentName> convention and remain simple for clean aggregation in Perfetto. Variable details (tree ID, sync/async, component ID, etc.) should be passed as arguments via the TraceScope in argsProvider.

When isTracing is false, none of the lambdas are evaluated except tracingBlock — zero overhead.

Usage:

ComponentsSystrace.traceWithArgs(
{ "resolve:${component.simpleName}" },
{ scope ->
scope.attribute("treeId", treeId)
scope.attribute("rootId", rootId)
},
) {
// actual work
}