Authors: @primiano
Status: Implemented PR: https://github.com/google/perfetto/pull/4112
Currently, when configuring a Perfetto trace, data sources reference buffers using a 0-based index (target_buffer: N). This index corresponds to the position of the buffer in the TraceConfig.buffers array.
This addressing scheme is error-prone for humans:
Add support for named buffer addressing while maintaining full backwards compatibility with index-based addressing.
TraceConfig.BufferConfig gets a new optional name field:
message BufferConfig { optional uint32 size_kb = 1; optional FillPolicy fill_policy = 4; // ... existing fields ... optional string name = 7; // New field }
DataSourceConfig gets a new optional target_buffer_name field:
message DataSourceConfig { optional string name = 1; optional uint32 target_buffer = 2; // ... existing fields ... optional string target_buffer_name = 11; // New field }
When setting up a tracing session, TracingServiceImpl will:
target_buffer is set: use it (current behavior)target_buffer_name is set: look up the index from the maptarget_buffer_name is set but not found: return an errorFor deploying configs that work on both old and new versions of Perfetto:
target_buffer_name and uses target_buffer. Works correctly.This is why supporting both target_buffer and target_buffer_name simultaneously is important: it allows a single config to work across Perfetto versions during a transition period.
The service will reject configs with:
target_buffer_name that doesn't match any buffer nametarget_buffer and target_buffer_name set but resolving to different buffersBefore (index-based):
buffers { size_kb: 1024 } # index 0
buffers { size_kb: 4096 } # index 1
data_sources {
config {
name: "linux.ftrace"
target_buffer: 1
}
}
After (name-based):
buffers { size_kb: 1024 name: "small" }
buffers { size_kb: 4096 name: "ftrace" }
data_sources {
config {
name: "linux.ftrace"
target_buffer_name: "ftrace"
}
}
With backwards compatibility:
buffers { size_kb: 1024 name: "small" }
buffers { size_kb: 4096 name: "ftrace" }
data_sources {
config {
name: "linux.ftrace"
target_buffer: 1
target_buffer_name: "ftrace"
}
}
Pro:
Con: