diff options
author | Etienne Pierre-doray <etiennep@google.com> | 2024-05-09 18:40:26 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-05-09 18:40:26 +0000 |
commit | 1f233121a8e6ce9b91e111aeff5118f9efb48823 (patch) | |
tree | e88579c1641cd9d3cb94b73a3cd3dfe306cb3d20 | |
parent | 7c179d70a2f2e302d72718bf9ca2ca4eebb18095 (diff) | |
parent | c04baebe6059ccdd20f11717066fec73343bffab (diff) | |
download | perfetto-1f233121a8e6ce9b91e111aeff5118f9efb48823.tar.gz |
Merge "[track] Remove deprecate SetTrackDescriptor functions" into main
-rw-r--r-- | include/perfetto/tracing/internal/track_event_data_source.h | 35 | ||||
-rw-r--r-- | include/perfetto/tracing/track.h | 16 | ||||
-rw-r--r-- | src/tracing/test/api_integrationtest.cc | 74 | ||||
-rw-r--r-- | src/tracing/track.cc | 12 |
4 files changed, 41 insertions, 96 deletions
diff --git a/include/perfetto/tracing/internal/track_event_data_source.h b/include/perfetto/tracing/internal/track_event_data_source.h index 1d924b271..6dcb7fe46 100644 --- a/include/perfetto/tracing/internal/track_event_data_source.h +++ b/include/perfetto/tracing/internal/track_event_data_source.h @@ -503,27 +503,6 @@ class TrackEventDataSource }); } - // DEPRECATED. Only kept for backwards compatibility. - static void SetTrackDescriptor( - const Track& track, - std::function<void(protos::pbzero::TrackDescriptor*)> callback) { - SetTrackDescriptorImpl(track, std::move(callback)); - } - - // DEPRECATED. Only kept for backwards compatibility. - static void SetProcessDescriptor( - std::function<void(protos::pbzero::TrackDescriptor*)> callback, - const ProcessTrack& track = ProcessTrack::Current()) { - SetTrackDescriptorImpl(std::move(track), std::move(callback)); - } - - // DEPRECATED. Only kept for backwards compatibility. - static void SetThreadDescriptor( - std::function<void(protos::pbzero::TrackDescriptor*)> callback, - const ThreadTrack& track = ThreadTrack::Current()) { - SetTrackDescriptorImpl(std::move(track), std::move(callback)); - } - static void EraseTrackDescriptor(const Track& track) { TrackRegistry::Get()->EraseTrack(track); } @@ -1054,20 +1033,6 @@ class TrackEventDataSource } } - // Records a track descriptor into the track descriptor registry and, if we - // are tracing, also mirrors the descriptor into the trace. - template <typename TrackType> - static void SetTrackDescriptorImpl( - const TrackType& track, - std::function<void(protos::pbzero::TrackDescriptor*)> callback) { - TrackRegistry::Get()->UpdateTrack(track, std::move(callback)); - Base::template Trace([&](typename Base::TraceContext ctx) { - TrackEventInternal::WriteTrackDescriptor( - track, ctx.tls_inst_->trace_writer.get(), ctx.GetIncrementalState(), - *ctx.GetCustomTlsState(), TrackEventInternal::GetTraceTime()); - }); - } - // Determines if the given dynamic category is enabled, first by checking the // per-trace writer cache or by falling back to computing it based on the // trace config for the given session. diff --git a/include/perfetto/tracing/track.h b/include/perfetto/tracing/track.h index c12f23100..f17ffbbeb 100644 --- a/include/perfetto/tracing/track.h +++ b/include/perfetto/tracing/track.h @@ -332,18 +332,6 @@ class PERFETTO_EXPORT_COMPONENT TrackRegistry { void EraseTrack(Track); - // Store metadata for |track| in the registry. |fill_function| is called - // synchronously to record additional properties for the track. - template <typename TrackType> - void UpdateTrack( - const TrackType& track, - std::function<void(protos::pbzero::TrackDescriptor*)> fill_function) { - UpdateTrackImpl(track, [&](protos::pbzero::TrackDescriptor* desc) { - track.Serialize(desc); - fill_function(desc); - }); - } - // This variant lets the user supply a serialized track descriptor directly. void UpdateTrack(Track, const std::string& serialized_desc); @@ -380,10 +368,6 @@ class PERFETTO_EXPORT_COMPONENT TrackRegistry { protozero::MessageHandle<protos::pbzero::TracePacket> packet); private: - void UpdateTrackImpl( - Track, - std::function<void(protos::pbzero::TrackDescriptor*)> fill_function); - std::mutex mutex_; std::map<uint64_t /* uuid */, SerializedTrackDescriptor> tracks_; diff --git a/src/tracing/test/api_integrationtest.cc b/src/tracing/test/api_integrationtest.cc index cd1207ce6..5e1e27758 100644 --- a/src/tracing/test/api_integrationtest.cc +++ b/src/tracing/test/api_integrationtest.cc @@ -1825,19 +1825,22 @@ TEST_P(PerfettoApiTest, TrackEventConcurrentSessions) { TEST_P(PerfettoApiTest, TrackEventProcessAndThreadDescriptors) { // Thread and process descriptors can be set before tracing is enabled. - perfetto::TrackEvent::SetProcessDescriptor( - [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("hello.exe"); - desc->set_chrome_process()->set_process_priority(1); - }); + { + auto track = perfetto::ProcessTrack::Current(); + auto desc = track.Serialize(); + desc.set_name("hello.exe"); + desc.mutable_chrome_process()->set_process_priority(1); + perfetto::TrackEvent::SetTrackDescriptor(track, std::move(desc)); + } // Erased tracks shouldn't show up anywhere. - perfetto::Track erased(1234u); - perfetto::TrackEvent::SetTrackDescriptor( - erased, [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("ErasedTrack"); - }); - perfetto::TrackEvent::EraseTrackDescriptor(erased); + { + perfetto::Track erased(1234u); + auto desc = erased.Serialize(); + desc.set_name("ErasedTrack"); + perfetto::TrackEvent::SetTrackDescriptor(erased, std::move(desc)); + perfetto::TrackEvent::EraseTrackDescriptor(erased); + } // Setup the trace config. perfetto::TraceConfig cfg; @@ -1852,29 +1855,33 @@ TEST_P(PerfettoApiTest, TrackEventProcessAndThreadDescriptors) { TRACE_EVENT_INSTANT("test", "MainThreadEvent"); std::thread thread([&] { - perfetto::TrackEvent::SetThreadDescriptor( - [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("TestThread"); - }); + auto track = perfetto::ThreadTrack::Current(); + auto desc = track.Serialize(); + desc.set_name("TestThread"); + perfetto::TrackEvent::SetTrackDescriptor(track, std::move(desc)); TRACE_EVENT_INSTANT("test", "ThreadEvent"); }); thread.join(); // Update the process descriptor while tracing is enabled. It should be // immediately reflected in the trace. - perfetto::TrackEvent::SetProcessDescriptor( - [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("goodbye.exe"); - }); - perfetto::TrackEvent::Flush(); + { + auto track = perfetto::ProcessTrack::Current(); + auto desc = track.Serialize(); + desc.set_name("goodbye.exe"); + perfetto::TrackEvent::SetTrackDescriptor(track, std::move(desc)); + perfetto::TrackEvent::Flush(); + } tracing_session->get()->StopBlocking(); // After tracing ends, setting the descriptor has no immediate effect. - perfetto::TrackEvent::SetProcessDescriptor( - [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("noop.exe"); - }); + { + auto track = perfetto::ProcessTrack::Current(); + auto desc = track.Serialize(); + desc.set_name("noop.exe"); + perfetto::TrackEvent::SetTrackDescriptor(track, std::move(desc)); + } std::vector<char> raw_trace = tracing_session->get()->ReadTraceBlocking(); perfetto::protos::gen::Trace trace; @@ -1972,11 +1979,13 @@ TEST_P(PerfettoApiTest, TrackEventCustomTrack) { // Declare a custom track and give it a name. uint64_t async_id = 123; - perfetto::TrackEvent::SetTrackDescriptor( - perfetto::Track(async_id), - [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("MyCustomTrack"); - }); + + { + auto track = perfetto::Track(async_id); + auto desc = track.Serialize(); + desc.set_name("MyCustomTrack"); + perfetto::TrackEvent::SetTrackDescriptor(track, std::move(desc)); + } // Start events on one thread and end them on another. TRACE_EVENT_BEGIN("bar", "AsyncEvent", perfetto::Track(async_id), "debug_arg", @@ -5331,10 +5340,9 @@ void EmitConsoleEvents() { TRACE_EVENT_END("foo"); uint64_t async_id = 4004; auto track = perfetto::Track(async_id, perfetto::ThreadTrack::Current()); - perfetto::TrackEvent::SetTrackDescriptor( - track, [](perfetto::protos::pbzero::TrackDescriptor* desc) { - desc->set_name("AsyncTrack"); - }); + auto desc = track.Serialize(); + desc.set_name("AsyncTrack"); + perfetto::TrackEvent::SetTrackDescriptor(track, std::move(desc)); TRACE_EVENT_BEGIN("test", "AsyncEvent", track); std::thread thread([&] { diff --git a/src/tracing/track.cc b/src/tracing/track.cc index 2f57e77f0..b7d979516 100644 --- a/src/tracing/track.cc +++ b/src/tracing/track.cc @@ -212,18 +212,6 @@ void TrackRegistry::UpdateTrack(Track track, tracks_[track.uuid] = std::move(serialized_desc); } -void TrackRegistry::UpdateTrackImpl( - Track track, - std::function<void(protos::pbzero::TrackDescriptor*)> fill_function) { - constexpr size_t kInitialSliceSize = 32; - constexpr size_t kMaximumSliceSize = 4096; - protozero::HeapBuffered<protos::pbzero::TrackDescriptor> new_descriptor( - kInitialSliceSize, kMaximumSliceSize); - fill_function(new_descriptor.get()); - auto serialized_desc = new_descriptor.SerializeAsString(); - UpdateTrack(track, serialized_desc); -} - void TrackRegistry::EraseTrack(Track track) { std::lock_guard<std::mutex> lock(mutex_); tracks_.erase(track.uuid); |