Commit e5b4a5ed authored by Sara Tang's avatar Sara Tang Committed by Commit Bot

[diagnostics] system instrumentation for MacOS

This CL implements the equivalent of ETW in macos (called Signposts)

Bug: v8:11043
Change-Id: Ifa72cfd17fca81b18e3e8b1003fd6ab72de3c986
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2807157
Commit-Queue: Sara Tang <sartang@microsoft.com>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73856}
parent 533cc512
......@@ -4771,6 +4771,9 @@ v8_component("v8_libplatform") {
} 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" ]
}
}
......
......@@ -4069,12 +4069,18 @@ bool Shell::SetOptions(int argc, char* argv[]) {
} else if (strcmp(argv[i], "--fuzzy-module-file-extensions") == 0) {
options.fuzzy_module_file_extensions = true;
argv[i] = nullptr;
#if defined(V8_OS_WIN) && defined(V8_ENABLE_SYSTEM_INSTRUMENTATION)
#if defined(V8_ENABLE_SYSTEM_INSTRUMENTATION)
#if defined(V8_OS_WIN) || defined(V8_OS_MACOSX)
} else if (strcmp(argv[i], "--enable-system-instrumentation") == 0) {
options.enable_system_instrumentation = true;
options.trace_enabled = true;
#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
}
}
......
// 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_MAC_H_
#define V8_LIBPLATFORM_TRACING_RECORDER_MAC_H_
#include "src/libplatform/tracing/recorder.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
namespace v8 {
namespace platform {
namespace tracing {
Recorder::Recorder() { v8Provider = os_log_create("v8", ""); }
Recorder::~Recorder() {}
bool Recorder::IsEnabled() {
return os_log_type_enabled(v8Provider, OS_LOG_TYPE_DEFAULT);
}
bool Recorder::IsEnabled(const uint8_t level) {
if (level == OS_LOG_TYPE_DEFAULT || level == OS_LOG_TYPE_INFO ||
level == OS_LOG_TYPE_DEBUG || level == OS_LOG_TYPE_ERROR ||
level == OS_LOG_TYPE_FAULT) {
return os_log_type_enabled(v8Provider, static_cast<os_log_type_t>(level));
}
return false;
}
void Recorder::AddEvent(TraceObject* trace_event) {
os_signpost_event_emit(v8Provider, OS_SIGNPOST_ID_EXCLUSIVE, "",
"%s, cpu_duration: %d", trace_event->name(),
static_cast<int>(trace_event->cpu_duration()));
}
} // namespace tracing
} // namespace platform
} // namespace v8
#pragma clang diagnostic pop
#endif // V8_LIBPLATFORM_TRACING_RECORDER_MAC_H_
......@@ -9,7 +9,19 @@
#include "include/libplatform/v8-tracing.h"
#ifdef V8_TARGET_OS_MACOSX
#if !defined(V8_ENABLE_SYSTEM_INSTRUMENTATION)
#error V8_ENABLE_SYSTEM_INSTRUMENTATION is not defined
#endif
#include <os/signpost.h>
#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
......@@ -31,14 +43,23 @@ class V8_PLATFORM_EXPORT Recorder {
Recorder();
~Recorder();
static bool IsEnabled();
static bool IsEnabled(const uint8_t level);
bool IsEnabled();
bool IsEnabled(const uint8_t level);
void AddEvent(TraceObject* trace_event);
private:
#ifdef V8_TARGET_OS_MACOSX
os_log_t v8Provider;
#endif
};
} // namespace tracing
} // namespace platform
} // namespace v8
#ifdef V8_TARGET_OS_MACOSX
#pragma clang diagnostic pop
#endif
#endif // V8_LIBPLATFORM_TRACING_RECORDER_H_
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