honggyukim / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
1 stars 0 forks source link

uftrace for chromium #8

Open honggyukim opened 5 years ago

honggyukim commented 5 years ago

top level change

diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 3005ee7659..8b030613e9 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -461,6 +461,10 @@ config("compiler") {
     # Do not use the -pthread ldflag here since it becomes a no-op
     # when using -nodefaultlibs, which would cause an unused argument
     # error.  "-lpthread" is added in //build/config:default_libs.
+
+    if (use_uftrace) {
+      cflags += [ "-g", "-pg", "-fno-omit-frame-pointer" ]
+    }
   }

   # Clang-specific compiler flags setup.
diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni
index bfbafe5b59..a2170211c9 100644
--- a/build/config/compiler/compiler.gni
+++ b/build/config/compiler/compiler.gni
@@ -69,6 +69,9 @@ declare_args() {
   # It's currently not possible to collect AFDO profiles on anything but
   # x86{,_64}.
   using_mismatched_sample_profile = current_cpu != "x64" && current_cpu != "x86"
+
+  # Enables -g -pg -fno-omit-frame-pointer for uftrace
+  use_uftrace = false
 }

 assert(!is_cfi || use_thin_lto, "CFI requires ThinLTO")

inside src/third_party/ffmpeg

diff --git a/BUILD.gn b/BUILD.gn
index 0448476773..585314c3c7 100755
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -7,6 +7,7 @@ import("ffmpeg_generated.gni")

 import("//build/buildflag_header.gni")
 import("//build/config/sanitizers/sanitizers.gni")
+import("//build/config/compiler/compiler.gni")

 # Path to platform configuration files.
 platform_config_root =
@@ -260,6 +261,10 @@ target(link_target_type, "ffmpeg_internal") {
       "-Wno-deprecated-declarations",
     ]

+    if (use_uftrace) {
+      cflags -= [ "-fomit-frame-pointer" ]
+    }
+
     if (!is_clang) {
       # gcc doesn't have flags for specific warnings, so disable them
       # all.

inside src/third_party/swiftshader

diff --git a/BUILD.gn b/BUILD.gn
index 027adfd76..4910a5bdb 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -75,6 +75,10 @@ config("swiftshader_config") {
         "-Os",
       ]

+      if (use_uftrace) {
+        cflags -= [ "-fomit-frame-pointer", ]
+      }
+
       defines += [
         "ANGLE_DISABLE_TRACE",
         "NDEBUG",

build command

$ gn gen out/Release.g.pg && cd out/Release.g.pg

$ cat args.gn
enable_nacl = false
is_component_build = false
is_debug = false
use_lld = false
use_gold = true
use_jumbo_build = true
symbol_level = 1
use_uftrace = true

$ ninja chrome

To know more about other options, gn args out/Release.g.pg --list will show the entire options.

honggyukim commented 1 year ago
$ git log -1 --oneline
30f86b24eeb5e (HEAD -> refs/heads/114.0.5715.1, tag: refs/tags/114.0.5715.1) Publish DEPS for 114.0.5715.1
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index d0b55ce295fdf..8ca5912034e5a 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -850,6 +850,10 @@ config("compiler") {
     asmflags += cflags_c
   }

+  if (use_uftrace) {
+    cflags += [ "-g", "-fpatchable-function-entry=5" ]
+  }
+
   # Rust compiler flags setup.
   # ---------------------------
   rustflags = [
diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni
index 4738ee80d307c..300b72b0b08fc 100644
--- a/build/config/compiler/compiler.gni
+++ b/build/config/compiler/compiler.gni
@@ -106,6 +106,9 @@ declare_args() {
   # x86{,_64}.
   using_mismatched_sample_profile = current_cpu != "x64" && current_cpu != "x86"

+  # Enables -g -fpatchable-function-entry=5 for uftrace
+  use_uftrace = false
+
   # Whether an error should be raised on attempts to make debug builds with
   # is_component_build=false. Very large debug symbols can have unwanted side
   # effects so this is enforced by default for chromium.
diff --git a/base/debug/stack_trace.cc b/base/debug/stack_trace.cc
index 3debc8bd070cd..82e2db29d0883 100644
--- a/base/debug/stack_trace.cc
+++ b/base/debug/stack_trace.cc
@@ -273,7 +273,6 @@ void StackTrace::Print() const {
 }

 void StackTrace::OutputToStream(std::ostream* os) const {
-  OutputToStreamWithPrefix(os, nullptr);
 }

 std::string StackTrace::ToString() const {
@@ -281,9 +280,6 @@ std::string StackTrace::ToString() const {
 }
 std::string StackTrace::ToStringWithPrefix(const char* prefix_string) const {
   std::stringstream stream;
-#if !defined(__UCLIBC__) && !defined(_AIX)
-  OutputToStreamWithPrefix(&stream, prefix_string);
-#endif
   return stream.str();
 }

diff --git a/base/debug/stack_trace_posix.cc b/base/debug/stack_trace_posix.cc
index 0eaad5ce3348c..6436847c5bd98 100644
--- a/base/debug/stack_trace_posix.cc
+++ b/base/debug/stack_trace_posix.cc
@@ -42,7 +42,6 @@
 // libc.
 #if BUILDFLAG(IS_APPLE) || \
     (defined(__GLIBC__) && !defined(__UCLIBC__) && !defined(__AIX))
-#define HAVE_BACKTRACE
 #include <execinfo.h>
 #endif

To fix build error.

diff --git a/third_party/dom_distiller_js/protoc_plugins/util/plugin_protos.py b/third_party/dom_distiller_js/protoc_plugins/util/plugin_protos.py
index 2c03e6835f3af..6c72cefe6f6aa 100644
--- a/third_party/dom_distiller_js/protoc_plugins/util/plugin_protos.py
+++ b/third_party/dom_distiller_js/protoc_plugins/util/plugin_protos.py
@@ -15,10 +15,10 @@ import sys
 SCRIPT_DIR = os.path.dirname(__file__)
 SRC_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..', '..'))

-sys.path.insert(
-    1, os.path.join(SRC_DIR, 'third_party', 'protobuf', 'python'))
-sys.path.insert(
-    1, os.path.join(SRC_DIR, 'third_party', 'protobuf', 'third_party', 'six'))
+#sys.path.insert(
+#    1, os.path.join(SRC_DIR, 'third_party', 'protobuf', 'python'))
+#sys.path.insert(
+#    1, os.path.join(SRC_DIR, 'third_party', 'protobuf', 'third_party', 'six'))
 from google.protobuf.descriptor_pb2 import FieldDescriptorProto
 from google.protobuf.compiler import plugin_pb2
honggyukim commented 1 year ago

NOTE: This code MUST be async-signal safe (it's used by in-process stack dumping signal handler). NO malloc or stdio is allowed here.

size_t CollectStackTrace(void** trace, size_t count) {
  // NOTE: This code MUST be async-signal safe (it's used by in-process
  // stack dumping signal handler). NO malloc or stdio is allowed here.

#if defined(NO_UNWIND_TABLES) && BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
  // If we do not have unwind tables, then try tracing using frame pointers.
  return base::debug::TraceStackFramePointers(const_cast<const void**>(trace),
                                              count, 0);
#elif defined(HAVE_BACKTRACE)
  // Though the backtrace API man page does not list any possible negative
  // return values, we take no chance.
  return base::saturated_cast<size_t>(
      backtrace(trace, base::saturated_cast<int>(count)));
#else
  return 0;
#endif
}

base/debug/stack_trace_posix.cc

honggyukim commented 1 year ago
$ uftrace record -P. --no-libcall -v ./chrome --no-sandbox --headless --disable-gpu \
      --screenshot --window-size=1280,1696 https://www.google.com

https://developer.chrome.com/blog/headless-chrome/