Skip to content

Commit 9c75b5c

Browse files
committed
wip
1 parent 1bb2371 commit 9c75b5c

25 files changed

+803
-805
lines changed

src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,16 @@
108108

109109
<FeatureMono>true</FeatureMono>
110110
<FeatureWasmManagedThreads Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
111-
<FeatureWasmPerfTracing Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and ('$(WasmEnableThreads)' == 'true')">true</FeatureWasmPerfTracing>
112111
<FeaturePortableTimer Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'">true</FeaturePortableTimer>
113112
<FeaturePortableThreadPool Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'">true</FeaturePortableThreadPool>
114-
<FeaturePerfTracing Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmPerftracing)' == 'true'">true</FeaturePerfTracing>
113+
<FeaturePerfTracing Condition="('$(TargetsWasi)' != 'true')">true</FeaturePerfTracing>
115114
<FeatureObjCMarshal Condition="'$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">true</FeatureObjCMarshal>
116115
</PropertyGroup>
117116

118117
<PropertyGroup>
119118
<DefineConstants Condition="'$(FeaturePerfTracing)' == 'true'">$(DefineConstants);FEATURE_PERFTRACING</DefineConstants>
120119
<DefineConstants Condition="'$(FeatureObjCMarshal)' == 'true'">$(DefineConstants);FEATURE_OBJCMARSHAL</DefineConstants>
121120
<DefineConstants Condition="'$(FeatureWasmManagedThreads)' == 'true'">$(DefineConstants);FEATURE_WASM_MANAGED_THREADS</DefineConstants>
122-
<DefineConstants Condition="'$(FeatureWasmPerfTracing)' == 'true'">$(DefineConstants);FEATURE_WASM_PERFTRACING</DefineConstants>
123121
</PropertyGroup>
124122

125123
<!-- ILLinker settings -->
@@ -132,7 +130,7 @@
132130
<ILLinkDescriptorsXmls Include="$(ILLinkDirectory)ILLink.Descriptors.xml" />
133131
<ILLinkDescriptorsXmls Include="$(ILLinkDirectory)ILLink.Descriptors.OSX.xml" Condition="'$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'" />
134132
<ILLinkDescriptorsXmls Include="$(CoreLibSharedDir)ILLink\ILLink.Descriptors.Shared.xml" />
135-
<ILLinkDescriptorsXmls Condition="'$(FeaturePerfTracing)' == 'true'" Include="$(CoreLibSharedDir)ILLink\ILLink.Descriptors.EventSource.xml" />
133+
<ILLinkDescriptorsLibraryBuildXml Condition="'$(FeaturePerfTracing)' == 'true'" Include="$(CoreLibSharedDir)ILLink\ILLink.Descriptors.EventSource.xml" />
136134

137135
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.$(Platform).xml" Condition="Exists('$(ILLinkDirectory)ILLink.Substitutions.$(Platform).xml')" />
138136
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.iOS.xml" Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'" />

src/mono/browser/runtime/corebindings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern void mono_wasm_invoke_js_function (int function_js_handle, void *args);
3232
extern int mono_runtime_run_module_cctor (MonoImage *image, MonoError *error);
3333

3434
typedef void (*background_job_cb)(void);
35+
typedef int (*background_job_cb1)(void* data);
3536

3637
void mono_wasm_bind_assembly_exports (char *assembly_name);
3738
void mono_wasm_assembly_get_entry_point (char *assembly_name, int auto_insert_breakpoint, MonoMethod **method_out);

src/mono/browser/runtime/cwraps.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ type SigLine = [lazyOrSkip: boolean | (() => boolean), name: string, returnType:
1717

1818
const threading_cwraps: SigLine[] = WasmEnableThreads ? [
1919
// MONO.diagnostics
20-
[true, "mono_wasm_event_pipe_enable", "bool", ["string", "number", "number", "string", "bool", "number"]],
21-
[true, "mono_wasm_event_pipe_session_start_streaming", "bool", ["number"]],
22-
[true, "mono_wasm_event_pipe_session_disable", "bool", ["number"]],
23-
[true, "mono_wasm_diagnostic_server_create_thread", "bool", ["string", "number"]],
24-
[true, "mono_wasm_diagnostic_server_thread_attach_to_runtime", "void", []],
25-
[true, "mono_wasm_diagnostic_server_post_resume_runtime", "void", []],
26-
[true, "mono_wasm_diagnostic_server_create_stream", "number", []],
2720
[false, "mono_wasm_init_finalizer_thread", null, []],
2821
[false, "mono_wasm_invoke_jsexport_async_post", "void", ["number", "number", "number"]],
2922
[false, "mono_wasm_invoke_jsexport_sync_send", "void", ["number", "number", "number"]],
@@ -49,6 +42,7 @@ const fn_signatures: SigLine[] = [
4942
[true, "mono_wasm_parse_runtime_options", null, ["number", "number"]],
5043
[true, "mono_wasm_strdup", "number", ["string"]],
5144
[true, "mono_background_exec", null, []],
45+
[true, "mono_ep_exec", null, []],
5246
[true, "mono_wasm_execute_timer", null, []],
5347
[true, "mono_wasm_load_icu_data", "number", ["number"]],
5448
[false, "mono_wasm_add_assembly", "number", ["string", "number", "number"]],
@@ -143,13 +137,6 @@ const fn_signatures: SigLine[] = [
143137

144138
export interface t_ThreadingCwraps {
145139
// MONO.diagnostics
146-
mono_wasm_event_pipe_enable(outputPath: string | null, stream: VoidPtr, bufferSizeInMB: number, providers: string, rundownRequested: boolean, outSessionId: VoidPtr): boolean;
147-
mono_wasm_event_pipe_session_start_streaming(sessionId: number): boolean;
148-
mono_wasm_event_pipe_session_disable(sessionId: number): boolean;
149-
mono_wasm_diagnostic_server_create_thread(websocketURL: string, threadIdOutPtr: VoidPtr): boolean;
150-
mono_wasm_diagnostic_server_thread_attach_to_runtime(): void;
151-
mono_wasm_diagnostic_server_post_resume_runtime(): void;
152-
mono_wasm_diagnostic_server_create_stream(): VoidPtr;
153140
mono_wasm_init_finalizer_thread(): void;
154141
mono_wasm_invoke_jsexport_async_post(targetTID: PThreadPtr, method: MonoMethod, args: VoidPtr): void;
155142
mono_wasm_invoke_jsexport_sync_send(targetTID: PThreadPtr, method: MonoMethod, args: VoidPtr): void;
@@ -180,6 +167,7 @@ export interface t_Cwraps {
180167
mono_wasm_strdup(value: string): number;
181168
mono_wasm_parse_runtime_options(length: number, argv: VoidPtr): void;
182169
mono_background_exec(): void;
170+
mono_ep_exec(): void;
183171
mono_wasm_execute_timer(): void;
184172
mono_wasm_load_icu_data(offset: VoidPtr): number;
185173
mono_wasm_add_assembly(name: string, data: VoidPtr, size: number): number;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
import WasmEnablePerfTracing from "consts:wasmEnablePerfTracing";
5+
6+
import { Module } from "../globals";
7+
import { utf8ToString } from "../strings";
8+
import { CharPtr, VoidPtr } from "../types/emscripten";
9+
import { createDiagConnectionJs } from "./diag-js";
10+
import { IDiagConnection } from "./common";
11+
import { createDiagConnectionWs } from "./diag-ws";
12+
13+
let socket_handles:Map<number, IDiagConnection> = undefined as any;
14+
let next_socket_handle = 1;
15+
16+
export function mono_wasm_ipc_websocket_create (urlPtr :CharPtr):number {
17+
if (!WasmEnablePerfTracing) {
18+
return -1;
19+
}
20+
if (!socket_handles) {
21+
socket_handles = new Map<number, IDiagConnection>();
22+
}
23+
const url = utf8ToString(urlPtr);
24+
const socket_handle = next_socket_handle++;
25+
const isWebSocket = url.startsWith("ws://") || url.startsWith("wss://");
26+
const wrapper = isWebSocket
27+
? createDiagConnectionWs(socket_handle, url)
28+
: createDiagConnectionJs(socket_handle, url);
29+
socket_handles.set(socket_handle, wrapper);
30+
return socket_handle;
31+
}
32+
33+
export function mono_wasm_ipc_websocket_send (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number {
34+
if (!WasmEnablePerfTracing) {
35+
return -1;
36+
}
37+
const wrapper = socket_handles.get(client_socket);
38+
if (!wrapper) {
39+
return -1;
40+
}
41+
const message = (new Uint8Array(Module.HEAPU8.buffer, buffer as any, bytes_to_write)).slice();
42+
return wrapper.send(message);
43+
}
44+
45+
export function mono_wasm_ipc_websocket_poll (client_socket :number):number {
46+
if (!WasmEnablePerfTracing) {
47+
return -1;
48+
}
49+
const wrapper = socket_handles.get(client_socket);
50+
if (!wrapper) {
51+
return 0;
52+
}
53+
return wrapper.poll();
54+
}
55+
56+
export function mono_wasm_ipc_websocket_recv (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number {
57+
if (!WasmEnablePerfTracing) {
58+
return -1;
59+
}
60+
const wrapper = socket_handles.get(client_socket);
61+
if (!wrapper) {
62+
return -1;
63+
}
64+
return wrapper.recv(buffer, bytes_to_read);
65+
}
66+
67+
export function mono_wasm_ipc_websocket_close (client_socket :number):number {
68+
if (!WasmEnablePerfTracing) {
69+
return -1;
70+
}
71+
const wrapper = socket_handles.get(client_socket);
72+
if (!wrapper) {
73+
return -1;
74+
}
75+
socket_handles.delete(client_socket);
76+
return wrapper.close();
77+
}
78+

src/mono/browser/runtime/exports-binding.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import { mono_interp_jit_wasm_jit_call_trampoline, mono_interp_invoke_wasm_jit_c
1212
import { mono_wasm_resolve_or_reject_promise } from "./marshal-to-js";
1313
import { mono_wasm_schedule_timer, schedule_background_exec } from "./scheduling";
1414
import { mono_wasm_asm_loaded } from "./startup";
15-
import { mono_wasm_diagnostic_server_on_server_thread_created } from "./diagnostics/server_pthread";
16-
import { mono_wasm_diagnostic_server_on_runtime_server_init, mono_wasm_event_pipe_early_startup_callback } from "./diagnostics";
17-
import { mono_wasm_diagnostic_server_stream_signal_work_available } from "./diagnostics/server_pthread/stream-queue";
1815
import { mono_log_warn, mono_wasm_console_clear, mono_wasm_trace_logger } from "./logging";
1916
import { mono_wasm_profiler_leave, mono_wasm_profiler_enter } from "./profiler";
2017
import { mono_wasm_browser_entropy } from "./crypto";
@@ -28,6 +25,7 @@ import {
2825
import { mono_wasm_dump_threads } from "./pthreads/ui-thread";
2926
import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared";
3027
import { mono_wasm_js_globalization_imports } from "./globalization";
28+
import { mono_wasm_ipc_websocket_create, mono_wasm_ipc_websocket_send, mono_wasm_ipc_websocket_poll, mono_wasm_ipc_websocket_recv, mono_wasm_ipc_websocket_close } from "./diag";
3129

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

@@ -43,10 +41,6 @@ export const mono_wasm_threads_imports = !WasmEnableThreads ? [] : [
4341

4442
// mono-threads.c
4543
mono_wasm_dump_threads,
46-
// diagnostics_server.c
47-
mono_wasm_diagnostic_server_on_server_thread_created,
48-
mono_wasm_diagnostic_server_on_runtime_server_init,
49-
mono_wasm_diagnostic_server_stream_signal_work_available,
5044

5145
// corebindings.c
5246
mono_wasm_install_js_worker_interop,
@@ -68,6 +62,13 @@ export const mono_wasm_imports = [
6862
// mono-threads-wasm.c
6963
schedule_background_exec,
7064

65+
//event pipe
66+
mono_wasm_ipc_websocket_create,
67+
mono_wasm_ipc_websocket_send,
68+
mono_wasm_ipc_websocket_poll,
69+
mono_wasm_ipc_websocket_recv,
70+
mono_wasm_ipc_websocket_close,
71+
7172
// interp.c and jiterpreter.c
7273
mono_interp_tier_prepare_jiterpreter,
7374
mono_interp_record_interp_entry,
@@ -83,7 +84,6 @@ export const mono_wasm_imports = [
8384
// driver.c
8485
mono_wasm_trace_logger,
8586
mono_wasm_set_entrypoint_breakpoint,
86-
mono_wasm_event_pipe_early_startup_callback,
8787

8888
// src/native/minipal/random.c
8989
mono_wasm_browser_entropy,

src/mono/browser/runtime/rollup.config.js

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as path from "path";
99
import { createHash } from "crypto";
1010
import dts from "rollup-plugin-dts";
1111
import { createFilter } from "@rollup/pluginutils";
12-
import fast_glob from "fast-glob";
1312
import gitCommitInfo from "git-commit-info";
1413
import MagicString from "magic-string";
1514

@@ -21,13 +20,13 @@ const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace
2120
const wasmObjDir = process.env.WasmObjDir ? process.env.WasmObjDir.replace(/"/g, "") : "obj";
2221
const wasmEnableThreads = process.env.WasmEnableThreads === "true" ? true : false;
2322
const wasmEnableSIMD = process.env.WASM_ENABLE_SIMD === "1" ? true : false;
23+
const wasmEnablePerfTracing = process.env.WASM_ENABLE_PERFTRACING === "1" ? true : false;
2424
const wasmEnableExceptionHandling = process.env.WASM_ENABLE_EH === "1" ? true : false;
2525
const wasmEnableJsInteropByValue = process.env.ENABLE_JS_INTEROP_BY_VALUE == "1" ? true : false;
26-
const monoDiagnosticsMock = process.env.MonoDiagnosticsMock === "true" ? true : false;
2726
// because of stack walk at src/mono/browser/debugger/BrowserDebugProxy/MonoProxy.cs
2827
// and unit test at with timers.mjs
2928
const keep_fnames = /(mono_wasm_runtime_ready|mono_wasm_fire_debugger_agent_message_with_data|mono_wasm_fire_debugger_agent_message_with_data_to_pause|mono_wasm_schedule_timer_tick)/;
30-
const keep_classnames = /(ManagedObject|ManagedError|Span|ArraySegment|WasmRootBuffer|SessionOptionsBuilder)/;
29+
const keep_classnames = /(ManagedObject|ManagedError|Span|ArraySegment)/;
3130
const terserConfig = {
3231
compress: {
3332
defaults: true,
@@ -110,8 +109,8 @@ const envConstants = {
110109
configuration,
111110
wasmEnableThreads,
112111
wasmEnableSIMD,
112+
wasmEnablePerfTracing,
113113
wasmEnableExceptionHandling,
114-
monoDiagnosticsMock,
115114
gitHash,
116115
wasmEnableJsInteropByValue,
117116
isContinuousIntegrationBuild,
@@ -237,51 +236,14 @@ if (isDebug) {
237236
banner: banner_dts,
238237
plugins: [alwaysLF(), writeOnChangePlugin()],
239238
});
240-
241-
// export types into the source code and commit to git
242-
diagnosticMockTypesConfig = {
243-
input: "./diagnostics/mock/export-types.ts",
244-
output: [
245-
{
246-
format: "es",
247-
file: "./diagnostics-mock.d.ts",
248-
banner: banner_dts,
249-
plugins: [alwaysLF(), writeOnChangePlugin()],
250-
}
251-
],
252-
external: externalDependencies,
253-
plugins: [dts()],
254-
onwarn: onwarn
255-
};
256-
}
257-
258-
/* Web Workers */
259-
function makeWorkerConfig (workerName, workerInputSourcePath) {
260-
const workerConfig = {
261-
input: workerInputSourcePath,
262-
output: [
263-
{
264-
file: nativeBinDir + `/src/dotnet-${workerName}-worker.js`,
265-
format: "iife",
266-
banner,
267-
plugins
268-
},
269-
],
270-
external: externalDependencies,
271-
plugins: outputCodePlugins,
272-
};
273-
return workerConfig;
274239
}
275240

276-
const workerConfigs = findWebWorkerInputs("./workers").map((workerInput) => makeWorkerConfig(workerInput.workerName, workerInput.path));
277-
278241
const allConfigs = [
279242
loaderConfig,
280243
runtimeConfig,
281244
wasmImportsConfig,
282245
typesConfig,
283246
]
284-
.concat(workerConfigs)
285247
.concat(diagnosticMockTypesConfig ? [diagnosticMockTypesConfig] : []);
286248
export default defineConfig(allConfigs);
287249

@@ -448,28 +410,6 @@ function regexReplace (replacements = []) {
448410
}
449411
}
450412

451-
// Finds all files that look like a webworker toplevel input file in the given path.
452-
// Does not look recursively in subdirectories.
453-
// Returns an array of objects {"workerName": "foo", "path": "/path/dotnet-foo-worker.ts"}
454-
//
455-
// A file looks like a webworker toplevel input if it's `dotnet-{name}-worker.ts` or `.js`
456-
function findWebWorkerInputs (basePath) {
457-
const glob = "dotnet-*-worker.[tj]s";
458-
const files = fast_glob.sync(glob, { cwd: basePath });
459-
if (files.length == 0) {
460-
return [];
461-
}
462-
const re = /^dotnet-(.*)-worker\.[tj]s$/;
463-
let results = [];
464-
for (const file of files) {
465-
const match = file.match(re);
466-
if (match) {
467-
results.push({ "workerName": match[1], "path": path.join(basePath, file) });
468-
}
469-
}
470-
return results;
471-
}
472-
473413
function onwarn (warning) {
474414
if (warning.code === "CIRCULAR_DEPENDENCY") {
475415
return;

src/mono/browser/runtime/startup.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { localHeapViewU8, malloc } from "./memory";
3232
import { assertNoProxies } from "./gc-handles";
3333
import { runtimeList } from "./exports";
3434
import { nativeAbort, nativeExit } from "./run";
35-
import { mono_wasm_init_diagnostics } from "./diagnostics";
3635
import { replaceEmscriptenPThreadInit } from "./pthreads/worker-thread";
3736

3837
export async function configureRuntimeStartup (module: DotnetModuleInternal): Promise<void> {
@@ -547,11 +546,6 @@ export async function start_runtime () {
547546
if (runtimeHelpers.config.logProfilerOptions)
548547
mono_wasm_init_log_profiler(runtimeHelpers.config.logProfilerOptions);
549548

550-
if (WasmEnableThreads) {
551-
// this is not mono-attached thread, so we can start it earlier
552-
await mono_wasm_init_diagnostics();
553-
}
554-
555549
mono_wasm_load_runtime();
556550

557551
jiterpreter_allocate_tables();

src/mono/mono/component/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ set(${MONO_DIAGNOSTICS_TRACING_COMPONENT_NAME}-sources
7676
${diagnostic_server_sources}
7777
${MONO_COMPONENT_PATH}/event_pipe.c
7878
${MONO_COMPONENT_PATH}/event_pipe.h
79-
${MONO_COMPONENT_PATH}/event_pipe-wasm.h
8079
${MONO_COMPONENT_PATH}/diagnostics_server.c
8180
${MONO_COMPONENT_PATH}/diagnostics_server.h
8281
)

0 commit comments

Comments
 (0)