Commit b2638151 authored by Jose Dapena Paz's avatar Jose Dapena Paz Committed by V8 LUCI CQ

[profiler][etw] Simplify method name passed to ETW.

In existing implementation, of MethodLoad event,
the method name passed to ETW is coming from
CodeEventLogger::CodeCreateEvent, and includes
the source file or URL, column and line numbers, method name
and a marker for the kind of code generation.

This is partially redundant, as the reference to source ID
will point to the already generated SourceLoad event, with
the file information. Also, Windows Performance Analyzer will
already pick line and column number for the stack representation.

So, for those cases, we just need to send to ETW the script
method name. Even better, this changeset uses the DebugNameCStr
logic to retrieve the inferred name in case there is no name
available.

Bug: v8:12987
Change-Id: If09c1fedc9da158a3c72932655e2e6b09e818d93
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3763862Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: José Dapena Paz <jdapena@igalia.com>
Cr-Commit-Position: refs/heads/main@{#82555}
parent cfe99458
......@@ -208,6 +208,35 @@ int GetScriptColumnNumber(const JitCodeEvent* event) {
1;
}
std::wstring GetScriptMethodNameFromEvent(const JitCodeEvent* event) {
int name_len = static_cast<int>(event->name.len);
// Note: event->name.str is not null terminated.
std::wstring method_name(name_len + 1, '\0');
MultiByteToWideChar(
CP_UTF8, 0, event->name.str, name_len,
// Const cast needed as building with C++14 (not const in >= C++17)
const_cast<LPWSTR>(method_name.data()),
static_cast<int>(method_name.size()));
return method_name;
}
std::wstring GetScriptMethodNameFromSharedFunctionInfo(
const SharedFunctionInfo& sfi) {
auto sfi_name = sfi.DebugNameCStr();
int method_name_length = static_cast<int>(strlen(sfi_name.get()));
std::wstring method_name(method_name_length, L'\0');
MultiByteToWideChar(CP_UTF8, 0, sfi_name.get(), method_name_length,
const_cast<LPWSTR>(method_name.data()),
static_cast<int>(method_name.length()));
return method_name;
}
std::wstring GetScriptMethodName(const JitCodeEvent* event) {
auto sfi = GetSharedFunctionInfo(event);
return sfi.is_null() ? GetScriptMethodNameFromEvent(event)
: GetScriptMethodNameFromSharedFunctionInfo(sfi);
}
void MaybeSetHandlerNow(Isolate* isolate) {
IsolateLoadScriptData::EnableLog(isolate, true);
}
......@@ -262,14 +291,7 @@ void EventHandler(const JitCodeEvent* event) {
if (event->code_type != v8::JitCodeEvent::CodeType::JIT_CODE) return;
if (event->type != v8::JitCodeEvent::EventType::CODE_ADDED) return;
int name_len = static_cast<int>(event->name.len);
// Note: event->name.str is not null terminated.
std::wstring method_name(name_len + 1, '\0');
MultiByteToWideChar(
CP_UTF8, 0, event->name.str, name_len,
// Const cast needed as building with C++14 (not const in >= C++17)
const_cast<LPWSTR>(method_name.data()),
static_cast<int>(method_name.size()));
std::wstring method_name = GetScriptMethodName(event);
v8::Isolate* script_context = event->isolate;
v8::Local<v8::UnboundScript> script = event->script;
......
......@@ -904,7 +904,7 @@ bool SharedFunctionInfo::HasInferredName() {
return HasUncompiledData();
}
String SharedFunctionInfo::inferred_name() {
String SharedFunctionInfo::inferred_name() const {
Object maybe_scope_info = name_or_scope_info(kAcquireLoad);
if (maybe_scope_info.IsScopeInfo()) {
ScopeInfo scope_info = ScopeInfo::cast(maybe_scope_info);
......
......@@ -294,7 +294,7 @@ CoverageInfo SharedFunctionInfo::GetCoverageInfo() const {
return CoverageInfo::cast(GetDebugInfo().coverage_info());
}
std::unique_ptr<char[]> SharedFunctionInfo::DebugNameCStr() {
std::unique_ptr<char[]> SharedFunctionInfo::DebugNameCStr() const {
#if V8_ENABLE_WEBASSEMBLY
if (HasWasmExportedFunctionData()) {
return WasmExportedFunction::GetDebugName(
......
......@@ -385,7 +385,7 @@ class SharedFunctionInfo
// code written in OO style, where almost all functions are anonymous but are
// assigned to object properties.
inline bool HasInferredName();
inline String inferred_name();
inline String inferred_name() const;
// Break infos are contained in DebugInfo, this is a convenience method
// to simplify access.
......@@ -398,7 +398,7 @@ class SharedFunctionInfo
CoverageInfo GetCoverageInfo() const;
// The function's name if it is non-empty, otherwise the inferred name.
std::unique_ptr<char[]> DebugNameCStr();
std::unique_ptr<char[]> DebugNameCStr() const;
static Handle<String> DebugName(Handle<SharedFunctionInfo>);
// Used for flags such as --turbo-filter.
......
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