Skip to content

[browser] add and load empty ES6 module dotnet.diag.js when FeaturePerfTracing #112787

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

Merged
merged 18 commits into from
Feb 27, 2025
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
2 changes: 2 additions & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@
$(LibrariesNativeArtifactsPath)dotnet.native.js;
$(LibrariesNativeArtifactsPath)dotnet.runtime.js;
$(LibrariesNativeArtifactsPath)dotnet.runtime.js.map;
$(LibrariesNativeArtifactsPath)dotnet.diagnostics.js;
$(LibrariesNativeArtifactsPath)dotnet.diagnostics.js.map;
$(LibrariesNativeArtifactsPath)dotnet.d.ts;
$(LibrariesNativeArtifactsPath)package.json;
$(LibrariesNativeArtifactsPath)dotnet.native.wasm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@
<PlatformManifestFileEntry Include="dotnet.js.map" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.runtime.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.runtime.js.map" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.diagnostics.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.diagnostics.js.map" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.worker.mjs" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.native.js.symbols" IsNative="true" />
Expand Down
4 changes: 4 additions & 0 deletions src/mono/browser/browser.proj
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
{ "identity": "WasmSingleFileBundle", "defaultValueInRuntimePack": "$(WasmSingleFileBundle)" },
{ "identity": "WasmEnableSIMD", "defaultValueInRuntimePack": "$(WasmEnableSIMD)" },
{ "identity": "WasmEnableExceptionHandling", "defaultValueInRuntimePack": "$(WasmEnableExceptionHandling)" },
{ "identity": "FeaturePerfTracing", "defaultValueInRuntimePack": "$(FeaturePerfTracing)" },
{ "identity": "WasmProfilers", "defaultValueInRuntimePack": "$(WasmProfilers)" },
{ "identity": "EmccMaximumHeapSize", "defaultValueInRuntimePack": "$(EmccMaximumHeapSize)" }
]
}
Expand Down Expand Up @@ -497,6 +499,8 @@
$(NativeBinDir)dotnet.js.map;
$(NativeBinDir)dotnet.runtime.js;
$(NativeBinDir)dotnet.runtime.js.map;
$(NativeBinDir)dotnet.diagnostics.js;
$(NativeBinDir)dotnet.diagnostics.js.map;
$(NativeBinDir)dotnet.native.js;
$(NativeBinDir)dotnet.d.ts;
$(NativeBinDir)package.json;
Expand Down
6 changes: 5 additions & 1 deletion src/mono/browser/build/BrowserWasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Post Wasm MVP features -->
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">true</WasmEnableExceptionHandling>
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">$(WasmEnableExceptionHandling)</WasmEnableSIMD>
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == '' and '$(Configuration)' == 'Debug'">true</FeaturePerfTracing>
<!-- we are not triggering FeaturePerfTracing in Debug automatically, because it would trigger re-link, making dev-loop slow -->
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == ''">false</FeaturePerfTracing>
</PropertyGroup>

Expand Down Expand Up @@ -90,6 +90,7 @@
<!-- If dotnet.{wasm,js} weren't added already (eg. AOT can add them), then add the default ones -->
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.js" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.runtime.js" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.diagnostics.js" Condition="'$(FeaturePerfTracing)' == 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.wasm" Condition="'$(_HasDotnetWasm)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.js" Condition="'$(_HasDotnetNativeJs)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.mjs" Condition="'$(_HasDotnetJsWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.native.worker.mjs')" />
Expand All @@ -101,6 +102,8 @@
Condition="'$(WasmEmitSourceMap)' != 'false'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.runtime.js.map"
Condition="'$(WasmEmitSourceMap)' != 'false'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.diagnostics.js.map"
Condition="'$(WasmEmitSourceMap)' != 'false' and '$(FeaturePerfTracing)' == 'true'" />
</ItemGroup>

<ItemGroup Condition="'$(InvariantGlobalization)' != 'true'">
Expand All @@ -113,6 +116,7 @@

<Error Condition="'$(InvariantGlobalization)' != 'true' and '$(WasmIncludeFullIcuData)' != 'true' and '$(WasmIcuDataFileName)' != '' and !Exists('$(_WasmIcuDataFileName)')" Text="File in location %24(WasmIcuDataFileName)=$(WasmIcuDataFileName) cannot be found neither when used as absolute path nor a relative runtime pack path. You might want to pass one of the values: @(_IcuAvailableDataFiles->'%(Filename)')."/>
<Error Condition="'$(InvariantGlobalization)' != 'true' and '$(WasmIncludeFullIcuData)' != 'true' and '$(WasmIcuDataFileName)' != '' and !$([System.IO.Path]::GetFileName('$(WasmIcuDataFileName)').StartsWith('icudt'))" Text="Custom ICU file name in path %24(WasmIcuDataFileName)=$(WasmIcuDataFileName) must start with 'icudt'."/>
<Error Condition="'$(WasmProfilers)' != '' and '$(FeaturePerfTracing)' != 'false'" Text="%24(WasmProfilers)=$(WasmProfilers) is not supported together with %24(FeaturePerfTracing)=$(FeaturePerfTracing)"/>
</Target>

<Target Name="_WasmGenerateAppBundle"
Expand Down
1 change: 0 additions & 1 deletion src/mono/browser/runtime/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
jiterpreter-opcodes.ts
jiterpreter-tables.ts
dotnet.d.ts
diagnostics-mock.d.ts
1 change: 0 additions & 1 deletion src/mono/browser/runtime/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
"jiterpreter-opcodes.ts",
"jiterpreter-tables.ts",
"dotnet.d.ts",
"diagnostics-mock.d.ts",
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
Expand Down
1 change: 1 addition & 0 deletions src/mono/browser/runtime/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8A
switch (asset.behavior) {
case "dotnetwasm":
case "js-module-threads":
case "js-module-diagnostics":
case "symbols":
// do nothing
break;
Expand Down
2 changes: 0 additions & 2 deletions src/mono/browser/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { mono_assert } from "./globals";
type SigLine = [lazyOrSkip: boolean | (() => boolean), name: string, returnType: string | null, argTypes?: string[], opts?: any];

const threading_cwraps: SigLine[] = WasmEnableThreads ? [
// MONO.diagnostics
[false, "mono_wasm_init_finalizer_thread", null, []],
[false, "mono_wasm_invoke_jsexport_async_post", "void", ["number", "number", "number"]],
[false, "mono_wasm_invoke_jsexport_sync_send", "void", ["number", "number", "number"]],
Expand Down Expand Up @@ -139,7 +138,6 @@ const fn_signatures: SigLine[] = [
];

export interface t_ThreadingCwraps {
// MONO.diagnostics
mono_wasm_init_finalizer_thread(): void;
mono_wasm_invoke_jsexport_async_post(targetTID: PThreadPtr, method: MonoMethod, args: VoidPtr): void;
mono_wasm_invoke_jsexport_sync_send(targetTID: PThreadPtr, method: MonoMethod, args: VoidPtr): void;
Expand Down
26 changes: 26 additions & 0 deletions src/mono/browser/runtime/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import type { CharPtr, VoidPtr } from "./types/emscripten";

import { diagnosticHelpers } from "./globals";

export function ds_rt_websocket_create (urlPtr :CharPtr):number {
return diagnosticHelpers.ds_rt_websocket_create(urlPtr);
}

export function ds_rt_websocket_send (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number {
return diagnosticHelpers.ds_rt_websocket_send(client_socket, buffer, bytes_to_write);
}

export function ds_rt_websocket_poll (client_socket :number):number {
return diagnosticHelpers.ds_rt_websocket_poll(client_socket);
}

export function ds_rt_websocket_recv (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number {
return diagnosticHelpers.ds_rt_websocket_recv(client_socket, buffer, bytes_to_read);
}

export function ds_rt_websocket_close (client_socket :number):number {
return diagnosticHelpers.ds_rt_websocket_close(client_socket);
}
23 changes: 23 additions & 0 deletions src/mono/browser/runtime/diagnostics/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import type { DiagnosticHelpers, GlobalObjects, LoaderHelpers, RuntimeHelpers, DotnetModuleInternal } from "../types/internal";

export let _diagnosticModuleLoaded = false; // please keep it in place also as rollup guard

export let diagnosticHelpers: DiagnosticHelpers = null as any;
export let runtimeHelpers: RuntimeHelpers = null as any;
export let loaderHelpers: LoaderHelpers = null as any;
export let Module: DotnetModuleInternal = null as any;

export function setRuntimeGlobalsImpl (globalObjects: GlobalObjects): void {
if (_diagnosticModuleLoaded) {
throw new Error("Diag module already loaded");
}
_diagnosticModuleLoaded = true;
diagnosticHelpers = globalObjects.diagnosticHelpers;
runtimeHelpers = globalObjects.runtimeHelpers;
loaderHelpers = globalObjects.loaderHelpers;
Module = globalObjects.module;
}
32 changes: 32 additions & 0 deletions src/mono/browser/runtime/diagnostics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import type { GlobalObjects } from "../types/internal";
import type { CharPtr, VoidPtr } from "../types/emscripten";

import { diagnosticHelpers, setRuntimeGlobalsImpl } from "./globals";

/* eslint-disable @typescript-eslint/no-unused-vars */
export function setRuntimeGlobals (globalObjects: GlobalObjects): void {
setRuntimeGlobalsImpl(globalObjects);

diagnosticHelpers.ds_rt_websocket_create = (urlPtr :CharPtr):number => {
throw new Error("Not implemented");
};

diagnosticHelpers.ds_rt_websocket_send = (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number => {
throw new Error("Not implemented");
};

diagnosticHelpers.ds_rt_websocket_poll = (client_socket :number):number => {
throw new Error("Not implemented");
};

diagnosticHelpers.ds_rt_websocket_recv = (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number => {
throw new Error("Not implemented");
};

diagnosticHelpers. ds_rt_websocket_close = (client_socket :number):number => {
throw new Error("Not implemented");
};
}
39 changes: 39 additions & 0 deletions src/mono/browser/runtime/diagnostics/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { loaderHelpers } from "./globals";

/* eslint-disable no-console */

const prefix = "MONO_WASM: ";

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

export function mono_log_info (msg: string, ...data: any) {
console.info(prefix + msg, ...data);
}

export function mono_log_warn (msg: string, ...data: any) {
console.warn(prefix + msg, ...data);
}

export function mono_log_error (msg: string, ...data: any) {
if (data && data.length > 0 && data[0] && typeof data[0] === "object") {
// don't log silent errors
if (data[0].silent) {
return;
}
if (data[0].toString) {
console.error(prefix + msg, data[0].toString());
return;
}
}
console.error(prefix + msg, ...data);
}
6 changes: 5 additions & 1 deletion src/mono/browser/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ interface ResourceGroups {
corePdb?: ResourceList;
pdb?: ResourceList;
jsModuleWorker?: ResourceList;
jsModuleGlobalization?: ResourceList;
jsModuleDiagnostics?: ResourceList;
jsModuleNative: ResourceList;
jsModuleRuntime: ResourceList;
wasmSymbols?: ResourceList;
Expand Down Expand Up @@ -360,6 +360,10 @@ type SingleAssetBehaviors =
* The javascript module for threads.
*/
| "js-module-threads"
/**
* The javascript module for diagnostic server and client.
*/
| "js-module-diagnostics"
/**
* The javascript module for runtime.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/es6/dotnet.es6.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function createWasmImportStubsFrom(collection) {
// we will replace them with the real implementation in replace_linker_placeholders
function injectDependencies() {
createWasmImportStubsFrom(methodIndexByName.mono_wasm_imports);
createWasmImportStubsFrom(methodIndexByName.mono_wasm_js_globalization_imports);
if (FEATURE_PERFTRACING) createWasmImportStubsFrom(methodIndexByName.mono_wasm_diagnostic_imports);

#if USE_PTHREADS
createWasmImportStubsFrom(methodIndexByName.mono_wasm_threads_imports);
Expand Down
30 changes: 18 additions & 12 deletions src/mono/browser/runtime/exports-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { mono_wasm_resolve_or_reject_promise } from "./marshal-to-js";
import { mono_wasm_schedule_timer, schedule_background_exec } from "./scheduling";
import { mono_wasm_asm_loaded } from "./startup";
import { mono_log_warn, mono_wasm_console_clear, mono_wasm_trace_logger } from "./logging";
import { mono_wasm_profiler_record, mono_wasm_profiler_now, ds_rt_websocket_close, ds_rt_websocket_create, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_send } from "./profiler";
import { mono_wasm_browser_entropy } from "./crypto";
import { mono_wasm_cancel_promise } from "./cancelable-promise";

Expand All @@ -24,7 +23,10 @@ import {
} from "./pthreads";
import { mono_wasm_dump_threads } from "./pthreads/ui-thread";
import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared";
import { mono_wasm_js_globalization_imports } from "./globalization";
import { mono_wasm_get_locale_info } from "./globalization-locale";

import { mono_wasm_profiler_record, mono_wasm_profiler_now } from "./profiler";
import { ds_rt_websocket_create, ds_rt_websocket_send, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_close } from "./diagnostics";

// the JS methods would be visible to EMCC linker and become imports of the WASM module

Expand All @@ -48,6 +50,15 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [
mono_wasm_warn_about_blocking_wait,
];

export const mono_wasm_diagnostic_imports = [
//event pipe
ds_rt_websocket_create,
ds_rt_websocket_send,
ds_rt_websocket_poll,
ds_rt_websocket_recv,
ds_rt_websocket_close,
];

export const mono_wasm_imports = [
// mini-wasm.c
mono_wasm_schedule_timer,
Expand All @@ -70,6 +81,7 @@ export const mono_wasm_imports = [
mono_interp_flush_jitcall_queue,
mono_wasm_free_method_data,

// browser.c
mono_wasm_profiler_now,
mono_wasm_profiler_record,

Expand All @@ -88,22 +100,16 @@ export const mono_wasm_imports = [
mono_wasm_invoke_jsimport_ST,
mono_wasm_resolve_or_reject_promise,
mono_wasm_cancel_promise,

//event pipe
ds_rt_websocket_create,
ds_rt_websocket_send,
ds_rt_websocket_poll,
ds_rt_websocket_recv,
ds_rt_websocket_close,
mono_wasm_get_locale_info,
];


// !!! Keep in sync with exports-linker.ts
const wasmImports: Function[] = [
...mono_wasm_imports,
// diagnostic server exports, when enabled
...mono_wasm_diagnostic_imports,
// threading exports, if threading is enabled
...mono_wasm_threads_imports,
// globalization exports
...mono_wasm_js_globalization_imports,
];

export function replace_linker_placeholders (imports: WebAssembly.Imports) {
Expand Down
9 changes: 4 additions & 5 deletions src/mono/browser/runtime/exports-linker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { mono_wasm_imports, mono_wasm_threads_imports } from "./exports-binding";
import { mono_wasm_diagnostic_imports, mono_wasm_imports, mono_wasm_threads_imports } from "./exports-binding";
import gitHash from "consts:gitHash";
import { mono_wasm_js_globalization_imports } from "./globalization";

export function export_linker_indexes_as_code (): string {
const indexByName: any = {
mono_wasm_imports: {},
mono_wasm_threads_imports: {},
mono_wasm_js_globalization_imports: {},
mono_wasm_diagnostic_imports: {},
};
let idx = 0;
for (const wi of mono_wasm_imports) {
Expand All @@ -20,8 +19,8 @@ export function export_linker_indexes_as_code (): string {
indexByName.mono_wasm_threads_imports[wi.name] = idx;
idx++;
}
for (const wi of mono_wasm_js_globalization_imports) {
indexByName.mono_wasm_js_globalization_imports[wi.name] = idx;
for (const wi of mono_wasm_diagnostic_imports) {
indexByName.mono_wasm_diagnostic_imports[wi.name] = idx;
idx++;
}
return `
Expand Down
5 changes: 4 additions & 1 deletion src/mono/browser/runtime/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { forceDisposeProxies } from "./gc-handles";
import { mono_wasm_dump_threads } from "./pthreads";

import { threads_c_functions as tcwraps } from "./cwraps";
import { utf8ToString } from "./strings";

export let runtimeList: RuntimeList;

Expand All @@ -40,7 +41,9 @@ function initializeExports (globalObjects: GlobalObjects): RuntimeAPI {
instantiate_asset,
jiterpreter_dump_stats,
forceDisposeProxies,

utf8ToString,
mono_background_exec: () => tcwraps.mono_background_exec(),
mono_wasm_ds_exec: () => tcwraps.mono_wasm_ds_exec(),
};
if (WasmEnableThreads) {
rh.dumpThreads = mono_wasm_dump_threads;
Expand Down
10 changes: 0 additions & 10 deletions src/mono/browser/runtime/globalization.ts

This file was deleted.

Loading
Loading