Skip to content

Commit 3f71cde

Browse files
authored
[browser] single threaded diagnostic server -part 1 (#111910)
1 parent 482e5b1 commit 3f71cde

35 files changed

Lines changed: 1209 additions & 77 deletions

src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,24 @@ ep_rt_sample_profiler_write_sampling_event_for_threads (
512512
ep_rt_aot_sample_profiler_write_sampling_event_for_threads (sampling_thread, sampling_event);
513513
}
514514

515+
static
516+
inline
517+
void
518+
ep_rt_sample_profiler_enabled (EventPipeEvent *sampling_event)
519+
{
520+
STATIC_CONTRACT_NOTHROW;
521+
// no-op
522+
}
523+
524+
static
525+
inline
526+
void
527+
ep_rt_sample_profiler_disabled (void)
528+
{
529+
STATIC_CONTRACT_NOTHROW;
530+
// no-op
531+
}
532+
515533
static
516534
inline
517535
void
@@ -744,6 +762,15 @@ ep_rt_thread_create (
744762
return ep_rt_aot_thread_create(thread_func, params, thread_type, id);
745763
}
746764

765+
static
766+
bool
767+
ep_rt_queue_job (
768+
void *job_func,
769+
void *params)
770+
{
771+
EP_UNREACHABLE ("Not implemented in NativeAOT");
772+
}
773+
747774
static
748775
inline
749776
void

src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,24 @@ ep_rt_sample_profiler_write_sampling_event_for_threads (
567567
ep_rt_coreclr_sample_profiler_write_sampling_event_for_threads (sampling_thread, sampling_event);
568568
}
569569

570+
static
571+
inline
572+
void
573+
ep_rt_sample_profiler_enabled (EventPipeEvent *sampling_event)
574+
{
575+
STATIC_CONTRACT_NOTHROW;
576+
// no-op
577+
}
578+
579+
static
580+
inline
581+
void
582+
ep_rt_sample_profiler_disabled (void)
583+
{
584+
STATIC_CONTRACT_NOTHROW;
585+
// no-op
586+
}
587+
570588
static
571589
inline
572590
void
@@ -871,6 +889,15 @@ ep_rt_thread_create (
871889
return result;
872890
}
873891

892+
static
893+
bool
894+
ep_rt_queue_job (
895+
void *job_func,
896+
void *params)
897+
{
898+
EP_UNREACHABLE ("Not implemented in CoreCLR");
899+
}
900+
874901
static
875902
inline
876903
void

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,17 @@
107107
<PropertyGroup>
108108
<NoWarn>$(NoWarn),618,67</NoWarn>
109109

110+
<!-- Diagnostics API for browser need to be made public for browser in future PRs, see https://github.com/dotnet/runtime/pull/111910 -->
111+
<NoWarn Condition="'$(TargetsBrowser)' == 'true'">$(NoWarn);CA1416</NoWarn>
112+
110113
<DefineConstants>$(DefineConstants);MONO_FEATURE_SRE</DefineConstants>
111114

112115
<FeatureMono>true</FeatureMono>
113116
<FeatureWasmManagedThreads Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(WasmEnableThreads)' == 'true'">true</FeatureWasmManagedThreads>
114117
<FeatureSingleThread Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(WasmEnableThreads)' != 'true'">true</FeatureSingleThread>
115118
<FeaturePortableTimer Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'">true</FeaturePortableTimer>
116119
<FeaturePortableThreadPool Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmManagedThreads)' == 'true'">true</FeaturePortableThreadPool>
117-
<FeaturePerfTracing Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true')">true</FeaturePerfTracing>
120+
<FeaturePerfTracing Condition="('$(TargetsWasi)' != 'true')">true</FeaturePerfTracing>
118121
<FeatureObjCMarshal Condition="'$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">true</FeatureObjCMarshal>
119122
</PropertyGroup>
120123

src/mono/browser/browser.proj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<EmccMaximumHeapSize Condition="'$(EmccMaximumHeapSize)' == ''">2147483648</EmccMaximumHeapSize>
2828
<WasmEnableJsInteropByValue Condition="'$(WasmEnableJsInteropByValue)' == '' and '$(WasmEnableThreads)' == 'true'">true</WasmEnableJsInteropByValue>
2929
<WasmEnableJsInteropByValue Condition="'$(WasmEnableJsInteropByValue)' == ''">false</WasmEnableJsInteropByValue>
30+
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == '' and '$(Configuration)' == 'Debug'">true</FeaturePerfTracing>
3031
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == ''">false</FeaturePerfTracing>
3132
<FilterSystemTimeZones Condition="'$(FilterSystemTimeZones)' == ''">false</FilterSystemTimeZones>
3233
<EmccCmd>emcc</EmccCmd>
@@ -424,6 +425,8 @@
424425
<_CmakeEnvironmentVariable Include="ENABLE_JS_INTEROP_BY_VALUE=0" Condition="'$(WasmEnableJsInteropByValue)' == 'false'"/>
425426
<_CmakeEnvironmentVariable Include="WASM_ENABLE_SIMD=1" Condition="'$(WasmEnableSIMD)' != 'false'" />
426427
<_CmakeEnvironmentVariable Include="WASM_ENABLE_SIMD=0" Condition="'$(WasmEnableSIMD)' == 'false'" />
428+
<_CmakeEnvironmentVariable Include="FEATURE_PERFTRACING=1" Condition="'$(FeaturePerfTracing)' == 'true'" />
429+
<_CmakeEnvironmentVariable Include="FEATURE_PERFTRACING=0" Condition="'$(FeaturePerfTracing)' != 'true'" />
427430
<_CmakeEnvironmentVariable Include="WASM_ENABLE_EH=1" Condition="'$(WasmEnableExceptionHandling)' != 'false'" />
428431
<_CmakeEnvironmentVariable Include="WASM_ENABLE_EH=0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
429432
<_CmakeEnvironmentVariable Include="RUN_AOT_COMPILATION=1" Condition="'$(RunAOTCompilation)' == 'true'" />
@@ -568,6 +571,8 @@
568571
<_MonoRollupEnvironmentVariable Include="WasmEnableThreads:$(WasmEnableThreads)" />
569572
<_MonoRollupEnvironmentVariable Include="WASM_ENABLE_SIMD:1" Condition="'$(WasmEnableSIMD)' != 'false'" />
570573
<_MonoRollupEnvironmentVariable Include="WASM_ENABLE_SIMD:0" Condition="'$(WasmEnableSIMD)' == 'false'" />
574+
<_MonoRollupEnvironmentVariable Include="FEATURE_PERFTRACING:1" Condition="'$(FeaturePerfTracing)' == 'true'" />
575+
<_MonoRollupEnvironmentVariable Include="FEATURE_PERFTRACING:0" Condition="'$(FeaturePerfTracing)' != 'true'" />
571576
<_MonoRollupEnvironmentVariable Include="WASM_ENABLE_EH:1" Condition="'$(WasmEnableExceptionHandling)' != 'false'" />
572577
<_MonoRollupEnvironmentVariable Include="WASM_ENABLE_EH:0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
573578
<_MonoRollupEnvironmentVariable Include="ENABLE_JS_INTEROP_BY_VALUE:1" Condition="'$(WasmEnableJsInteropByValue)' == 'true'" />

src/mono/browser/build/BrowserWasmApp.targets

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<!-- Post Wasm MVP features -->
44
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">true</WasmEnableExceptionHandling>
55
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">$(WasmEnableExceptionHandling)</WasmEnableSIMD>
6+
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == '' and '$(Configuration)' == 'Debug'">true</FeaturePerfTracing>
7+
<FeaturePerfTracing Condition="'$(FeaturePerfTracing)' == ''">false</FeaturePerfTracing>
68
</PropertyGroup>
79

810
<Import Project="$(WasmCommonTargetsPath)WasmApp.Common.targets" />
@@ -362,6 +364,8 @@
362364
<EmscriptenEnvVars Include="ENABLE_JS_INTEROP_BY_VALUE=0" Condition="'$(WasmEnableJsInteropByValue)' != 'true'" />
363365
<EmscriptenEnvVars Include="WASM_ENABLE_SIMD=1" Condition="'$(WasmEnableSIMD)' != 'false'" />
364366
<EmscriptenEnvVars Include="WASM_ENABLE_SIMD=0" Condition="'$(WasmEnableSIMD)' == 'false'" />
367+
<EmscriptenEnvVars Include="FEATURE_PERFTRACING=1" Condition="'$(FeaturePerfTracing)' == 'true'" />
368+
<EmscriptenEnvVars Include="FEATURE_PERFTRACING=0" Condition="'$(FeaturePerfTracing)' != 'true'" />
365369
<EmscriptenEnvVars Include="WASM_ENABLE_EH=1" Condition="'$(WasmEnableExceptionHandling)' != 'false'" />
366370
<EmscriptenEnvVars Include="WASM_ENABLE_EH=0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
367371
<EmscriptenEnvVars Include="ENABLE_AOT_PROFILER=$([System.Convert]::ToInt32($(WasmProfilers.Contains('aot'))))" />
@@ -434,6 +438,13 @@
434438
<_EmccExportedRuntimeMethods>"[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]"</_EmccExportedRuntimeMethods>
435439
<_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',')</_EmccExportedFunctions>
436440
</PropertyGroup>
441+
442+
<ItemGroup>
443+
<_MonoRuntimeComponentDontLink Include="wasm-bundled-timezones.a" Condition="'$(InvariantTimezone)' == 'true'"/>
444+
<_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a" Condition="'$(FeaturePerfTracing)' != 'true'" />
445+
<_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-stub-static.lib" Condition="'$(FeaturePerfTracing)' == 'true'" />
446+
</ItemGroup>
447+
437448
<ItemGroup>
438449
<!-- order matters -->
439450
<!-- some flags will be duplicated on the commandline and in the .rsp file. The last wins. -->

src/mono/browser/build/WasmApp.InTree.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<!-- This is temporary hack for https://github.com/dotnet/runtime/issues/61294 -->
2929
<ItemGroup>
3030
<_MonoRuntimeComponentDontLink Include="libmono-component-debugger-stub-static.a" />
31-
<_MonoRuntimeComponentDontLink Include="libmono-component-diagnostics_tracing-static.a"/>
3231
<_MonoRuntimeComponentDontLink Include="libmono-component-hot_reload-stub-static.a" />
3332
<_MonoRuntimeComponentDontLink Include="libmono-component-marshal-ilgen-stub-static.a" />
3433
</ItemGroup>

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 (*ds_job_cb)(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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const fn_signatures: SigLine[] = [
4242
[true, "mono_wasm_parse_runtime_options", null, ["number", "number"]],
4343
[true, "mono_wasm_strdup", "number", ["string"]],
4444
[true, "mono_background_exec", null, []],
45+
[true, "mono_wasm_ds_exec", null, []],
4546
[true, "mono_wasm_execute_timer", null, []],
4647
[true, "mono_wasm_load_icu_data", "number", ["number"]],
4748
[false, "mono_wasm_add_assembly", "number", ["string", "number", "number"]],
@@ -166,6 +167,7 @@ export interface t_Cwraps {
166167
mono_wasm_strdup(value: string): number;
167168
mono_wasm_parse_runtime_options(length: number, argv: VoidPtr): void;
168169
mono_background_exec(): void;
170+
mono_wasm_ds_exec(): void;
169171
mono_wasm_execute_timer(): void;
170172
mono_wasm_load_icu_data(offset: VoidPtr): number;
171173
mono_wasm_add_assembly(name: string, data: VoidPtr, size: number): number;

src/mono/browser/runtime/es6/dotnet.es6.lib.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
// because we can't pass custom define symbols to acorn optimizer, we use environment variables to pass other build options
1010
const WASM_ENABLE_SIMD = process.env.WASM_ENABLE_SIMD === "1";
11+
const FEATURE_PERFTRACING = process.env.FEATURE_PERFTRACING === "1";
1112
const WASM_ENABLE_EH = process.env.WASM_ENABLE_EH === "1";
1213
const ENABLE_BROWSER_PROFILER = process.env.ENABLE_BROWSER_PROFILER === "1";
1314
const ENABLE_AOT_PROFILER = process.env.ENABLE_AOT_PROFILER === "1";
@@ -86,6 +87,7 @@ function injectDependencies() {
8687
DotnetSupportLib["$DOTNET__postset"] = `DOTNET.setup({ ` +
8788
`wasmEnableSIMD: ${WASM_ENABLE_SIMD ? "true" : "false"},` +
8889
`wasmEnableEH: ${WASM_ENABLE_EH ? "true" : "false"},` +
90+
`enablePerfTracing: ${FEATURE_PERFTRACING ? "true" : "false"}, ` +
8991
`enableAotProfiler: ${ENABLE_AOT_PROFILER ? "true" : "false"}, ` +
9092
`enableBrowserProfiler: ${ENABLE_BROWSER_PROFILER ? "true" : "false"}, ` +
9193
`enableLogProfiler: ${ENABLE_LOG_PROFILER ? "true" : "false"}, ` +

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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";
1515
import { mono_log_warn, mono_wasm_console_clear, mono_wasm_trace_logger } from "./logging";
16-
import { mono_wasm_profiler_leave, mono_wasm_profiler_enter } from "./profiler";
16+
import { mono_wasm_profiler_leave, mono_wasm_profiler_enter, ds_rt_websocket_close, ds_rt_websocket_create, ds_rt_websocket_poll, ds_rt_websocket_recv, ds_rt_websocket_send } from "./profiler";
1717
import { mono_wasm_browser_entropy } from "./crypto";
1818
import { mono_wasm_cancel_promise } from "./cancelable-promise";
1919

@@ -88,6 +88,13 @@ export const mono_wasm_imports = [
8888
mono_wasm_invoke_jsimport_ST,
8989
mono_wasm_resolve_or_reject_promise,
9090
mono_wasm_cancel_promise,
91+
92+
//event pipe
93+
ds_rt_websocket_create,
94+
ds_rt_websocket_send,
95+
ds_rt_websocket_poll,
96+
ds_rt_websocket_recv,
97+
ds_rt_websocket_close,
9198
];
9299

93100

0 commit comments

Comments
 (0)