[M108 Migration] Bring up ttrace 10/287210/7
authorBakka Uday Kiran <b.kiran@samsung.com>
Tue, 24 Jan 2023 19:50:55 +0000 (01:20 +0530)
committerBot Blink <blinkbot@samsung.com>
Fri, 27 Jan 2023 14:02:30 +0000 (14:02 +0000)
Add '--ttrace' build option
  Import ttrace package
  Define USE_TTRACE macro
  Add use_ttrace GN variable
Add helper macro functions for TTRACE
Add TTRACE backend under TRACE_EVENT macro
Enable TTRACE except chrome trace log for TV product by default.

Reference: https://review.tizen.org/gerrit/c/277764

Change-Id: I40e2ec67c3619827a8b7de9c7e3bbcc22722d8a4
Signed-off-by: Bakka Uday Kiran <b.kiran@samsung.com>
15 files changed:
base/trace_event/trace_event.h
packaging/chromium-efl.spec
third_party/skia/src/core/SkTraceEvent.h
tizen_src/build/BUILD.gn
tizen_src/build/common.sh
tizen_src/build/config/BUILD.gn
tizen_src/build/config/tizen_features.gni
tizen_src/chromium_impl/base/BUILD.gn [new file with mode: 0644]
tizen_src/chromium_impl/base/base_efl.gni
tizen_src/chromium_impl/base/trace_event/trace_event_ttrace.cc [new file with mode: 0644]
tizen_src/chromium_impl/base/trace_event/ttrace.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/public/ewk_view.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
v8/BUILD.gn
v8/src/tracing/trace-event.h

index 02f96b1..2283ae7 100644 (file)
 #include "base/trace_event/traced_value_support.h"
 #include "base/tracing_buildflags.h"
 
+#if BUILDFLAG(IS_EFL)
+#include "base/trace_event/ttrace.h"
+#endif
+
 #if !BUILDFLAG(USE_PERFETTO_CLIENT_LIBRARY)
 
 // By default, const char* argument values are assumed to have long-lived scope
 // Implementation detail: internal macro to create static category and add begin
 // event if the category is enabled. Also adds the end event when the scope
 // ends.
+#if defined(USE_TTRACE_TRACE_EVENT_WEBCORE)
+#define TTRACE_TRACE_EVENT(tracer, category_group, name) \
+  INTERNAL_TRACE_EVENT_UID(tracer).TTraceBegin(category_group, name);
+#else
+#define TTRACE_TRACE_EVENT(tracer, category_group, name)
+#endif
 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...)           \
   INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                    \
   trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer);       \
+  TTRACE_TRACE_EVENT(tracer, category_group, name)                           \
   if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED()) {                       \
     base::trace_event::TraceEventHandle INTERNAL_TRACE_EVENT_UID(h) =        \
         trace_event_internal::AddTraceEvent(                                 \
@@ -712,9 +723,17 @@ static void AddMetadataEvent(const unsigned char* category_group_enabled,
 // Used by TRACE_EVENTx macros. Do not use directly.
 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
  public:
+#if defined(USE_TTRACE_TRACE_EVENT_WEBCORE)
+  ScopedTracer() : use_ttrace_(false) {}
+#else
   ScopedTracer() = default;
+#endif
 
   ~ScopedTracer() {
+#if defined(USE_TTRACE_TRACE_EVENT_WEBCORE)
+    if (use_ttrace_)
+      TTRACE_WEB_TRACE_EVENT_END();
+#endif
     if (category_group_enabled_ && *category_group_enabled_) {
       TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
                                                   name_, event_handle_);
@@ -729,6 +748,12 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
     event_handle_ = event_handle;
   }
 
+#if defined(USE_TTRACE_TRACE_EVENT_WEBCORE)
+  void TTraceBegin(const char* category_group, const char* name) {
+    use_ttrace_ = TTRACE_WEB_TRACE_EVENT_BEGIN(category_group, name);
+  }
+#endif
+
  private:
   // NOTE: Only initialize the first member to reduce generated code size,
   // since there is no point in initializing the other members if Initialize()
@@ -736,6 +761,10 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
   const unsigned char* category_group_enabled_ = nullptr;
   const char* name_;
   base::trace_event::TraceEventHandle event_handle_;
+
+#if defined(USE_TTRACE_TRACE_EVENT_WEBCORE)
+  bool use_ttrace_;
+#endif
 };
 
 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
index baa95b3..d5b0dac 100644 (file)
@@ -107,6 +107,7 @@ BuildRequires: pkgconfig(scim)
 BuildRequires: pkgconfig(security-manager)
 BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(stt)
+BuildRequires: pkgconfig(ttrace)
 BuildRequires: pkgconfig(tts)
 BuildRequires: pkgconfig(ui-gadget-1)
 BuildRequires: pkgconfig(vconf)
@@ -308,6 +309,9 @@ fi
 %else
   "build_chrome=false" \
 %endif
+%if "%{?_ttrace}" == "1"
+  "use_ttrace=true" \
+%endif
 %endif  # _skip_gn
 
 ninja %{_smp_mflags} -C "%{OUTPUT_FOLDER}" \
index c1881e3..273a194 100644 (file)
 #ifndef SkTraceEvent_DEFINED
 #define SkTraceEvent_DEFINED
 
+#include <atomic>
+#include "build/build_config.h"
 #include "include/utils/SkEventTracer.h"
 #include "src/core/SkTraceEventCommon.h"
-#include <atomic>
+
+#if BUILDFLAG(IS_EFL)
+#include "base/trace_event/ttrace.h"
+#endif
 
 ////////////////////////////////////////////////////////////////////////////////
 // Implementation specific tracing API definitions.
 // Implementation detail: internal macro to create static category and add begin
 // event if the category is enabled. Also adds the end event when the scope
 // ends.
+#if defined(USE_TTRACE_TRACE_EVENT_SKIA)
+#define TTRACE_TRACE_EVENT(tracer, category_group, name) \
+  INTERNAL_TRACE_EVENT_UID(tracer).TTraceBegin(category_group, name);
+#else
+#define TTRACE_TRACE_EVENT(tracer, category_group, name)
+#endif
 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
     INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
     skia::tracing_internals::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
+    TTRACE_TRACE_EVENT(tracer, category_group, name) \
     do { \
         if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
           SkEventTracer::Handle h = skia::tracing_internals::AddTraceEvent( \
@@ -334,9 +346,17 @@ AddTraceEvent(
 class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
  public:
   // Note: members of data_ intentionally left uninitialized. See Initialize.
+#if defined(USE_TTRACE_TRACE_EVENT_SKIA)
+  ScopedTracer() : p_data_(NULL), use_ttrace_(false) {}
+#else
   ScopedTracer() : p_data_(nullptr) {}
+#endif
 
   ~ScopedTracer() {
+#if defined(USE_TTRACE_TRACE_EVENT_SKIA)
+    if (use_ttrace_)
+      TTRACE_WEB_TRACE_EVENT_END();
+#endif
     if (p_data_ && *data_.category_group_enabled)
       TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
           data_.category_group_enabled, data_.name, data_.event_handle);
@@ -351,6 +371,12 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
     p_data_ = &data_;
   }
 
+#if defined(USE_TTRACE_TRACE_EVENT_SKIA)
+  void TTraceBegin(const char* category_group, const char* name) {
+    use_ttrace_ = TTRACE_WEB_TRACE_EVENT_BEGIN(category_group, name);
+  }
+#endif
+
  private:
     ScopedTracer(const ScopedTracer&) = delete;
     ScopedTracer& operator=(const ScopedTracer&) = delete;
@@ -367,6 +393,9 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer {
   };
   Data* p_data_;
   Data data_;
+#if defined(USE_TTRACE_TRACE_EVENT_SKIA)
+  bool use_ttrace_;
+#endif
 };
 
 }  // namespace tracing_internals
index ce7e0ba..bee9081 100644 (file)
@@ -2,8 +2,8 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import("//tizen_src/build/config/tizen_features.gni")
 import("//tizen_src/build/config/linux/pkg_config.gni")
+import("//tizen_src/build/config/tizen_features.gni")
 
 config("evas") {
   ldflags = [ "-levas" ]
@@ -179,6 +179,13 @@ config("ui-gadget-public") {
   }
 }
 
+tizen_pkg_config("libttrace") {
+  packages = []
+  if (is_tizen) {
+    packages = [ "ttrace" ]
+  }
+}
+
 config("capi-appfw-application") {
   if (is_tizen) {
     ldflags = [ "-lcapi-appfw-application" ]
index deca03d..a8ebf16 100755 (executable)
@@ -242,6 +242,11 @@ function setupAndExecuteTargetBuild() {
     --skip-gn)
         ARGS+=(--define "_skip_gn 1")
     ;;
+    --ttrace)
+        ARGS[$count]=--define
+        count=$(( $count + 1 ))
+        ARGS[$count]="_ttrace 1"
+    ;;
     --component-build)
         ARGS+=(--define "component_build 1")
     ;;
index 3b4e9c1..eb89768 100644 (file)
@@ -49,12 +49,20 @@ config("tizen_feature_flags") {
       defines += [ "WAYLAND_BRINGUP" ]
     }
     if (tizen_product_tv) {
-      defines += [
-        "OS_TIZEN_TV_PRODUCT",
-      ]
+      defines += [ "OS_TIZEN_TV_PRODUCT" ]
     }
     if (tizen_multimedia) {
       defines += [ "TIZEN_MULTIMEDIA" ]
     }
+    if (use_ttrace) {
+      defines += [ "USE_TTRACE" ]
+      if (use_ttrace_chrome_trace) {
+        defines += [
+          "USE_TTRACE_TRACE_EVENT_SKIA",
+          "USE_TTRACE_TRACE_EVENT_V8",
+          "USE_TTRACE_TRACE_EVENT_WEBCORE",
+        ]
+      }
+    }
   }
 }
index 5e1ec9a..de32d58 100644 (file)
@@ -22,6 +22,9 @@ declare_args() {
   use_cairo = false
   use_pango = false
 
+  use_ttrace = false
+  use_ttrace_chrome_trace = false
+
   werror = false
 
   tizen_clang_base_path = "//tizen_src/buildtools/llvm"
@@ -49,6 +52,15 @@ declare_args() {
   tizen_web_speech_recognition = false
 }
 
+if (use_ttrace) {
+  use_ttrace_chrome_trace = true
+}
+
+# Enable ttrace except chrome trace log for TV profile by default
+if (tizen_product_tv) {
+  use_ttrace = true
+}
+
 if (is_tizen && tizen_multimedia_support) {
   tizen_multimedia_eme_support = true
 } else {
diff --git a/tizen_src/chromium_impl/base/BUILD.gn b/tizen_src/chromium_impl/base/BUILD.gn
new file mode 100644 (file)
index 0000000..0864461
--- /dev/null
@@ -0,0 +1,11 @@
+# Copyright (c) 2021 samsung electronics. all rights reserved.
+# use of this source code is governed by a bsd-style license that can be
+# found in the license file.
+
+static_library("trace_event_ttrace") {
+  configs += [ "//tizen_src/build:libttrace" ]
+  sources = [
+    "//tizen_src/chromium_impl/base/trace_event/trace_event_ttrace.cc",
+    "//tizen_src/chromium_impl/base/trace_event/ttrace.h",
+  ]
+}
index 61a9e08..83210b2 100644 (file)
@@ -3,6 +3,13 @@
 # found in the LICENSE file.
 
 import("//build/config/ui.gni")
+import("//tizen_src/build/config/tizen_features.gni")
+
+external_base_public_deps = []
+if (use_ttrace) {
+  external_base_public_deps +=
+      [ "//tizen_src/chromium_impl/base:trace_event_ttrace" ]
+}
 
 external_base_configs = [
   "//tizen_src/build:ecore",
@@ -13,4 +20,5 @@ external_base_sources = [
   "//tizen_src/chromium_impl/base/message_loop/message_pump_ecore.h",
   "//tizen_src/chromium_impl/base/message_loop/message_pump_for_ui_efl.cc",
   "//tizen_src/chromium_impl/base/message_loop/message_pump_for_ui_efl.h",
+  "//tizen_src/chromium_impl/base/trace_event/ttrace.h",
 ]
diff --git a/tizen_src/chromium_impl/base/trace_event/trace_event_ttrace.cc b/tizen_src/chromium_impl/base/trace_event/trace_event_ttrace.cc
new file mode 100644 (file)
index 0000000..0802abd
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2021 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ttrace.h"
+
+#if defined(USE_TTRACE)
+#include <string.h>
+#include <string>
+
+bool TraceEventTTraceBegin(uint64_t tag,
+                           const char* category_group,
+                           const char* name) {
+  bool result = false;
+  std::string tokens[] = {"!disabled", "!debug",      "blink", "cc", "gpu",
+                          "media",     "sandbox_ipc", "skia",  "v8"};
+  for (int i = 0; i < 9; i++) {
+    const char* category_group_token = tokens[i].c_str();
+    if (category_group_token[0] == '!') {
+      category_group_token++;
+      if ((*category_group_token == '*') ||
+          strstr(category_group, category_group_token))
+        return false;
+    } else {
+      if ((*category_group_token == '*') ||
+          strstr(category_group, category_group_token)) {
+        result = true;
+        break;
+      }
+    }
+  }
+
+  if (result)
+    traceBegin(tag, "[%s]%s", category_group, name);
+  return result;
+}
+#endif
diff --git a/tizen_src/chromium_impl/base/trace_event/ttrace.h b/tizen_src/chromium_impl/base/trace_event/ttrace.h
new file mode 100644 (file)
index 0000000..e90f737
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright 2021 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TRACE_EVENT_TTRACE_H_
+#define BASE_TRACE_EVENT_TTRACE_H_
+
+#ifdef USE_TTRACE
+#include <TTraceWrapper.h>
+
+bool TraceEventTTraceBegin(uint64_t tag,
+                           const char* category_group,
+                           const char* name);
+
+#define __TTRACE_WEB_SCOPE_VAR_HELPER(A, B) A##B
+#define __TTRACE_WEB_SCOPE_VAR(V, L) __TTRACE_WEB_SCOPE_VAR_HELPER(V, L)
+#define TTRACE_WEB_SCOPE(...)                                            \
+  TTraceWrapper __TTRACE_WEB_SCOPE_VAR(ttrace, __LINE__)(TTRACE_TAG_WEB, \
+                                                         __VA_ARGS__)
+#define TTRACE_WEB_MARK(...) traceMark(TTRACE_TAG_WEB, __VA_ARGS__)
+#define TTRACE_WEB_ASYNC_BEGIN(uid, ...) \
+  traceAsyncBegin(TTRACE_TAG_WEB, uid, __VA_ARGS__)
+#define TTRACE_WEB_ASYNC_END(uid, ...) \
+  traceAsyncEnd(TTRACE_TAG_WEB, uid, __VA_ARGS__)
+
+#define TTRACE_WEB_TRACE_EVENT_BEGIN(category_group, name) \
+  TraceEventTTraceBegin(TTRACE_TAG_WEB, category_group, name)
+#define TTRACE_WEB_TRACE_EVENT_END() traceEnd(TTRACE_TAG_WEB)
+#else
+#define TTRACE_WEB_SCOPE(...)
+#define TTRACE_WEB_MARK(...)
+#define TTRACE_WEB_ASYNC_BEGIN(...)
+#define TTRACE_WEB_ASYNC_END(...)
+#endif
+
+#define TTRACE_WEB TTRACE_WEB_SCOPE
+
+#endif  // BASE_TRACE_EVENT_TTRACE_H_
index 9392ea8..0e7b349 100644 (file)
@@ -24,6 +24,7 @@
 #include <algorithm>
 
 #include "authentication_challenge_popup.h"
+#include "base/trace_event/ttrace.h"
 #include "content/public/browser/navigation_controller.h"
 #include "cookie_manager.h"
 #include "eweb_view.h"
@@ -133,6 +134,7 @@ Ewk_Context *ewk_view_context_get(const Evas_Object *view)
 
 Eina_Bool ewk_view_url_set(Evas_Object* view, const char* url_string)
 {
+  TTRACE_WEB("ewk_view_url_set url: %s", url_string);
   EWK_VIEW_IMPL_GET_OR_RETURN(view, impl, false);
   EINA_SAFETY_ON_NULL_RETURN_VAL(url_string, false);
   GURL url(url_string);
index 2d6149d..67a2e18 100644 (file)
@@ -5,6 +5,7 @@
 #include "web_contents_delegate_efl.h"
 
 #include "base/strings/utf_string_conversions.h"
+#include "base/trace_event/ttrace.h"
 #include "browser/favicon/favicon_database.h"
 #include "browser/input_picker/color_chooser_efl.h"
 #include "browser/javascript_dialog_manager_efl.h"
@@ -567,9 +568,7 @@ void WebContentsDelegateEfl::DidRenderFrame() {
       (web_view_->GetProgressValue() > 0.1)) {
     did_first_visually_non_empty_paint_ = false;
     did_render_frame_ = true;
-#if defined(USE_TTRACE)
     TTRACE_WEB("WebContentsDelegateEfl::DidRenderFrame");
-#endif
     LOG(INFO) << "WebContentsDelegateEfl::DidRenderFrame";
 
     // "frame,rendered" message is triggered as soon as rendering of a frame
index be07049..53d0a15 100644 (file)
@@ -9,6 +9,7 @@ import("//build/config/host_byteorder.gni")
 import("//build/config/mips.gni")
 import("//build/config/sanitizers/sanitizers.gni")
 import("//build_overrides/build.gni")
+import("//tizen_src/build/config/tizen_features.gni")
 
 if (is_android) {
   import("//build/config/android/rules.gni")
@@ -5495,6 +5496,9 @@ v8_component("v8_libbase") {
         "pthread",
       ]
     }
+    if (use_ttrace) {
+      deps += [ "//tizen_src/chromium_impl/base:trace_event_ttrace" ]
+    }
   } else if (current_os == "aix") {
     sources += [
       "src/base/debug/stack_trace_posix.cc",
index ed53d55..61df648 100644 (file)
 #include "base/trace_event/common/trace_event_common.h"
 #endif  // !defined(V8_USE_PERFETTO)
 
+#include "build/build_config.h"
 #include "include/v8-platform.h"
 #include "src/base/atomicops.h"
 #include "src/base/macros.h"
 
+#if BUILDFLAG(IS_EFL)
+#include "base/trace_event/ttrace.h"
+#endif
 // This header file defines implementation details of how the trace macros in
 // trace_event_common.h collect and store trace events. Anything not
 // implementation-specific should go in trace_macros_common.h instead of here.
@@ -192,18 +196,24 @@ enum CategoryGroupEnabledFlags {
 // Implementation detail: internal macro to create static category and add begin
 // event if the category is enabled. Also adds the end event when the scope
 // ends.
+#if defined(USE_TTRACE_TRACE_EVENT_V8)
+#define TTRACE_TRACE_EVENT(tracer, category_group, name) \
+  INTERNAL_TRACE_EVENT_UID(tracer).TTraceBegin(category_group, name);
+#else
+#define TTRACE_TRACE_EVENT(tracer, category_group, name)
+#endif
 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...)           \
   INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                    \
   v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer);      \
+  TTRACE_TRACE_EVENT(tracer, category_group, name)                           \
   if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) {    \
     uint64_t h = v8::internal::tracing::AddTraceEvent(                       \
         TRACE_EVENT_PHASE_COMPLETE,                                          \
         INTERNAL_TRACE_EVENT_UID(category_group_enabled), name,              \
         v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId,   \
         v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
-    INTERNAL_TRACE_EVENT_UID(tracer)                                         \
-        .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name,  \
-                    h);                                                      \
+    INTERNAL_TRACE_EVENT_UID(tracer).Initialize(                             \
+        INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h);          \
   }
 
 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name,     \
@@ -562,9 +572,16 @@ static V8_INLINE uint64_t AddTraceEventWithTimestamp(
 class ScopedTracer {
  public:
   // Note: members of data_ intentionally left uninitialized. See Initialize.
+#if defined(USE_TTRACE_TRACE_EVENT_V8)
+  ScopedTracer() : p_data_(nullptr), use_ttrace_(false) {}
+#else
   ScopedTracer() : p_data_(nullptr) {}
+#endif
 
   ~ScopedTracer() {
+#if defined(USE_TTRACE_TRACE_EVENT_V8)
+    if (use_ttrace_) TTRACE_WEB_TRACE_EVENT_END();
+#endif
     if (p_data_ && base::Relaxed_Load(reinterpret_cast<const base::Atomic8*>(
                        data_.category_group_enabled))) {
       TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
@@ -572,6 +589,12 @@ class ScopedTracer {
     }
   }
 
+#if defined(USE_TTRACE_TRACE_EVENT_V8)
+  void TTraceBegin(const char* category_group, const char* name) {
+    use_ttrace_ = TTRACE_WEB_TRACE_EVENT_BEGIN(category_group, name);
+  }
+#endif
+
   void Initialize(const uint8_t* category_group_enabled, const char* name,
                   uint64_t event_handle) {
     data_.category_group_enabled = category_group_enabled;
@@ -593,6 +616,9 @@ class ScopedTracer {
   };
   Data* p_data_;
   Data data_;
+#if defined(USE_TTRACE_TRACE_EVENT_V8)
+  bool use_ttrace_;
+#endif
 };
 
 #ifdef V8_RUNTIME_CALL_STATS