Skip to content

Commit e9230b8

Browse files
jeromelabanpavelsavarailonatommy
authored andcommitted
[wasm] Enable the log profiler (dotnet#107434)
* feat(wasm): Enable the log profiler * chore: Disable for wasi * chore: Add log profiler docs * chore: Adjust flush logs syntax * chore: Adjust defines, add conditionals, remove Module dependency * chore: Adjust buffer_unlock exclusion * chore: Adjust doc * chore: Add log profiler sample * chore: Add more sample logging * chore: Remove unused makefile target * chore: Remove icall, use jit interception to take heap sot * chore: Remove unused logs * chore: Remove unused dependency * Revert "chore: Remove unused dependency" This reverts commit 33221c4. * remove ENABLE_BROWSER_PROFILER from default build * Draft of WBT. * Miss-commit, there's no profiler.js in the sample. * Shift the responsibility of checking profile's size to the browser. * Test linking of all 3 types of loggers + running one of them. * link all 3 at the same time * fix [Fact] * Treat a list of loggers as one argument. Avoid "MSBUILD : error MSB1005: Specify a property and its value." * fix? --------- Co-authored-by: pavelsavara <[email protected]> Co-authored-by: Ilona Tomkowicz <[email protected]> Co-authored-by: Ilona Tomkowicz <[email protected]> Co-authored-by: Pavel Savara <[email protected]>
1 parent e74cfd9 commit e9230b8

File tree

29 files changed

+426
-8
lines changed

29 files changed

+426
-8
lines changed

src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
<PlatformManifestFileEntry Include="libmono-ee-interp.a" IsNative="true" />
221221
<PlatformManifestFileEntry Include="libmono-icall-table.a" IsNative="true" />
222222
<PlatformManifestFileEntry Include="libmono-profiler-aot.a" IsNative="true" />
223+
<PlatformManifestFileEntry Include="libmono-profiler-log.a" IsNative="true" />
223224
<PlatformManifestFileEntry Include="libmono-profiler-browser.a" IsNative="true" />
224225
<PlatformManifestFileEntry Include="libmono-wasm-eh-js.a" IsNative="true" />
225226
<PlatformManifestFileEntry Include="libmono-wasm-eh-wasm.a" IsNative="true" />

src/mono/browser/browser.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@
385385
<PInvokeTableFile>$(ArtifactsObjDir)wasm/pinvoke-table.h</PInvokeTableFile>
386386
<InterpToNativeTableFile>$(ArtifactsObjDir)wasm/wasm_m2n_invoke.g.h</InterpToNativeTableFile>
387387

388-
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
389-
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz -DENABLE_BROWSER_PROFILER=1</CMakeConfigurationEmccFlags>
388+
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Debug'">-g -Os -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -DENABLE_BROWSER_PROFILER=1 -DENABLE_LOG_PROFILER=1</CMakeConfigurationEmccFlags>
389+
<CMakeConfigurationEmccFlags Condition="'$(Configuration)' == 'Release'">-Oz</CMakeConfigurationEmccFlags>
390390

391391
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 </CMakeConfigurationLinkFlags>
392392
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>

src/mono/browser/build/BrowserWasmApp.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
<_EmccCFlags Include="-DLINK_ICALLS=1" Condition="'$(WasmLinkIcalls)' == 'true'" />
315315
<_EmccCFlags Include="-DENABLE_AOT_PROFILER=1" Condition="$(WasmProfilers.Contains('aot'))" />
316316
<_EmccCFlags Include="-DENABLE_BROWSER_PROFILER=1" Condition="$(WasmProfilers.Contains('browser'))" />
317+
<_EmccCFlags Include="-DENABLE_LOG_PROFILER=1" Condition="$(WasmProfilers.Contains('log'))" />
317318
<_EmccCFlags Include="-DENABLE_JS_INTEROP_BY_VALUE=1" Condition="'$(WasmEnableJsInteropByValue)' == 'true'" />
318319

319320
<_EmccCFlags Include="-DGEN_PINVOKE=1" />
@@ -368,6 +369,7 @@
368369
<EmscriptenEnvVars Include="WASM_ENABLE_EH=0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
369370
<EmscriptenEnvVars Include="ENABLE_AOT_PROFILER=$([System.Convert]::ToInt32($(WasmProfilers.Contains('aot'))))" />
370371
<EmscriptenEnvVars Include="ENABLE_BROWSER_PROFILER=$([System.Convert]::ToInt32($(WasmProfilers.Contains('browser'))))" />
372+
<EmscriptenEnvVars Include="ENABLE_LOG_PROFILER=$([System.Convert]::ToInt32($(WasmProfilers.Contains('log'))))" />
371373
<EmscriptenEnvVars Include="RUN_AOT_COMPILATION=1" Condition="'$(RunAOTCompilation)' == 'true'" />
372374
<EmscriptenEnvVars Include="RUN_AOT_COMPILATION=0" Condition="'$(RunAOTCompilation)' != 'true'" />
373375

src/mono/browser/runtime/cwraps.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ const fn_signatures: SigLine[] = [
6565
[false, "mono_wasm_exit", "void", ["number"]],
6666
[true, "mono_wasm_getenv", "number", ["string"]],
6767
[true, "mono_wasm_set_main_args", "void", ["number", "number"]],
68-
// These two need to be lazy because they may be missing
68+
// These three need to be lazy because they may be missing
6969
[() => !runtimeHelpers.emscriptenBuildOptions.enableAotProfiler, "mono_wasm_profiler_init_aot", "void", ["string"]],
7070
[() => !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_wasm_profiler_init_browser", "void", ["string"]],
71+
[() => !runtimeHelpers.emscriptenBuildOptions.enableLogProfiler, "mono_wasm_profiler_init_log", "void", ["string"]],
7172
[true, "mono_wasm_profiler_init_browser", "void", ["number"]],
7273
[false, "mono_wasm_exec_regression", "number", ["number", "string"]],
7374
[false, "mono_wasm_invoke_jsexport", "void", ["number", "number"]],
@@ -165,6 +166,7 @@ export interface t_ThreadingCwraps {
165166
export interface t_ProfilerCwraps {
166167
mono_wasm_profiler_init_aot(desc: string): void;
167168
mono_wasm_profiler_init_browser(desc: string): void;
169+
mono_wasm_profiler_init_log(desc: string): void;
168170
}
169171

170172
export interface t_Cwraps {

src/mono/browser/runtime/driver.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ mono_wasm_profiler_init_browser (const char *desc)
430430

431431
#endif
432432

433+
#ifdef ENABLE_LOG_PROFILER
434+
435+
void mono_profiler_init_log (const char *desc);
436+
437+
EMSCRIPTEN_KEEPALIVE void
438+
mono_wasm_profiler_init_log (const char *desc)
439+
{
440+
mono_profiler_init_log (desc);
441+
}
442+
443+
#endif
444+
433445
EMSCRIPTEN_KEEPALIVE void
434446
mono_wasm_init_finalizer_thread (void)
435447
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const WASM_ENABLE_SIMD = process.env.WASM_ENABLE_SIMD === "1";
1111
const WASM_ENABLE_EH = process.env.WASM_ENABLE_EH === "1";
1212
const ENABLE_BROWSER_PROFILER = process.env.ENABLE_BROWSER_PROFILER === "1";
1313
const ENABLE_AOT_PROFILER = process.env.ENABLE_AOT_PROFILER === "1";
14+
const ENABLE_LOG_PROFILER = process.env.ENABLE_LOG_PROFILER === "1";
1415
const RUN_AOT_COMPILATION = process.env.RUN_AOT_COMPILATION === "1";
1516
var methodIndexByName = undefined;
1617
var gitHash = undefined;
@@ -88,6 +89,7 @@ function injectDependencies() {
8889
`wasmEnableEH: ${WASM_ENABLE_EH ? "true" : "false"},` +
8990
`enableAotProfiler: ${ENABLE_AOT_PROFILER ? "true" : "false"}, ` +
9091
`enableBrowserProfiler: ${ENABLE_BROWSER_PROFILER ? "true" : "false"}, ` +
92+
`enableLogProfiler: ${ENABLE_LOG_PROFILER ? "true" : "false"}, ` +
9193
`runAOTCompilation: ${RUN_AOT_COMPILATION ? "true" : "false"}, ` +
9294
`wasmEnableThreads: ${USE_PTHREADS ? "true" : "false"}, ` +
9395
`gitHash: "${gitHash}", ` +

src/mono/browser/runtime/profiler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import { ENVIRONMENT_IS_WEB, mono_assert, runtimeHelpers } from "./globals";
5-
import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions } from "./types/internal";
5+
import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions, LogProfilerOptions } from "./types/internal";
66
import { profiler_c_functions as cwraps } from "./cwraps";
77
import { utf8ToString } from "./strings";
88

@@ -34,6 +34,12 @@ export function mono_wasm_init_browser_profiler (options: BrowserProfilerOptions
3434
cwraps.mono_wasm_profiler_init_browser(arg);
3535
}
3636

37+
export function mono_wasm_init_log_profiler (options: LogProfilerOptions): void {
38+
mono_assert(runtimeHelpers.emscriptenBuildOptions.enableLogProfiler, "Log profiler is not enabled, please use <WasmProfilers>log;</WasmProfilers> in your project file.");
39+
mono_assert(options.takeHeapshot, "Log profiler is not enabled, the takeHeapshot method must be defined in LogProfilerOptions.takeHeapshot");
40+
cwraps.mono_wasm_profiler_init_log( (options.configuration || "log:alloc,output=output.mlpd") + `,take-heapshot-method=${options.takeHeapshot}`);
41+
}
42+
3743
export const enum MeasuredBlock {
3844
emscriptenStartup = "mono.emscriptenStartup",
3945
instantiateWasm = "mono.instantiateWasm",

src/mono/browser/runtime/startup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { exportedRuntimeAPI, INTERNAL, loaderHelpers, Module, runtimeHelpers, cr
99
import cwraps, { init_c_exports, threads_c_functions as tcwraps } from "./cwraps";
1010
import { mono_wasm_raise_debug_event, mono_wasm_runtime_ready } from "./debug";
1111
import { toBase64StringImpl } from "./base64";
12-
import { mono_wasm_init_aot_profiler, mono_wasm_init_browser_profiler } from "./profiler";
12+
import { mono_wasm_init_aot_profiler, mono_wasm_init_browser_profiler, mono_wasm_init_log_profiler } from "./profiler";
1313
import { initialize_marshalers_to_cs } from "./marshal-to-cs";
1414
import { initialize_marshalers_to_js } from "./marshal-to-js";
1515
import { init_polyfills_async } from "./polyfills";
@@ -544,6 +544,9 @@ export async function start_runtime () {
544544
if (runtimeHelpers.config.browserProfilerOptions)
545545
mono_wasm_init_browser_profiler(runtimeHelpers.config.browserProfilerOptions);
546546

547+
if (runtimeHelpers.config.logProfilerOptions)
548+
mono_wasm_init_log_profiler(runtimeHelpers.config.logProfilerOptions);
549+
547550
if (WasmEnableThreads) {
548551
// this is not mono-attached thread, so we can start it earlier
549552
await mono_wasm_init_diagnostics();

src/mono/browser/runtime/types/internal.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export type MonoConfigInternal = MonoConfig & {
7777
assets?: AssetEntryInternal[],
7878
runtimeOptions?: string[], // array of runtime options as strings
7979
aotProfilerOptions?: AOTProfilerOptions, // dictionary-style Object. If omitted, aot profiler will not be initialized.
80+
logProfilerOptions?: LogProfilerOptions, // dictionary-style Object. If omitted, log profiler will not be initialized.
8081
browserProfilerOptions?: BrowserProfilerOptions, // dictionary-style Object. If omitted, browser profiler will not be initialized.
8182
waitForDebugger?: number,
8283
appendElementOnExit?: boolean
@@ -274,6 +275,11 @@ export type AOTProfilerOptions = {
274275
export type BrowserProfilerOptions = {
275276
}
276277

278+
export type LogProfilerOptions = {
279+
takeHeapshot?: string,
280+
configuration?: string // log profiler options string"
281+
}
282+
277283
// how we extended emscripten Module
278284
export type DotnetModule = EmscriptenModule & DotnetModuleConfig;
279285
export type DotnetModuleInternal = EmscriptenModule & DotnetModuleConfig & EmscriptenModuleInternal;
@@ -290,6 +296,7 @@ export type EmscriptenBuildOptions = {
290296
wasmEnableEH: boolean,
291297
enableAotProfiler: boolean,
292298
enableBrowserProfiler: boolean,
299+
enableLogProfiler: boolean,
293300
runAOTCompilation: boolean,
294301
wasmEnableThreads: boolean,
295302
gitHash: string,

src/mono/mono.proj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ JS_ENGINES = [NODE_JS]
11851185
<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-aot.a">
11861186
<Destination>$(RuntimeBinDir)libmono-profiler-aot.a</Destination>
11871187
</_MonoRuntimeArtifacts>
1188+
<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-log.a">
1189+
<Destination>$(RuntimeBinDir)libmono-profiler-log.a</Destination>
1190+
</_MonoRuntimeArtifacts>
11881191
<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-browser.a">
11891192
<Destination>$(RuntimeBinDir)libmono-profiler-browser.a</Destination>
11901193
</_MonoRuntimeArtifacts>

0 commit comments

Comments
 (0)