Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { setSegmentationRulesFromJson } from "./hybrid-globalization/grapheme-se

// this need to be run only after onRuntimeInitialized event, when the memory is ready
export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8Array): void {
mono_log_debug(`Loaded:${asset.name} as ${asset.behavior} size ${bytes.length} from ${url}`);
mono_log_debug(() => `Loaded:${asset.name} as ${asset.behavior} size ${bytes.length} from ${url}`);
const mark = startMeasure();

const virtualName: string = typeof (asset.virtualPath) === "string"
Expand Down Expand Up @@ -64,7 +64,7 @@ export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8A
parentDirectory = "/";
}

mono_log_debug(`Creating file '${fileName}' in directory '${parentDirectory}'`);
mono_log_debug(() => `Creating file '${fileName}' in directory '${parentDirectory}'`);

Module.FS_createDataFile(
parentDirectory, fileName,
Expand Down
20 changes: 10 additions & 10 deletions src/mono/browser/runtime/diagnostics/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function mock (script: MockScript): Mock {
class MockScriptEngineSocketImpl implements MockRemoteSocket {
constructor (private readonly engine: MockScriptEngineImpl) { }
send (data: string | ArrayBuffer): void {
mono_log_debug(`mock ${this.engine.ident} client sent: `, data);
mono_log_debug(() => `mock ${this.engine.ident} client sent: ${data}`);
let event: MessageEvent<string | ArrayBuffer> | null = null;
if (typeof data === "string") {
event = new MessageEvent("message", { data });
Expand All @@ -46,15 +46,15 @@ export function mock (script: MockScript): Mock {
}
addEventListener<T extends keyof WebSocketEventMap>(event: T, listener: (event: WebSocketEventMap[T]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener (event: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {
mono_log_debug(`mock ${this.engine.ident} client added listener for ${event}`);
mono_log_debug(() => `mock ${this.engine.ident} client added listener for ${event}`);
this.engine.eventTarget.addEventListener(event, listener, options);
}
removeEventListener (event: string, listener: EventListenerOrEventListenerObject): void {
mono_log_debug(`mock ${this.engine.ident} client removed listener for ${event}`);
mono_log_debug(() => `mock ${this.engine.ident} client removed listener for ${event}`);
this.engine.eventTarget.removeEventListener(event, listener);
}
close (): void {
mono_log_debug(`mock ${this.engine.ident} client closed`);
mono_log_debug(() => `mock ${this.engine.ident} client closed`);
this.engine.mockReplyEventTarget.dispatchEvent(new CloseEvent("close"));
}
dispatchEvent (ev: Event): boolean {
Expand All @@ -73,7 +73,7 @@ export function mock (script: MockScript): Mock {
}

reply (data: ArrayBuffer | Uint8Array) {
mono_log_debug(`mock ${this.ident} reply:`, data);
mono_log_debug(() => `mock ${this.ident} reply:${data}`);
let sendData: ArrayBuffer;
if (typeof data === "object" && data instanceof ArrayBuffer) {
sendData = new ArrayBuffer(data.byteLength);
Expand All @@ -92,7 +92,7 @@ export function mock (script: MockScript): Mock {
}

processSend (onMessage: (data: ArrayBuffer) => any): Promise<void> {
mono_log_debug(`mock ${this.ident} processSend`);
mono_log_debug(() => `mock ${this.ident} processSend`);

return new Promise<void>((resolve, reject) => {
this.mockReplyEventTarget.addEventListener("close", () => {
Expand All @@ -105,15 +105,15 @@ export function mock (script: MockScript): Mock {
reject(new Error("mock script connection received string data"));
}

mono_log_debug(`mock ${this.ident} processSend got:`, data.byteLength);
mono_log_debug(() => `mock ${this.ident} processSend got: ${data.byteLength}`);

onMessage(data);
});
});
}

async waitForSend<T = void> (filter: (data: ArrayBuffer) => boolean, extract?: (data: ArrayBuffer) => T): Promise<T> {
mono_log_debug(`mock ${this.ident} waitForSend`);
mono_log_debug(() => `mock ${this.ident} waitForSend`);

const data = await new Promise<ArrayBuffer>((resolve) => {
this.mockReplyEventTarget.addEventListener("message", (event: any) => {
Expand All @@ -122,7 +122,7 @@ export function mock (script: MockScript): Mock {
mono_log_warn(`mock ${this.ident} waitForSend got string:`, data);
throw new Error("mock script connection received string data");
}
mono_log_debug(`mock ${this.ident} waitForSend got:`, data.byteLength);
mono_log_debug(() => `mock ${this.ident} waitForSend got:${data.byteLength}`);

resolve(data);
}, { once: true });
Expand Down Expand Up @@ -153,7 +153,7 @@ export function mock (script: MockScript): Mock {
}
open (): MockRemoteSocket {
const i = this.openCount++;
mono_log_debug(`mock ${i} open`);
mono_log_debug(() => `mock ${i} open`);
return this.engines[i].socket;
}

Expand Down
14 changes: 7 additions & 7 deletions src/mono/browser/runtime/diagnostics/server_pthread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ class DiagnosticServerImpl implements DiagnosticServer {
async advertiseAndWaitForClient (): Promise<void> {
try {
const connNum = this.openCount++;
mono_log_debug("opening websocket and sending ADVR_V1", connNum);
mono_log_debug(() => `opening websocket and sending ADVR_V1 ${connNum}`);
const ws = await this.openSocket();
const p = addOneShotProtocolCommandEventListener(createProtocolSocket(ws));
this.sendAdvertise(ws);
const message = await p;
mono_log_debug("received advertising response: ", message, connNum);
mono_log_debug(() => `received advertising response: ${message},${connNum}`);
queueMicrotask(() => this.parseAndDispatchMessage(ws, connNum, message));
} finally {
// if there were errors, resume the runtime anyway
Expand Down Expand Up @@ -183,9 +183,9 @@ class DiagnosticServerImpl implements DiagnosticServer {
}

parseCommand (message: ProtocolCommandEvent, connNum: number): ProtocolClientCommandBase | null {
mono_log_debug("parsing byte command: ", message.data, connNum);
mono_log_debug(() => `parsing byte command: ${message.data}, ${connNum}`);
const result = parseProtocolCommand(message.data);
mono_log_debug("parsed byte command: ", result, connNum);
mono_log_debug(() => `parsed byte command: ${result} ${connNum}`);
if (result.success) {
return result.result;
} else {
Expand Down Expand Up @@ -236,7 +236,7 @@ class DiagnosticServerImpl implements DiagnosticServer {
}

async stopEventPipe (ws: WebSocket | MockRemoteSocket, sessionID: EventPipeSessionIDImpl): Promise<void> {
mono_log_debug("stopEventPipe", sessionID);
mono_log_debug(() => `stopEventPipe ${sessionID}`);
cwraps.mono_wasm_event_pipe_session_disable(sessionID);
// we might send OK before the session is actually stopped since the websocket is async
// but the client end should be robust to that.
Expand All @@ -252,7 +252,7 @@ class DiagnosticServerImpl implements DiagnosticServer {
sessionIDbuf[3] = (session.sessionID >> 24) & 0xFF;
// sessionIDbuf[4..7] is 0 because all our session IDs are 32-bit
this.postClientReplyOK(ws, sessionIDbuf);
mono_log_debug("created session, now streaming: ", session);
mono_log_debug(() => `created session, now streaming: ${session}`);
cwraps.mono_wasm_event_pipe_session_start_streaming(session.sessionID);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ function parseProtocolCommand (data: ArrayBuffer | BinaryProtocolCommand): Parse
export function mono_wasm_diagnostic_server_on_server_thread_created (websocketUrlPtr: CharPtr): void {
mono_assert(WasmEnableThreads, "The diagnostic server requires threads to be enabled during build time.");
const websocketUrl = utf8ToString(websocketUrlPtr);
mono_log_debug(`mono_wasm_diagnostic_server_on_server_thread_created, url ${websocketUrl}`);
mono_log_debug(() => `mono_wasm_diagnostic_server_on_server_thread_created, url ${websocketUrl}`);
let mock: PromiseAndController<Mock> | undefined = undefined;
if (monoDiagnosticsMock && websocketUrl.startsWith("mock:")) {
mock = createPromiseController<Mock>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class StatefulParser {
result = this.tryAppendBuffer(new Uint8Array(buf));
}
if (result.success) {
mono_log_debug("protocol-socket: got result", result);
mono_log_debug(() => `protocol-socket: got result ${result}`);
this.setState(result.newState);
if (result.command) {
const command = result.command;
Expand Down Expand Up @@ -177,14 +177,14 @@ class ProtocolSocketImpl implements ProtocolSocket {

onMessage (this: ProtocolSocketImpl, ev: MessageEvent<ArrayBuffer | Blob | string>): void {
const data = ev.data;
mono_log_debug("protocol socket received message", ev.data);
mono_log_debug(() => `protocol socket received message ${ev.data}`);
if (typeof data === "object" && data instanceof ArrayBuffer) {
this.onArrayBuffer(data);
} else if (typeof data === "object" && data instanceof Blob) {
data.arrayBuffer().then(this.onArrayBuffer.bind(this));
} else if (typeof data === "string") {
// otherwise it's string, ignore it.
mono_log_debug("protocol socket received string message; ignoring it", ev.data);
mono_log_debug(() => `protocol socket received string message; ignoring it ${ev.data}`);
} else {
assertNever(data);
}
Expand All @@ -195,15 +195,15 @@ class ProtocolSocketImpl implements ProtocolSocket {
}

onArrayBuffer (this: ProtocolSocketImpl, buf: ArrayBuffer) {
mono_log_debug("protocol-socket: parsing array buffer", buf);
mono_log_debug(() => `protocol-socket: parsing array buffer ${buf}`);
this.statefulParser.receiveBuffer(buf);
}

// called by the stateful parser when it has a complete command
emitCommandCallback (this: this, command: BinaryProtocolCommand): void {
mono_log_debug("protocol-socket: queueing command", command);
mono_log_debug(() => `protocol-socket: queueing command ${command}`);
queueMicrotask(() => {
mono_log_debug("dispatching protocol event with command", command);
mono_log_debug(() => `dispatching protocol event with command ${command}`);
this.dispatchProtocolCommandEvent(command);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class EventPipeSocketConnection {
}

private _onError (event: Event) {
mono_log_debug("EventPipe session stream websocket error", event);
mono_log_debug(() => `EventPipe session stream websocket error ${event}`);
this._state = ListenerState.Error;
this.stream.close();
// TODO: notify runtime that connection had an error
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/invoke-cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { mono_log_debug } from "./logging";
export function mono_wasm_bind_cs_function (method: MonoMethod, assemblyName: string, namespaceName: string, shortClassName: string, methodName: string, signatureHash: number, signature: JSFunctionSignature): void {
const fullyQualifiedName = `[${assemblyName}] ${namespaceName}.${shortClassName}:${methodName}`;
const mark = startMeasure();
mono_log_debug(`Binding [JSExport] ${namespaceName}.${shortClassName}:${methodName} from ${assemblyName} assembly`);
mono_log_debug(() => `Binding [JSExport] ${namespaceName}.${shortClassName}:${methodName} from ${assemblyName} assembly`);
const version = get_signature_version(signature);
mono_assert(version === 2, () => `Signature version ${version} mismatch.`);

Expand Down
8 changes: 4 additions & 4 deletions src/mono/browser/runtime/invoke-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function bind_js_import (signature: JSFunctionSignature): Function {
const js_module_name = get_signature_module_name(signature)!;
const function_handle = get_signature_handle(signature);

mono_log_debug(`Binding [JSImport] ${js_function_name} from ${js_module_name} module`);
mono_log_debug(() => `Binding [JSImport] ${js_function_name} from ${js_module_name} module`);

const fn = mono_wasm_lookup_js_import(js_function_name, js_module_name);
const args_count = get_signature_argument_count(signature);
Expand Down Expand Up @@ -369,7 +369,7 @@ export function mono_wasm_invoke_js_function_impl (bound_function_js_handle: JSH

export function mono_wasm_set_module_imports (module_name: string, moduleImports: any) {
importedModules.set(module_name, moduleImports);
mono_log_debug(`added module imports '${module_name}'`);
mono_log_debug(() => `added module imports '${module_name}'`);
}

function mono_wasm_lookup_js_import (function_name: string, js_module_name: string | null): Function {
Expand Down Expand Up @@ -446,7 +446,7 @@ export function dynamic_import (module_name: string, module_url: string): Promis
let promise = importedModulesPromises.get(module_name);
const newPromise = !promise;
if (newPromise) {
mono_log_debug(`importing ES6 module '${module_name}' from '${module_url}'`);
mono_log_debug(() => `importing ES6 module '${module_name}' from '${module_url}'`);
promise = import(/*! webpackIgnore: true */module_url);
importedModulesPromises.set(module_name, promise);
}
Expand All @@ -455,7 +455,7 @@ export function dynamic_import (module_name: string, module_url: string): Promis
const module = await promise;
if (newPromise) {
importedModules.set(module_name, module);
mono_log_debug(`imported ES6 module '${module_name}' from '${module_url}'`);
mono_log_debug(() => `imported ES6 module '${module_name}' from '${module_url}'`);
}
return module;
});
Expand Down
8 changes: 4 additions & 4 deletions src/mono/browser/runtime/loader/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,14 @@ export async function start_asset_download (asset: AssetEntryInternal): Promise<
// second attempt only after all first attempts are queued
await loaderHelpers.allDownloadsQueued.promise;
try {
mono_log_debug(`Retrying download '${asset.name}'`);
mono_log_debug(() => `Retrying download '${asset.name}'`);
return await start_asset_download_with_throttle(asset);
} catch (err) {
asset.pendingDownloadInternal = undefined;
// third attempt after small delay
await delay(100);

mono_log_debug(`Retrying download (2) '${asset.name}' after delay`);
mono_log_debug(() => `Retrying download (2) '${asset.name}' after delay`);
return await start_asset_download_with_throttle(asset);
}
}
Expand Down Expand Up @@ -577,9 +577,9 @@ async function start_asset_download_sources (asset: AssetEntryInternal): Promise

const attemptUrl = resolve_path(asset, sourcePrefix);
if (asset.name === attemptUrl) {
mono_log_debug(`Attempting to download '${attemptUrl}'`);
mono_log_debug(() => `Attempting to download '${attemptUrl}'`);
} else {
mono_log_debug(`Attempting to download '${attemptUrl}' for ${asset.name}`);
mono_log_debug(() => `Attempting to download '${attemptUrl}' for ${asset.name}`);
}
try {
asset.resolvedUrl = attemptUrl;
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/loader/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function mono_exit (exit_code: number, reason?: any): void {
unregisterEmscriptenExitHandlers();
uninstallUnhandledErrorHandler();
if (!runtimeHelpers.runtimeReady) {
mono_log_debug("abort_startup, reason: " + reason);
mono_log_debug(() => `abort_startup, reason: ${reason}`);
abort_promises(reason);
} else {
if (runtimeHelpers.jiterpreter_dump_stats) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/loader/libraryInitializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function importLibraryInitializers (libraryInitializers: ResourceLi
async function importInitializer (path: string): Promise<void> {
try {
const adjustedPath = appendUniqueQuery(loaderHelpers.locateFile(path), "js-module-library-initializer");
mono_log_debug(`Attempting to import '${adjustedPath}' for ${path}`);
mono_log_debug(() => `Attempting to import '${adjustedPath}' for ${path}`);
const initializer = await import(/*! webpackIgnore: true */ adjustedPath);

loaderHelpers.libraryInitializers!.push({ scriptName: path, exports: initializer });
Expand Down
7 changes: 5 additions & 2 deletions src/mono/browser/runtime/loader/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export function set_thread_prefix (threadPrefix: string) {
threadNamePrefix = threadPrefix;
}

export function mono_log_debug (msg: string, ...data: any[]) {
export function mono_log_debug (messageFactory: string | (() => string)) {
if (loaderHelpers.diagnosticTracing) {
console.debug(prefix + msg, ...data);
const message = (typeof messageFactory === "function"
? messageFactory()
: messageFactory);
console.debug(prefix + message);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/loader/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,14 @@ function importModules () {
if (typeof jsModuleRuntimeAsset.moduleExports === "object") {
jsModuleRuntimePromise = jsModuleRuntimeAsset.moduleExports;
} else {
mono_log_debug(`Attempting to import '${jsModuleRuntimeAsset.resolvedUrl}' for ${jsModuleRuntimeAsset.name}`);
mono_log_debug(() => `Attempting to import '${jsModuleRuntimeAsset.resolvedUrl}' for ${jsModuleRuntimeAsset.name}`);
jsModuleRuntimePromise = import(/*! webpackIgnore: true */jsModuleRuntimeAsset.resolvedUrl!);
}

if (typeof jsModuleNativeAsset.moduleExports === "object") {
jsModuleNativePromise = jsModuleNativeAsset.moduleExports;
} else {
mono_log_debug(`Attempting to import '${jsModuleNativeAsset.resolvedUrl}' for ${jsModuleNativeAsset.name}`);
mono_log_debug(() => `Attempting to import '${jsModuleNativeAsset.resolvedUrl}' for ${jsModuleNativeAsset.name}`);
jsModuleNativePromise = import(/*! webpackIgnore: true */jsModuleNativeAsset.resolvedUrl!);
}

Expand Down
Loading