From 0567eb1b288162e4f2f4c8961eebd4ea6084bd4a Mon Sep 17 00:00:00 2001 From: Robert Bycul Date: Mon, 13 May 2024 12:32:50 +0200 Subject: [PATCH] [M120 Migration] Fix crash on tracing initialization Ported commit: https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/292707 Bug: https://jira-eu.sec.samsung.net/browse/VDWASM-1543 Change-Id: I02a02328be78bd0a73c5967f2e310ec6c8c6b8ea Signed-off-by: Robert Bycul --- .../perfetto/ext/base/waitable_event.h | 9 ++++++++ .../perfetto/src/base/waitable_event.cc | 7 ++++++ third_party/perfetto/src/tracing/tracing.cc | 23 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/third_party/perfetto/include/perfetto/ext/base/waitable_event.h b/third_party/perfetto/include/perfetto/ext/base/waitable_event.h index 15fa6a216a7d..bb096315bb3c 100644 --- a/third_party/perfetto/include/perfetto/ext/base/waitable_event.h +++ b/third_party/perfetto/include/perfetto/ext/base/waitable_event.h @@ -20,6 +20,11 @@ #include #include +#include "build/build_config.h" +#if BUILDFLAG(IS_TIZEN_TV) +#include "perfetto/base/time.h" +#endif // BUILDFLAG(IS_TIZEN_TV) + namespace perfetto { namespace base { @@ -35,6 +40,10 @@ class WaitableEvent { // Synchronously block until the event is notified. void Wait(); +#if BUILDFLAG(IS_TIZEN_TV) + bool TimedWait(TimeSeconds seconds); +#endif // BUILDFLAG(IS_TIZEN_TV) + // Signal the event, waking up blocked waiters. void Notify(); diff --git a/third_party/perfetto/src/base/waitable_event.cc b/third_party/perfetto/src/base/waitable_event.cc index c5b5c047856b..533fcb997cbd 100644 --- a/third_party/perfetto/src/base/waitable_event.cc +++ b/third_party/perfetto/src/base/waitable_event.cc @@ -27,6 +27,13 @@ void WaitableEvent::Wait() { return event_.wait(lock, [this] { return notified_; }); } +#if BUILDFLAG(IS_TIZEN_TV) +bool WaitableEvent::TimedWait(TimeSeconds seconds) { + std::unique_lock lock(mutex_); + return event_.wait_for(lock, seconds, [this] { return notified_; }); +} +#endif // BUILDFLAG(IS_TIZEN_TV) + void WaitableEvent::Notify() { std::unique_lock lock(mutex_); notified_ = true; diff --git a/third_party/perfetto/src/tracing/tracing.cc b/third_party/perfetto/src/tracing/tracing.cc index 5da8337e98b3..ae5b5c2feb7d 100644 --- a/third_party/perfetto/src/tracing/tracing.cc +++ b/third_party/perfetto/src/tracing/tracing.cc @@ -20,15 +20,28 @@ #include #include +#include "build/build_config.h" +#if BUILDFLAG(IS_TIZEN_TV) +#include "perfetto/base/logging.h" +#include "perfetto/base/time.h" +#include "perfetto/ext/base/waitable_event.h" +#endif // BUILDFLAG(IS_TIZEN_TV) #include "perfetto/ext/base/no_destructor.h" #include "perfetto/ext/base/waitable_event.h" #include "perfetto/tracing/internal/track_event_internal.h" +#if BUILDFLAG(IS_TIZEN_TV) +#include "src/tracing/internal/tracing_muxer_fake.h" +#endif // BUILDFLAG(IS_TIZEN_TV) #include "src/tracing/internal/tracing_muxer_impl.h" namespace perfetto { namespace { bool g_was_initialized = false; +#if BUILDFLAG(IS_TIZEN_TV) +base::WaitableEvent g_initialize_event; +#endif // BUILDFLAG(IS_TIZEN_TV) + // Wrapped in a function to avoid global constructor std::mutex& InitializedMutex() { static base::NoDestructor initialized_mutex; @@ -64,6 +77,9 @@ void Tracing::InitializeInternal(const TracingInitArgs& args) { internal::TracingMuxerImpl::InitializeInstance(args); internal::TrackRegistry::InitializeInstance(); g_was_initialized = true; +#if BUILDFLAG(IS_TIZEN_TV) + g_initialize_event.Notify(); +#endif // BUILDFLAG(IS_TIZEN_TV) } // static @@ -96,6 +112,13 @@ void Tracing::ResetForTesting() { std::unique_ptr Tracing::NewTraceInternal( BackendType backend, TracingConsumerBackend* (*system_backend_factory)()) { +#if BUILDFLAG(IS_TIZEN_TV) + static constexpr const auto kInitializationTimeout = + base::TimeSeconds(10); + g_initialize_event.TimedWait(kInitializationTimeout); + PERFETTO_CHECK(internal::TracingMuxer::Get() && + internal::TracingMuxer::Get() != internal::TracingMuxerFake::Get()); +#endif // BUILDFLAG(IS_TIZEN_TV) return static_cast(internal::TracingMuxer::Get()) ->CreateTracingSession(backend, system_backend_factory); } -- 2.34.1