aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Khokhlov <khokhlov@google.com>2024-05-10 16:29:24 +0100
committerMikhail Khokhlov <khokhlov@google.com>2024-05-10 16:29:24 +0100
commitf59110d7b8a7fcc56d1f58849897b807ba249a1a (patch)
tree4d96567129256d873d0e7bafc8dc39ff54ea691b
parent51a1471bbd6bbf2fbeb69ad71cf65543f2bbf961 (diff)
downloadperfetto-f59110d7b8a7fcc56d1f58849897b807ba249a1a.tar.gz
Use correct thread ids in Track::ThreadScoped()
Perfetto embedders (e.g. Chromium) can provide their own platforms for stuff like determining thread ids. ThreadTrack::Current() correctly calls into tracing muxer methods to get thread id from the platform. Track::ThreadScoped() should do the same to avoid inconsistencies. Bug: 339835280 Change-Id: I43c8b2cdd5666a690451b68b1b4f01234242d488
-rw-r--r--include/perfetto/tracing/track.h6
-rw-r--r--src/tracing/track.cc7
2 files changed, 8 insertions, 5 deletions
diff --git a/include/perfetto/tracing/track.h b/include/perfetto/tracing/track.h
index f17ffbbeb..37f02e585 100644
--- a/include/perfetto/tracing/track.h
+++ b/include/perfetto/tracing/track.h
@@ -120,11 +120,7 @@ struct PERFETTO_EXPORT_COMPONENT Track {
// Construct a track using |ptr| as identifier within thread-scope.
// Shorthand for `Track::FromPointer(ptr, ThreadTrack::Current())`
// Usage: TRACE_EVENT_BEGIN("...", "...", perfetto::Track::ThreadScoped(this))
- static Track ThreadScoped(
- const void* ptr,
- Track parent = MakeThreadTrack(base::GetThreadId())) {
- return Track::FromPointer(ptr, parent);
- }
+ static Track ThreadScoped(const void* ptr, Track parent = Track());
protected:
constexpr Track(uint64_t uuid_, uint64_t parent_uuid_)
diff --git a/src/tracing/track.cc b/src/tracing/track.cc
index b7d979516..02e6e035e 100644
--- a/src/tracing/track.cc
+++ b/src/tracing/track.cc
@@ -49,6 +49,13 @@ void Track::Serialize(protos::pbzero::TrackDescriptor* desc) const {
desc->AppendRawProtoBytes(bytes.data(), bytes.size());
}
+// static
+Track Track::ThreadScoped(const void* ptr, Track parent) {
+ if (parent.uuid == 0)
+ return Track::FromPointer(ptr, ThreadTrack::Current());
+ return Track::FromPointer(ptr, parent);
+}
+
protos::gen::TrackDescriptor ProcessTrack::Serialize() const {
auto desc = Track::Serialize();
auto pd = desc.mutable_process();