Commit 205338ce authored by Sara Tang's avatar Sara Tang Committed by V8 LUCI CQ

[diagnostics] Added line numbers to ETW JIT events

Feedback suggests that it would be easier to trace minified JS code if
line numbers were included in the ETW JIT events, so I added them.

Bug: v8:11043
Change-Id: I1660c695db2e4659184b2b679839dafe256fb3ff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2971625Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Sara Tang <sartang@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#75290}
parent 4e19455b
......@@ -4360,6 +4360,8 @@ bool Shell::SetOptions(int argc, char* argv[]) {
} else if (strcmp(argv[i], "--enable-system-instrumentation") == 0) {
options.enable_system_instrumentation = true;
options.trace_enabled = true;
// This needs to be manually triggered for JIT ETW events to work.
i::FLAG_enable_system_instrumentation = true;
#if defined(V8_OS_WIN)
// Guard this bc the flag has a lot of overhead and is not currently used
// by macos
......
......@@ -4,10 +4,12 @@
#include "src/diagnostics/system-jit-win.h"
#include "src/api/api-inl.h"
#include "src/base/lazy-instance.h"
#include "src/base/logging.h"
#include "src/diagnostics/system-jit-metadata-win.h"
#include "src/libplatform/tracing/recorder.h"
#include "src/objects/shared-function-info.h"
#if !defined(V8_ENABLE_SYSTEM_INSTRUMENTATION)
#error "This file is only compiled if v8_enable_system_instrumentation"
......@@ -29,6 +31,20 @@ using ScriptMapType = std::unordered_set<int>;
static base::LazyInstance<ScriptMapType>::type script_map =
LAZY_INSTANCE_INITIALIZER;
// TODO(v8/11911): UnboundScript::GetLineNumber should be replaced
SharedFunctionInfo GetSharedFunctionInfo(const JitCodeEvent* event) {
return event->script.IsEmpty() ? SharedFunctionInfo()
: *Utils::OpenHandle(*event->script);
}
int GetScriptLineNumber(const JitCodeEvent* event) {
auto sfi = GetSharedFunctionInfo(event);
return sfi.is_null()
? -1 // invalid sentinel number
: Script::cast(sfi.script()).GetLineNumber(sfi.StartPosition()) +
1;
}
void Register() {
DCHECK(!TraceLoggingProviderEnabled(g_v8Provider, 0, 0));
TraceLoggingRegister(g_v8Provider);
......@@ -54,7 +70,7 @@ void EventHandler(const JitCodeEvent* event) {
static_cast<int>(method_name.size()));
v8::Isolate* script_context = event->isolate;
auto script = event->script;
v8::Local<v8::UnboundScript> script = event->script;
int script_id = 0;
if (!script.IsEmpty()) {
// if the first time seeing this source file, log the SourceLoad event
......@@ -62,7 +78,7 @@ void EventHandler(const JitCodeEvent* event) {
if (script_map.Pointer()->find(script_id) == script_map.Pointer()->end()) {
script_map.Pointer()->insert(script_id);
auto script_name = script->GetScriptName();
v8::Local<v8::Value> script_name = script->GetScriptName();
std::wstring wstr_name(0, L'\0');
if (script_name->IsString()) {
auto v8str_name = script_name.As<v8::String>();
......@@ -103,7 +119,8 @@ void EventHandler(const JitCodeEvent* event) {
(uint32_t)0, // MethodId
(uint16_t)0, // MethodFlags
(uint16_t)0, // MethodAddressRangeId
(uint64_t)script_id, (uint32_t)0, (uint32_t)0, // Line & Column
(uint64_t)script_id, (uint32_t)GetScriptLineNumber(event),
(uint32_t)0, // Line & Column
method_name);
}
......
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