From 87043bbb966ae4fedf1410bfd23028bab59d701b Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 27 Apr 2021 10:15:16 -0400 Subject: [PATCH] [diagnostics] Don't build system trace code on non-win non-mac Bug: v8:11699 Change-Id: I286ea7d3a6455528c66eee3f479455bfc49f190c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2852039 Commit-Queue: Nico Weber Reviewed-by: Camillo Bruni Cr-Commit-Position: refs/heads/master@{#74232} --- BUILD.gn | 21 +++++++++-------- src/d8/d8.cc | 4 +--- src/diagnostics/system-jit-win.cc | 4 ++++ src/libplatform/tracing/recorder-default.cc | 25 --------------------- src/libplatform/tracing/recorder.h | 12 +++++----- src/libplatform/tracing/trace-writer.cc | 5 +++++ src/libplatform/tracing/trace-writer.h | 2 ++ tools/generate-header-include-checks.py | 2 ++ 8 files changed, 29 insertions(+), 46 deletions(-) delete mode 100644 src/libplatform/tracing/recorder-default.cc diff --git a/BUILD.gn b/BUILD.gn index ebd711bc6a..5bf2f3ecc7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -41,7 +41,7 @@ declare_args() { v8_enable_future = false # Sets -DSYSTEM_INSTRUMENTATION. Enables OS-dependent event tracing - v8_enable_system_instrumentation = true + v8_enable_system_instrumentation = is_win || is_mac # Sets the GUID for the ETW provider v8_etw_guid = "" @@ -4781,8 +4781,6 @@ v8_component("v8_libplatform") { "src/libplatform/delayed-task-queue.h", "src/libplatform/task-queue.cc", "src/libplatform/task-queue.h", - "src/libplatform/tracing/recorder-default.cc", - "src/libplatform/tracing/recorder.h", "src/libplatform/tracing/trace-buffer.cc", "src/libplatform/tracing/trace-buffer.h", "src/libplatform/tracing/trace-config.cc", @@ -4813,8 +4811,6 @@ v8_component("v8_libplatform") { if (v8_use_perfetto) { sources -= [ "//base/trace_event/common/trace_event_common.h", - "src/libplatform/tracing/recorder-default.cc", - "src/libplatform/tracing/recorder.h", "src/libplatform/tracing/trace-buffer.cc", "src/libplatform/tracing/trace-buffer.h", "src/libplatform/tracing/trace-object.cc", @@ -4829,12 +4825,15 @@ v8_component("v8_libplatform") { # TODO(skyostil): Switch TraceEventListener to protozero. "//third_party/perfetto/protos/perfetto/trace:lite", ] - } else if (is_win) { - sources -= [ "src/libplatform/tracing/recorder-default.cc" ] - sources += [ "src/libplatform/tracing/recorder-win.cc" ] - } else if (is_mac) { - sources -= [ "src/libplatform/tracing/recorder-default.cc" ] - sources += [ "src/libplatform/tracing/recorder-mac.cc" ] + } + + if (v8_enable_system_instrumentation) { + sources += [ "src/libplatform/tracing/recorder.h" ] + if (is_mac) { + sources += [ "src/libplatform/tracing/recorder-mac.cc" ] + } else if (is_win) { + sources += [ "src/libplatform/tracing/recorder-win.cc" ] + } } } diff --git a/src/d8/d8.cc b/src/d8/d8.cc index ce1e1a2c04..9299a7fc48 100644 --- a/src/d8/d8.cc +++ b/src/d8/d8.cc @@ -4146,17 +4146,15 @@ bool Shell::SetOptions(int argc, char* argv[]) { options.fuzzy_module_file_extensions = true; argv[i] = nullptr; #if defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) -#if defined(V8_TARGET_OS_WIN) || defined(V8_TARGET_OS_MACOSX) } else if (strcmp(argv[i], "--enable-system-instrumentation") == 0) { options.enable_system_instrumentation = true; options.trace_enabled = true; -#if defined(V8_TARGET_OS_WIN) +#if defined(V8_OS_WIN) // Guard this bc the flag has a lot of overhead and is not currently used // by macos i::FLAG_interpreted_frames_native_stack = true; #endif argv[i] = nullptr; -#endif #endif } } diff --git a/src/diagnostics/system-jit-win.cc b/src/diagnostics/system-jit-win.cc index 49200219c2..a4c4237c16 100644 --- a/src/diagnostics/system-jit-win.cc +++ b/src/diagnostics/system-jit-win.cc @@ -9,6 +9,10 @@ #include "src/diagnostics/system-jit-metadata-win.h" #include "src/libplatform/tracing/recorder.h" +#if !defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) +#error "This file is only compiled if v8_enable_system_instrumentation" +#endif + #if defined(__clang__) #pragma clang diagnostic ignored "-Wc++98-compat-extra-semi" #endif diff --git a/src/libplatform/tracing/recorder-default.cc b/src/libplatform/tracing/recorder-default.cc deleted file mode 100644 index 46e0cbb8e2..0000000000 --- a/src/libplatform/tracing/recorder-default.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020 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. -#ifndef V8_LIBPLATFORM_TRACING_RECORDER_DEFAULT_H_ -#define V8_LIBPLATFORM_TRACING_RECORDER_DEFAULT_H_ - -#include "src/libplatform/tracing/recorder.h" - -namespace v8 { -namespace platform { -namespace tracing { - -Recorder::Recorder() {} -Recorder::~Recorder() {} - -bool Recorder::IsEnabled() { return false; } -bool Recorder::IsEnabled(const uint8_t level) { return false; } - -void Recorder::AddEvent(TraceObject* trace_event) {} - -} // namespace tracing -} // namespace platform -} // namespace v8 - -#endif // V8_LIBPLATFORM_TRACING_RECORDER_DEFAULT_H_ diff --git a/src/libplatform/tracing/recorder.h b/src/libplatform/tracing/recorder.h index b0fac64e0a..8b8eb0e0e9 100644 --- a/src/libplatform/tracing/recorder.h +++ b/src/libplatform/tracing/recorder.h @@ -9,19 +9,17 @@ #include "include/libplatform/v8-tracing.h" -#ifdef V8_OS_MACOSX #if !defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) -#error V8_ENABLE_SYSTEM_INSTRUMENTATION is not defined +#error "only include this file if V8_ENABLE_SYSTEM_INSTRUMENTATION" #endif + +#if V8_OS_MACOSX #include #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability" #endif #if V8_OS_WIN -#if !defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) -#error V8_ENABLE_SYSTEM_INSTRUMENTATION is not defined -#endif #ifndef V8_ETW_GUID #define V8_ETW_GUID \ 0x57277741, 0x3638, 0x4A4B, 0xBD, 0xBA, 0x0A, 0xC6, 0xE4, 0x5D, 0xA5, 0x6C @@ -49,7 +47,7 @@ class V8_PLATFORM_EXPORT Recorder { void AddEvent(TraceObject* trace_event); private: -#ifdef V8_OS_MACOSX +#if V8_OS_MACOSX os_log_t v8Provider; #endif }; @@ -58,7 +56,7 @@ class V8_PLATFORM_EXPORT Recorder { } // namespace platform } // namespace v8 -#ifdef V8_OS_MACOSX +#if V8_OS_MACOSX #pragma clang diagnostic pop #endif diff --git a/src/libplatform/tracing/trace-writer.cc b/src/libplatform/tracing/trace-writer.cc index 5740dabd8f..1131522eec 100644 --- a/src/libplatform/tracing/trace-writer.cc +++ b/src/libplatform/tracing/trace-writer.cc @@ -9,7 +9,10 @@ #include "base/trace_event/common/trace_event_common.h" #include "include/v8-platform.h" #include "src/base/platform/platform.h" + +#if defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) #include "src/libplatform/tracing/recorder.h" +#endif namespace v8 { namespace platform { @@ -191,6 +194,7 @@ TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream, return new JSONTraceWriter(stream, tag); } +#if defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) SystemInstrumentationTraceWriter::SystemInstrumentationTraceWriter() { recorder_ = std::make_unique(); } @@ -211,6 +215,7 @@ void SystemInstrumentationTraceWriter::Flush() {} TraceWriter* TraceWriter::CreateSystemInstrumentationTraceWriter() { return new SystemInstrumentationTraceWriter(); } +#endif } // namespace tracing } // namespace platform diff --git a/src/libplatform/tracing/trace-writer.h b/src/libplatform/tracing/trace-writer.h index 1f727b815a..2fada45108 100644 --- a/src/libplatform/tracing/trace-writer.h +++ b/src/libplatform/tracing/trace-writer.h @@ -29,6 +29,7 @@ class JSONTraceWriter : public TraceWriter { bool append_comma_ = false; }; +#if defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) class SystemInstrumentationTraceWriter : public TraceWriter { public: SystemInstrumentationTraceWriter(); @@ -39,6 +40,7 @@ class SystemInstrumentationTraceWriter : public TraceWriter { private: std::unique_ptr recorder_; }; +#endif } // namespace tracing } // namespace platform diff --git a/tools/generate-header-include-checks.py b/tools/generate-header-include-checks.py index 4e58a492de..2171ee8a0d 100755 --- a/tools/generate-header-include-checks.py +++ b/tools/generate-header-include-checks.py @@ -31,6 +31,8 @@ OUT_DIR = os.path.join(V8_DIR, 'check-header-includes') AUTO_EXCLUDE = [ # flag-definitions.h needs a mode set for being included. 'src/flags/flag-definitions.h', + # recorder.h should only be included conditionally. + 'src/libplatform/tracing/recorder.h', ] AUTO_EXCLUDE_PATTERNS = [ 'src/base/atomicops_internals_.*',