Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Defer parsing of wasm stack symbolication maps #99974

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/mono/browser/runtime/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

/* eslint-disable no-console */
import { INTERNAL, runtimeHelpers } from "./globals";
import { INTERNAL, runtimeHelpers, mono_assert } from "./globals";
import { utf8ToString } from "./strings";
import { CharPtr, VoidPtr } from "./types/emscripten";

Expand Down Expand Up @@ -35,6 +35,7 @@ export function mono_log_error(msg: string, ...data: any) {
}

export const wasm_func_map = new Map<number, string>();
let wasm_pending_symbol_table : string | undefined;
const regexes: any[] = [];

// V8
Expand All @@ -54,6 +55,8 @@ regexes.push(/(?<replaceSection><[^ >]+>[.:]wasm-function\[(?<funcNum>[0-9]+)\])

export function mono_wasm_symbolicate_string(message: string): string {
try {
performDeferredSymbolMapParsing();

if (wasm_func_map.size == 0)
return message;

Expand Down Expand Up @@ -143,22 +146,40 @@ export function mono_wasm_trace_logger(log_domain_ptr: CharPtr, log_level_ptr: C


export function parseSymbolMapFile(text: string) {
text.split(/[\r\n]/).forEach((line: string) => {
const parts: string[] = line.split(/:/);
if (parts.length < 2)
return;
// Symbol map parsing is very expensive, so doing it during startup is wasteful
// instead, we defer it until the first time the symbol map is needed - which
// may be never
mono_assert(!wasm_pending_symbol_table, "Another symbol map was already loaded");
wasm_pending_symbol_table = text;
mono_log_debug(`Deferred loading of ${text.length}ch symbol map`);
}

parts[1] = parts.splice(1).join(":");
wasm_func_map.set(Number(parts[0]), parts[1]);
});
function performDeferredSymbolMapParsing() {
if (!wasm_pending_symbol_table)
return;

mono_log_debug(`Loaded ${wasm_func_map.size} symbols`);
const text = wasm_pending_symbol_table!;
wasm_pending_symbol_table = undefined;
try {
text.split(/[\r\n]/).forEach((line: string) => {
const parts: string[] = line.split(/:/);
if (parts.length < 2)
return;

parts[1] = parts.splice(1).join(":");
wasm_func_map.set(Number(parts[0]), parts[1]);
});
mono_log_debug(`Loaded ${wasm_func_map.size} symbols`);
} catch (exc) {
mono_log_warn(`Failed to load symbol map: ${exc}`);
}
}

export function mono_wasm_get_func_id_to_name_mappings() {
performDeferredSymbolMapParsing();
return [...wasm_func_map.values()];
}

export function mono_wasm_console_clear() {
console.clear();
}
}
Loading