Commit c65456bf authored by Sami Kyostila's avatar Sami Kyostila Committed by Commit Bot

tracing: Initialize track events conditionally

If V8 is running in a context where Perfetto hasn't been initialized
(e.g., as part of mksnapshot), don't try to initialize track events
either.

Since perfetto::Tracing::IsInitialized() was only added recently, we
also roll Perfetto to the latest revision. This also requires updating
the proto_library GN template together with the underlying libprotobuf
dependency.

Bug: chromium:1006541
Change-Id: Icec626b7ed78264a81f1a80d73d60be3bde0d908
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2632590
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72130}
parent a75b129a
This diff is collapsed.
......@@ -286,9 +286,9 @@ deps = {
'dep_type': 'cipd',
},
'third_party/perfetto':
Var('android_url') + '/platform/external/perfetto.git' + '@' + '7cdc44f903d3bcfd1d0f67188bfa797a24756868',
Var('android_url') + '/platform/external/perfetto.git' + '@' + 'aa4385bc5997ecad4c633885e1b331b1115012fb',
'third_party/protobuf':
Var('chromium_url') + '/external/github.com/google/protobuf'+ '@' + 'b68a347f56137b4b1a746e8c7438495a6ac1bd91',
Var('chromium_url') + '/external/github.com/google/protobuf'+ '@' + '6a59a2ad1f61d9696092f79b6d74368b4d7970a3',
'third_party/zlib':
Var('chromium_url') + '/chromium/src/third_party/zlib.git'+ '@' + '2c183c9f93a328bfb3121284da13cf89a0f7e64a',
'third_party/jsoncpp/source':
......
......@@ -7,16 +7,16 @@ import("//build_overrides/build.gni")
# This file should not be pulled in chromium builds.
assert(!build_with_chromium)
if (host_os == "win") {
_host_executable_suffix = ".exe"
} else {
_host_executable_suffix = ""
}
template("proto_library") {
assert(defined(invoker.sources))
proto_sources = invoker.sources
if (host_os == "win") {
host_executable_suffix = ".exe"
} else {
host_executable_suffix = ""
}
# All the proto imports should be relative to the project root.
proto_in_dir = "//"
if (defined(invoker.proto_in_dir)) {
......@@ -32,6 +32,11 @@ template("proto_library") {
# generate_python = true.
assert(defined(invoker.generate_python) && !invoker.generate_python)
import_dirs = []
if (defined(invoker.import_dirs)) {
import_dirs = invoker.import_dirs
}
# If false will not generate the default .pb.{cc,h} files. Used for custom
# codegen plugins.
generate_cc = true
......@@ -48,7 +53,7 @@ template("proto_library") {
plugin_host_label = invoker.generator_plugin_label + "($host_toolchain)"
plugin_path =
get_label_info(plugin_host_label, "root_out_dir") + "/" +
get_label_info(plugin_host_label, "name") + host_executable_suffix
get_label_info(plugin_host_label, "name") + _host_executable_suffix
generate_with_plugin = true
} else if (defined(invoker.generator_plugin_script)) {
plugin_path = invoker.generator_plugin_script
......@@ -68,14 +73,19 @@ template("proto_library") {
}
}
cc_out_dir = "$root_gen_dir/" + proto_out_dir
rel_cc_out_dir = rebase_path(cc_out_dir, root_build_dir)
out_dir = "$root_gen_dir/" + proto_out_dir
rel_out_dir = rebase_path(out_dir, root_build_dir)
# Prevent unused errors when generating descriptor only.
if (generate_descriptor != "") {
not_needed([ "rel_out_dir" ])
}
protos = rebase_path(proto_sources, proto_in_dir)
protogens = []
if (generate_descriptor != "") {
protogens += [ "$root_gen_dir/" + generate_descriptor ]
protogens += [ "$out_dir/${generate_descriptor}" ]
}
foreach(proto, protos) {
......@@ -83,44 +93,64 @@ template("proto_library") {
proto_name = get_path_info(proto, "name")
proto_path = proto_dir + "/" + proto_name
# Prevent unused errors when generating descriptor only.
if (generate_descriptor != "") {
not_needed([ "proto_path" ])
}
if (generate_cc) {
protogens += [
"$cc_out_dir/$proto_path.pb.h",
"$cc_out_dir/$proto_path.pb.cc",
"$out_dir/$proto_path.pb.h",
"$out_dir/$proto_path.pb.cc",
]
}
if (generate_with_plugin) {
foreach(suffix, generator_plugin_suffixes) {
protogens += [ "$cc_out_dir/${proto_path}${suffix}" ]
protogens += [ "$out_dir/${proto_path}${suffix}" ]
}
}
}
config_name = "${target_name}_config"
action_name = "${target_name}_gen"
source_set_name = target_name
if (generate_descriptor == "") {
action_name = "${target_name}_gen"
source_set_name = target_name
} else {
action_name = target_name
}
config(config_name) {
include_dirs = [ cc_out_dir ]
include_dirs = [ out_dir ]
}
# The XXX_gen action that generates the .pb.{cc,h} files.
action(action_name) {
visibility = [ ":$source_set_name" ]
script = "//build/gn_run_binary.py"
if (generate_descriptor == "") {
visibility = [ ":$source_set_name" ]
}
sources = proto_sources
outputs = get_path_info(protogens, "abspath")
protoc_label = "//:protoc($host_toolchain)"
protoc_path = get_label_info(protoc_label, "root_out_dir") + "/protoc" +
host_executable_suffix
_host_executable_suffix
protoc_rebased_path = "./" + rebase_path(protoc_path, root_build_dir)
script = "//gni/protoc.py"
args = [
# Path should be rebased because |root_build_dir| for current toolchain
# may be different from |root_out_dir| of protoc built on host toolchain.
"./" + rebase_path(protoc_path, root_build_dir),
protoc_rebased_path,
"--proto_path",
rebase_path(proto_in_dir, root_build_dir),
]
foreach(path, import_dirs) {
args += [
"--proto_path",
rebase_path(path, root_build_dir),
]
}
if (generate_cc) {
cc_generator_options_ = ""
if (defined(invoker.cc_generator_options)) {
......@@ -128,30 +158,27 @@ template("proto_library") {
}
args += [
"--cpp_out",
cc_generator_options_ + rel_cc_out_dir,
cc_generator_options_ + rel_out_dir,
]
}
if (generate_descriptor != "") {
depfile = "$out_dir/$generate_descriptor.d"
args += [
"--include_imports",
"--descriptor_set_out",
rebase_path("$root_gen_dir/" + generate_descriptor, root_build_dir),
rebase_path("$out_dir/$generate_descriptor", root_build_dir),
"--dependency_out",
rebase_path(depfile, root_build_dir),
]
}
if (defined(invoker.import_dirs)) {
foreach(path, invoker.import_dirs) {
args += [ "--import-dir=" + rebase_path(path, root_build_dir) ]
}
}
if (generate_with_plugin) {
plugin_path_rebased = rebase_path(plugin_path, root_build_dir)
plugin_out_args = ""
if (defined(invoker.generator_plugin_options)) {
plugin_out_args += invoker.generator_plugin_options
}
plugin_out_args += ":$rel_cc_out_dir"
plugin_out_args += ":$rel_out_dir"
args += [
"--plugin=protoc-gen-plugin=$plugin_path_rebased",
......@@ -162,8 +189,15 @@ template("proto_library") {
args += rebase_path(proto_sources, root_build_dir)
inputs = [ protoc_path ]
deps = [ protoc_label ]
# TODO(hjd): Avoid adding to deps here this.
# When we generate BUILD files we need find the transitive proto,
# dependencies, so also add link_deps to actual deps so they show up
# in gn desc.
if (defined(invoker.link_deps)) {
deps += invoker.link_deps
}
if (generate_with_plugin) {
inputs += [ plugin_path ]
if (defined(plugin_host_label)) {
......@@ -172,61 +206,64 @@ template("proto_library") {
}
}
if (defined(invoker.proto_deps)) {
deps += invoker.proto_deps
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
} # action "${target_name}_gen"
} # action(action_name)
# The source_set that builds the generated .pb.cc files.
source_set(target_name) {
forward_variables_from(invoker,
[
"defines",
"include_dirs",
"public_configs",
"testonly",
"visibility",
])
sources = get_target_outputs(":$action_name")
# configs -= [ "//gn/standalone:extra_warnings" ]
if (defined(invoker.extra_configs)) {
configs += invoker.extra_configs
}
if (generate_descriptor == "") {
source_set(source_set_name) {
forward_variables_from(invoker,
[
"defines",
"include_dirs",
"public_configs",
"testonly",
"visibility",
])
sources = get_target_outputs(":$action_name")
if (defined(invoker.extra_configs)) {
configs += invoker.extra_configs
}
if (!defined(invoker.public_configs)) {
public_configs = []
}
if (!defined(invoker.public_configs)) {
public_configs = []
}
public_configs += [ "//:protobuf_gen_config" ]
public_configs += [
"//:protobuf_gen_config",
":$config_name",
]
propagate_imports_configs = !defined(invoker.propagate_imports_configs) ||
invoker.propagate_imports_configs
if (propagate_imports_configs) {
public_configs += [ ":$config_name" ]
} else {
# Embedder handles include directory propagation to dependents.
configs += [ ":$config_name" ]
}
# By default, propagate the config for |include_dirs| to dependent
# targets, so that public imports can be resolved to corresponding header
# files. In some cases, the embedder target handles include directory
# propagation itself, e.g. via a common config.
propagate_imports_configs = !defined(invoker.propagate_imports_configs) ||
invoker.propagate_imports_configs
if (propagate_imports_configs) {
public_configs += [ ":$config_name" ]
} else {
configs += [ ":$config_name" ]
}
# Use protobuf_full only for tests.
if (defined(invoker.use_protobuf_full) &&
invoker.use_protobuf_full == true) {
deps = [ "//:protobuf_full" ]
} else {
deps = [ "//:protobuf_lite" ]
}
# Use protobuf_full only for tests.
if (defined(invoker.use_protobuf_full) &&
invoker.use_protobuf_full == true) {
deps = [ "//:protobuf_full" ]
} else if (generate_cc) {
deps = [ "//:protobuf_lite" ]
} else {
deps = []
}
deps += [ ":$action_name" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (defined(invoker.link_deps)) {
deps += invoker.link_deps
}
} # source_set(target_name)
deps += [ ":$action_name" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
} # source_set(source_set_name)
}
} # template
#!/usr/bin/env python
# Copyright 2021 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Script to wrap protoc execution.
This script exists to work-around the bad depfile generation by protoc when
generating descriptors."""
from __future__ import print_function
import argparse
import os
import sys
import subprocess
import tempfile
import uuid
from codecs import open
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--descriptor_set_out', default=None)
parser.add_argument('--dependency_out', default=None)
parser.add_argument('protoc')
args, remaining = parser.parse_known_args()
if args.dependency_out and args.descriptor_set_out:
tmp_path = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
custom = [
'--descriptor_set_out', args.descriptor_set_out, '--dependency_out',
tmp_path
]
try:
cmd = [args.protoc] + custom + remaining
subprocess.check_call(cmd)
with open(tmp_path, 'rb') as tmp_rd:
dependency_data = tmp_rd.read().decode('utf-8')
finally:
if os.path.exists(tmp_path):
os.unlink(tmp_path)
with open(args.dependency_out, 'w', encoding='utf-8') as f:
f.write(args.descriptor_set_out + ":")
f.write(dependency_data)
else:
subprocess.check_call(sys.argv[1:])
if __name__ == '__main__':
sys.exit(main())
......@@ -106,7 +106,7 @@ void V8::InitializeOncePerProcessImpl() {
if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed);
#if defined(V8_USE_PERFETTO)
TrackEvent::Register();
if (perfetto::Tracing::IsInitialized()) TrackEvent::Register();
#endif
Isolate::InitializeOncePerProcess();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment