From c43aa974a4b7181d356f1b4a8a1f1e1fec9fba9d Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 14 May 2024 11:35:40 +0200 Subject: [PATCH 1/2] wip --- src/mono/browser/runtime/assets.ts | 6 ++--- .../browser/runtime/diagnostics/mock/index.ts | 20 ++++++++--------- .../diagnostics/server_pthread/index.ts | 14 ++++++------ .../server_pthread/protocol-socket.ts | 12 +++++----- .../server_pthread/socket-connection.ts | 2 +- src/mono/browser/runtime/invoke-cs.ts | 2 +- src/mono/browser/runtime/invoke-js.ts | 8 +++---- src/mono/browser/runtime/loader/assets.ts | 8 +++---- src/mono/browser/runtime/loader/exit.ts | 2 +- .../runtime/loader/libraryInitializers.ts | 2 +- src/mono/browser/runtime/loader/logging.ts | 11 ++++++++-- src/mono/browser/runtime/loader/run.ts | 4 ++-- src/mono/browser/runtime/logging.ts | 16 ++++++++++---- .../browser/runtime/pthreads/ui-thread.ts | 4 ++-- .../browser/runtime/pthreads/worker-thread.ts | 2 +- src/mono/browser/runtime/rollup.config.js | 22 ++++++++++++++++--- 16 files changed, 83 insertions(+), 52 deletions(-) diff --git a/src/mono/browser/runtime/assets.ts b/src/mono/browser/runtime/assets.ts index 5c3f7ecce88221..b445486da8a5cf 100644 --- a/src/mono/browser/runtime/assets.ts +++ b/src/mono/browser/runtime/assets.ts @@ -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" @@ -52,7 +52,7 @@ export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8A if (fileName.startsWith("/")) fileName = fileName.substring(1); if (parentDirectory) { - mono_log_debug(`Creating directory '${parentDirectory}'`); + mono_log_debug(() => `Creating directory '${parentDirectory}'`); Module.FS_createPath( "/", parentDirectory, true, true // fixme: should canWrite be false? @@ -61,7 +61,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, diff --git a/src/mono/browser/runtime/diagnostics/mock/index.ts b/src/mono/browser/runtime/diagnostics/mock/index.ts index d320980e454da4..3d1014d02c126f 100644 --- a/src/mono/browser/runtime/diagnostics/mock/index.ts +++ b/src/mono/browser/runtime/diagnostics/mock/index.ts @@ -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 | null = null; if (typeof data === "string") { event = new MessageEvent("message", { data }); @@ -46,15 +46,15 @@ export function mock (script: MockScript): Mock { } addEventListener(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 { @@ -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); @@ -92,7 +92,7 @@ export function mock (script: MockScript): Mock { } processSend (onMessage: (data: ArrayBuffer) => any): Promise { - mono_log_debug(`mock ${this.ident} processSend`); + mono_log_debug(() => `mock ${this.ident} processSend`); return new Promise((resolve, reject) => { this.mockReplyEventTarget.addEventListener("close", () => { @@ -105,7 +105,7 @@ 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); }); @@ -113,7 +113,7 @@ export function mock (script: MockScript): Mock { } async waitForSend (filter: (data: ArrayBuffer) => boolean, extract?: (data: ArrayBuffer) => T): Promise { - mono_log_debug(`mock ${this.ident} waitForSend`); + mono_log_debug(() => `mock ${this.ident} waitForSend`); const data = await new Promise((resolve) => { this.mockReplyEventTarget.addEventListener("message", (event: any) => { @@ -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 }); @@ -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; } diff --git a/src/mono/browser/runtime/diagnostics/server_pthread/index.ts b/src/mono/browser/runtime/diagnostics/server_pthread/index.ts index cbc94347a7d20e..1175aeb2d8c52a 100644 --- a/src/mono/browser/runtime/diagnostics/server_pthread/index.ts +++ b/src/mono/browser/runtime/diagnostics/server_pthread/index.ts @@ -139,12 +139,12 @@ class DiagnosticServerImpl implements DiagnosticServer { async advertiseAndWaitForClient (): Promise { 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 @@ -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 { @@ -236,7 +236,7 @@ class DiagnosticServerImpl implements DiagnosticServer { } async stopEventPipe (ws: WebSocket | MockRemoteSocket, sessionID: EventPipeSessionIDImpl): Promise { - 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. @@ -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); } @@ -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 | undefined = undefined; if (monoDiagnosticsMock && websocketUrl.startsWith("mock:")) { mock = createPromiseController(); diff --git a/src/mono/browser/runtime/diagnostics/server_pthread/protocol-socket.ts b/src/mono/browser/runtime/diagnostics/server_pthread/protocol-socket.ts index 049d1525cd32bd..9b6cea2bc060d6 100644 --- a/src/mono/browser/runtime/diagnostics/server_pthread/protocol-socket.ts +++ b/src/mono/browser/runtime/diagnostics/server_pthread/protocol-socket.ts @@ -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; @@ -177,14 +177,14 @@ class ProtocolSocketImpl implements ProtocolSocket { onMessage (this: ProtocolSocketImpl, ev: MessageEvent): 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); } @@ -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); }); } diff --git a/src/mono/browser/runtime/diagnostics/server_pthread/socket-connection.ts b/src/mono/browser/runtime/diagnostics/server_pthread/socket-connection.ts index fec4a1fc32aabd..bdecd140999c86 100644 --- a/src/mono/browser/runtime/diagnostics/server_pthread/socket-connection.ts +++ b/src/mono/browser/runtime/diagnostics/server_pthread/socket-connection.ts @@ -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 diff --git a/src/mono/browser/runtime/invoke-cs.ts b/src/mono/browser/runtime/invoke-cs.ts index f613df56687d4b..3b7a869e8661c3 100644 --- a/src/mono/browser/runtime/invoke-cs.ts +++ b/src/mono/browser/runtime/invoke-cs.ts @@ -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.`); diff --git a/src/mono/browser/runtime/invoke-js.ts b/src/mono/browser/runtime/invoke-js.ts index c5d385a17e4e44..191bd8a0fc2934 100644 --- a/src/mono/browser/runtime/invoke-js.ts +++ b/src/mono/browser/runtime/invoke-js.ts @@ -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); @@ -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 { @@ -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); } @@ -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; }); diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index ad9d3650791e48..e23e4197252b36 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -417,14 +417,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); } } @@ -505,9 +505,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; diff --git a/src/mono/browser/runtime/loader/exit.ts b/src/mono/browser/runtime/loader/exit.ts index ecb2b46bb1f1f8..3632969487868b 100644 --- a/src/mono/browser/runtime/loader/exit.ts +++ b/src/mono/browser/runtime/loader/exit.ts @@ -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) { diff --git a/src/mono/browser/runtime/loader/libraryInitializers.ts b/src/mono/browser/runtime/loader/libraryInitializers.ts index a8a16c543dbccf..4dd0ccfed9ff25 100644 --- a/src/mono/browser/runtime/loader/libraryInitializers.ts +++ b/src/mono/browser/runtime/loader/libraryInitializers.ts @@ -18,7 +18,7 @@ export async function importLibraryInitializers (libraryInitializers: ResourceLi async function importInitializer (path: string): Promise { 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 }); diff --git a/src/mono/browser/runtime/loader/logging.ts b/src/mono/browser/runtime/loader/logging.ts index ce98616e08d0ee..2cc94df15279f0 100644 --- a/src/mono/browser/runtime/loader/logging.ts +++ b/src/mono/browser/runtime/loader/logging.ts @@ -18,12 +18,19 @@ 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); + mono_always_log_debug( message); } } +export function mono_always_log_debug (msg: string) { + console.debug(prefix + msg); +} + export function mono_log_info (msg: string, ...data: any) { console.info(prefix + msg, ...data); } diff --git a/src/mono/browser/runtime/loader/run.ts b/src/mono/browser/runtime/loader/run.ts index 0bd2dd60d80852..663c7b930f68b9 100644 --- a/src/mono/browser/runtime/loader/run.ts +++ b/src/mono/browser/runtime/loader/run.ts @@ -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!); } diff --git a/src/mono/browser/runtime/logging.ts b/src/mono/browser/runtime/logging.ts index f6928320efba7b..1076b70893d288 100644 --- a/src/mono/browser/runtime/logging.ts +++ b/src/mono/browser/runtime/logging.ts @@ -15,12 +15,20 @@ export function set_thread_prefix (threadPrefix: string) { } /* eslint-disable no-console */ -export function mono_log_debug (msg: string, ...data: any) { + +export function mono_log_debug (messageFactory: string | (() => string)) { if (runtimeHelpers.diagnosticTracing) { - console.debug(prefix + msg, ...data); + const message = (typeof messageFactory === "function" + ? messageFactory() + : messageFactory); + mono_always_log_debug( message); } } +export function mono_always_log_debug (msg: string) { + console.debug(prefix + msg); +} + export function mono_log_info (msg: string, ...data: any) { console.info(prefix + msg, ...data); } @@ -164,7 +172,7 @@ export function parseSymbolMapFile (text: string) { // 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`); + mono_log_debug(() => `Deferred loading of ${text.length}ch symbol map`); } function performDeferredSymbolMapParsing () { @@ -197,7 +205,7 @@ function performDeferredSymbolMapParsing () { parts[1] = parts.splice(1).join(":"); wasm_func_map.set(Number(parts[0]), parts[1]); }); - mono_log_debug(`Loaded ${wasm_func_map.size} symbols`); + mono_log_debug(() => `Loaded ${wasm_func_map.size} symbols`); } catch (exc) { mono_log_warn(`Failed to load symbol map: ${exc}`); } diff --git a/src/mono/browser/runtime/pthreads/ui-thread.ts b/src/mono/browser/runtime/pthreads/ui-thread.ts index 0dc2b80c57e0f8..2e95fa9b5a5e9b 100644 --- a/src/mono/browser/runtime/pthreads/ui-thread.ts +++ b/src/mono/browser/runtime/pthreads/ui-thread.ts @@ -254,7 +254,7 @@ function getNewWorker (modulePThread: PThreadLibrary): PThreadWorker { if (!WasmEnableThreads) return null as any; if (modulePThread.unusedWorkers.length == 0) { - mono_log_debug(`Failed to find unused WebWorker, this may deadlock. Please increase the pthreadPoolInitialSize. Running threads ${modulePThread.runningWorkers.length}. Loading workers: ${modulePThread.unusedWorkers.length}`); + mono_log_debug(() => `Failed to find unused WebWorker, this may deadlock. Please increase the pthreadPoolInitialSize. Running threads ${modulePThread.runningWorkers.length}. Loading workers: ${modulePThread.unusedWorkers.length}`); const worker = allocateUnusedWorker(); modulePThread.loadWasmModuleToWorker(worker); return worker; @@ -273,7 +273,7 @@ function getNewWorker (modulePThread: PThreadLibrary): PThreadWorker { return worker; } } - mono_log_debug(`Failed to find loaded WebWorker, this may deadlock. Please increase the pthreadPoolInitialSize. Running threads ${modulePThread.runningWorkers.length}. Loading workers: ${modulePThread.unusedWorkers.length}`); + mono_log_debug(() => `Failed to find loaded WebWorker, this may deadlock. Please increase the pthreadPoolInitialSize. Running threads ${modulePThread.runningWorkers.length}. Loading workers: ${modulePThread.unusedWorkers.length}`); return modulePThread.unusedWorkers.pop()!; } diff --git a/src/mono/browser/runtime/pthreads/worker-thread.ts b/src/mono/browser/runtime/pthreads/worker-thread.ts index fa1269c300cb6f..75b249812d338f 100644 --- a/src/mono/browser/runtime/pthreads/worker-thread.ts +++ b/src/mono/browser/runtime/pthreads/worker-thread.ts @@ -65,7 +65,7 @@ export function initWorkerThreadEvents () { // this is the message handler for the worker that receives messages from the main thread // extend this with new cases as needed function monoDedicatedChannelMessageFromMainToWorker (event: MessageEvent): void { - mono_log_debug("got message from main on the dedicated channel", event.data); + mono_log_debug(() => `got message from main on the dedicated channel ${event.data}`); } export function on_emscripten_thread_init (pthread_ptr: PThreadPtr) { diff --git a/src/mono/browser/runtime/rollup.config.js b/src/mono/browser/runtime/rollup.config.js index 2588ad79d9ea19..86245ef5bf4e00 100644 --- a/src/mono/browser/runtime/rollup.config.js +++ b/src/mono/browser/runtime/rollup.config.js @@ -68,13 +68,29 @@ const inlineAssert = [ // eslint-disable-next-line quotes pattern: 'mono_assert\\(([^,]*), \\(\\) => *`([^`]*)`\\);', replacement: (match) => `if (!(${match[1]})) mono_assert(false, \`${match[2]}\`); // inlined mono_assert condition` - } + }, + { + // eslint-disable-next-line quotes + pattern: 'mono_log_debug\\(*"([^"]*)"\\);', + // eslint-disable-next-line quotes + replacement: (match) => `if (loaderHelpers.diagnosticTracing) mono_always_log_debug("${match[2]}"); // inlined mono_log_debug condition` + }, + { + // eslint-disable-next-line quotes + pattern: 'mono_log_debug\\(\\(\\) => *`([^`]*)`\\);', + replacement: (match) => `if (loaderHelpers.diagnosticTracing) mono_always_log_debug(\`${match[1]}\`); // inlined mono_log_debug condition` + }, ]; const checkAssert = { pattern: /^\s*mono_check/gm, failure: "previous regexp didn't inline all mono_check statements" }; +const checkDebugLog = +{ + pattern: /^\s*mono_log_debug/gm, + failure: "previous regexp didn't inline all mono_log_debug statements" +}; const checkNoLoader = { pattern: /_loaderModuleLoaded/gm, @@ -164,7 +180,7 @@ const loaderConfig = { } ], external: externalDependencies, - plugins: [nodeResolve(), regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime]), ...outputCodePlugins], + plugins: [nodeResolve(), regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime, checkDebugLog]), ...outputCodePlugins], onwarn: onwarn }; const runtimeConfig = { @@ -181,7 +197,7 @@ const runtimeConfig = { } ], external: externalDependencies, - plugins: [regexReplace(inlineAssert), regexCheck([checkAssert, checkNoLoader]), ...outputCodePlugins], + plugins: [regexReplace(inlineAssert), regexCheck([checkAssert, checkNoLoader, checkDebugLog]), ...outputCodePlugins], onwarn: onwarn }; const wasmImportsConfig = { From d1ddbf5bc401c0e75d4c1c05da13e4dbcc5c5f8b Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 14 May 2024 21:01:08 +0200 Subject: [PATCH 2/2] fix --- src/mono/browser/runtime/loader/logging.ts | 6 +----- src/mono/browser/runtime/logging.ts | 6 +----- src/mono/browser/runtime/rollup.config.js | 15 +++++---------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/mono/browser/runtime/loader/logging.ts b/src/mono/browser/runtime/loader/logging.ts index 2cc94df15279f0..e11e844c56b4d8 100644 --- a/src/mono/browser/runtime/loader/logging.ts +++ b/src/mono/browser/runtime/loader/logging.ts @@ -23,14 +23,10 @@ export function mono_log_debug (messageFactory: string | (() => string)) { const message = (typeof messageFactory === "function" ? messageFactory() : messageFactory); - mono_always_log_debug( message); + console.debug(prefix + message); } } -export function mono_always_log_debug (msg: string) { - console.debug(prefix + msg); -} - export function mono_log_info (msg: string, ...data: any) { console.info(prefix + msg, ...data); } diff --git a/src/mono/browser/runtime/logging.ts b/src/mono/browser/runtime/logging.ts index 1076b70893d288..7cd4af973fb889 100644 --- a/src/mono/browser/runtime/logging.ts +++ b/src/mono/browser/runtime/logging.ts @@ -21,14 +21,10 @@ export function mono_log_debug (messageFactory: string | (() => string)) { const message = (typeof messageFactory === "function" ? messageFactory() : messageFactory); - mono_always_log_debug( message); + console.debug(prefix + message); } } -export function mono_always_log_debug (msg: string) { - console.debug(prefix + msg); -} - export function mono_log_info (msg: string, ...data: any) { console.info(prefix + msg, ...data); } diff --git a/src/mono/browser/runtime/rollup.config.js b/src/mono/browser/runtime/rollup.config.js index 86245ef5bf4e00..83d4ca31223802 100644 --- a/src/mono/browser/runtime/rollup.config.js +++ b/src/mono/browser/runtime/rollup.config.js @@ -14,7 +14,7 @@ import gitCommitInfo from "git-commit-info"; import MagicString from "magic-string"; const configuration = process.env.Configuration; -const isDebug = configuration !== "Release"; +const isDebug = false; const isContinuousIntegrationBuild = process.env.ContinuousIntegrationBuild === "true" ? true : false; const productVersion = process.env.ProductVersion || "8.0.0-dev"; const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace(/"/g, "") : "bin"; @@ -73,12 +73,12 @@ const inlineAssert = [ // eslint-disable-next-line quotes pattern: 'mono_log_debug\\(*"([^"]*)"\\);', // eslint-disable-next-line quotes - replacement: (match) => `if (loaderHelpers.diagnosticTracing) mono_always_log_debug("${match[2]}"); // inlined mono_log_debug condition` + replacement: (match) => `if (loaderHelpers.diagnosticTracing) mono_log_debug("${match[1]}"); // inlined mono_log_debug condition` }, { // eslint-disable-next-line quotes pattern: 'mono_log_debug\\(\\(\\) => *`([^`]*)`\\);', - replacement: (match) => `if (loaderHelpers.diagnosticTracing) mono_always_log_debug(\`${match[1]}\`); // inlined mono_log_debug condition` + replacement: (match) => `if (loaderHelpers.diagnosticTracing) mono_log_debug(\`${match[1]}\`); // inlined mono_log_debug condition` }, ]; const checkAssert = @@ -86,11 +86,6 @@ const checkAssert = pattern: /^\s*mono_check/gm, failure: "previous regexp didn't inline all mono_check statements" }; -const checkDebugLog = -{ - pattern: /^\s*mono_log_debug/gm, - failure: "previous regexp didn't inline all mono_log_debug statements" -}; const checkNoLoader = { pattern: /_loaderModuleLoaded/gm, @@ -180,7 +175,7 @@ const loaderConfig = { } ], external: externalDependencies, - plugins: [nodeResolve(), regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime, checkDebugLog]), ...outputCodePlugins], + plugins: [nodeResolve(), regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime]), ...outputCodePlugins], onwarn: onwarn }; const runtimeConfig = { @@ -197,7 +192,7 @@ const runtimeConfig = { } ], external: externalDependencies, - plugins: [regexReplace(inlineAssert), regexCheck([checkAssert, checkNoLoader, checkDebugLog]), ...outputCodePlugins], + plugins: [regexReplace(inlineAssert), regexCheck([checkAssert, checkNoLoader]), ...outputCodePlugins], onwarn: onwarn }; const wasmImportsConfig = {