Skip to content

uftrace for chromium

Honggyu Kim edited this page Aug 11, 2019 · 21 revisions

1. Download depot_tools

Chromium uses a package of scripts called depot_tools to manage checkouts and code reviews.
The depot_tools package includes gclient, gcl, git-cl, repo, and others. Chromium uses a package of scripts called depot_tools to manage checkouts and code reviews.

# download depot_tools
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

# environment setup for depot_tools
$ export PATH=`pwd`/depot_tools:$PATH

2. Download chromium

First, create a directory chromium.

$ mkdir chromium && cd chromium

Then, create .gclient file in the current directory as follows:

solutions = [
  {
    "url": "https://chromium.googlesource.com/chromium/src.git",
    "managed": False,
    "name": "src",
    "custom_deps": {},
  },
]

Do (shallow) git clone for chromium source code.

$ git clone --depth=1 https://chromium.googlesource.com/chromium/src.git -b 73.0.3676.0
$ cd src

Then, download third party modules.

$ gclient sync --shallow

3. Change build scripts for -pg build support

The following use_uftrace.diff file contains some changes to apply -pg build for uftrace.

diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 54ce77b..204e721 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -762,6 +762,10 @@ config("compiler") {
     asmflags += cflags
     asmflags += cflags_c
   }
+
+  if (use_uftrace) {
+    cflags += [ "-g", "-pg", "-fno-omit-frame-pointer" ]
+  }
 }
 
 # This provides the basic options to select the target CPU and ABI.
diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni
index 18a7f08..ca00a68 100644
--- a/build/config/compiler/compiler.gni
+++ b/build/config/compiler/compiler.gni
@@ -74,6 +74,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")
diff --git a/third_party/ffmpeg/BUILD.gn b/third_party/ffmpeg/BUILD.gn
index fd79bc4..4a3eaae 100755
--- a/third_party/ffmpeg/BUILD.gn
+++ b/third_party/ffmpeg/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 =
@@ -265,6 +266,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.
diff --git a/third_party/swiftshader/BUILD.gn b/third_party/swiftshader/BUILD.gn
index 56c78ce..54933c0 100644
--- a/third_party/swiftshader/BUILD.gn
+++ b/third_party/swiftshader/BUILD.gn
@@ -76,6 +76,10 @@ config("swiftshader_config") {
         "-Os",
       ]

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

Since those changes have to be made across multiple different repositories, it has to be applied as follows:

$ patch -p1 < use_uftrace.diff
patching file build/config/compiler/compiler.gni
patching file third_party/ffmpeg/BUILD.gn
patching file third_party/swiftshader/BUILD.gn

4. Build for chrome

$ gn gen out/Release.pg.g "--args=enable_nacl=false is_component_build=false is_debug=false use_jumbo_build=true symbol_level=2 use_uftrace=true"

$ ninja -C out/Release.pg.g chrome

$ cd out/Release.pg.g
$ nm ./chrome | grep mcount
                 U mcount

5. Tracing chrome with uftrace The following command records a simple chrome execution in headless mode.

$ uftrace record -t 5ms ./chrome --no-sandbox --headless https://www.google.com

6. Visualized trace output of chrome

chrome.svg

Clone this wiki locally