[M120 Migration] Fix crash on tracing initialization 73/311473/4
authorRobert Bycul <r.bycul@samsung.com>
Mon, 13 May 2024 10:32:50 +0000 (12:32 +0200)
committerBot Blink <blinkbot@samsung.com>
Wed, 22 May 2024 21:35:19 +0000 (21:35 +0000)
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 <r.bycul@samsung.com>
third_party/perfetto/include/perfetto/ext/base/waitable_event.h
third_party/perfetto/src/base/waitable_event.cc
third_party/perfetto/src/tracing/tracing.cc

index 15fa6a216a7d16e314d4553ba18583608cb9b2a1..bb096315bb3cead464ae6678f869c9a7e493d176 100644 (file)
 #include <condition_variable>
 #include <mutex>
 
+#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();
 
index c5b5c047856b791df3d612f835836dd42742681a..533fcb997cbd675ff4c13847165aa680b9c4033b 100644 (file)
@@ -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<std::mutex> lock(mutex_);
+  return event_.wait_for(lock, seconds, [this] { return notified_; });
+}
+#endif  // BUILDFLAG(IS_TIZEN_TV)
+
 void WaitableEvent::Notify() {
   std::unique_lock<std::mutex> lock(mutex_);
   notified_ = true;
index 5da8337e98b3da930cc2f167d9a1781ddbecf513..ae5b5c2feb7d24fb6dc82999d9fe1e00ae7a81af 100644 (file)
 #include <condition_variable>
 #include <mutex>
 
+#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<std::mutex> 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<TracingSession> 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::TracingMuxerImpl*>(internal::TracingMuxer::Get())
       ->CreateTracingSession(backend, system_backend_factory);
 }