// We have no way to know whether other data sources have already added
// a track and thread descriptor for this thread, so we add one just in
// case. Perfetto's incremental state tracking handles deduplication
// automatically.
if (seen_threads.insert(thread_id).second) {
auto packet = ctx.NewTracePacket();
auto* track_descriptor = packet->set_track_descriptor();
track_descriptor->set_uuid(thread_track_uuid);
track_descriptor->set_parent_uuid(thread_track.parent_uuid);
auto* thread = track_descriptor->set_thread();
thread->set_pid(thread_track.pid);
thread->set_tid(thread_id);
const char* thread_name =
base::ThreadIdNameManager::GetInstance()->GetName(
base::PlatformThreadId(thread_id));
if (thread_name && thread_name[0] != '\0') {
thread->set_thread_name(thread_name);
} else {
// Fallback: if this thread is not known to Chromium, we must still
// provide a thread descriptor with some name for it.
thread->set_thread_name("Unknown Thread");
}
}
I find this awkward - emitting track event data is a lot of boilerplate when not using TRACE_EVENT macros directly.
I hit a similar problem for SystemMetricsSampler:
https://source.chromium.org/chromium/chromium/src/+/main:services/tracing/public/cpp/system_metrics_sampler.cc?q=systemmetricssampler&ss=chromium
I ended up using a combination of DataSource (to allow configuration and capturing Start/Stop) + using TRACE_EVENT directly, which is a bit weird (because it requires enabling both the category and the data source, which is the case here as well) but a lot simpler.
This could also be a simple TRACE_EVENT + TraceSessionObserver if you don't need a dedicated DataSourceConfig and state.
track_event->add_categories("os_log");Let's have this match the category in AddDataSourceConfigs()
TRACE_DISABLED_BY_DEFAULT("os_log"))) {Let's add the category in base/trace_event/builtin_categories.h
Nit: TRACE_DISABLED_BY_DEFAULT is mostly deprecated, I'd recommend seomthing like "ios.log.debug"
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// We have no way to know whether other data sources have already added
// a track and thread descriptor for this thread, so we add one just in
// case. Perfetto's incremental state tracking handles deduplication
// automatically.
if (seen_threads.insert(thread_id).second) {
auto packet = ctx.NewTracePacket();
auto* track_descriptor = packet->set_track_descriptor();
track_descriptor->set_uuid(thread_track_uuid);
track_descriptor->set_parent_uuid(thread_track.parent_uuid);
auto* thread = track_descriptor->set_thread();
thread->set_pid(thread_track.pid);
thread->set_tid(thread_id);
const char* thread_name =
base::ThreadIdNameManager::GetInstance()->GetName(
base::PlatformThreadId(thread_id));
if (thread_name && thread_name[0] != '\0') {
thread->set_thread_name(thread_name);
} else {
// Fallback: if this thread is not known to Chromium, we must still
// provide a thread descriptor with some name for it.
thread->set_thread_name("Unknown Thread");
}
}
I find this awkward - emitting track event data is a lot of boilerplate when not using TRACE_EVENT macros directly.
I hit a similar problem for SystemMetricsSampler:
https://source.chromium.org/chromium/chromium/src/+/main:services/tracing/public/cpp/system_metrics_sampler.cc?q=systemmetricssampler&ss=chromiumI ended up using a combination of DataSource (to allow configuration and capturing Start/Stop) + using TRACE_EVENT directly, which is a bit weird (because it requires enabling both the category and the data source, which is the case here as well) but a lot simpler.
This could also be a simple TRACE_EVENT + TraceSessionObserver if you don't need a dedicated DataSourceConfig and state.
Oh, wow. It's so much simpler that way. Thanks!
Done.
Let's have this match the category in AddDataSourceConfigs()
Done
Let's add the category in base/trace_event/builtin_categories.h
Nit: TRACE_DISABLED_BY_DEFAULT is mostly deprecated, I'd recommend seomthing like "ios.log.debug"
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
session_->FlushBlocking();I'd expect this to happen already as part of StopBlocking below.
auto thread_track = perfetto::ThreadTrack::ForThread(thread_id);Nit: You might want to create a named track scoped by the ThreadTrack, e.g.
`NamedTrack("OSLog", 0, thread_track)` if you want this to appear separately from the regular thread's trace events.
inline constexpr char kOsLogSourceName[] = "org.chromium.os_log";I think the data source name should have ios in the name as well?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |