Skip to content

Commit

Permalink
[browser] bench - separate scripts for memory snapshot (#93548)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara authored Oct 16, 2023
1 parent cccdc1d commit a30d6c9
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/mono/sample/mbr/browser/WasmDelta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
<Import Project="$(MonoProjectRoot)wasm\build\WasmApp.InTree.targets" />

<Target Name="RunSample" DependsOnTargets="Build">
<Exec Command="$(_Dotnet) serve -o -d:bin/$(Configuration)/AppBundle -p:8000 --mime .mjs=text/javascript" IgnoreExitCode="true" YieldDuringToolExecution="true" />
<Exec Command="$(_Dotnet) serve -S -o -d:bin/$(Configuration)/AppBundle -p:8000 --mime .mjs=text/javascript" IgnoreExitCode="true" YieldDuringToolExecution="true" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<Exec Command="dotnet tool install -g dotnet-serve" IgnoreExitCode="true" />
</Target>
<Target Name="RunSampleWithBrowser" DependsOnTargets="BuildSampleInTree;CheckServe">
<Exec Command="$(_Dotnet) serve -o -d:bin/$(Configuration)/AppBundle -p:8000 $(_ServeMimeTypes) $(_ServeHeaders)" IgnoreExitCode="true" YieldDuringToolExecution="true" />
<Exec Command="$(_Dotnet) serve -S -o -d:bin/$(Configuration)/AppBundle -p:8000 $(_ServeMimeTypes) $(_ServeHeaders)" IgnoreExitCode="true" YieldDuringToolExecution="true" />
</Target>
<Target Name="RunSampleWithBrowserAndSimpleServer" DependsOnTargets="BuildSampleInTree">
<Exec Command="$(_Dotnet) build -c $(Configuration) ..\simple-server\HttpServer.csproj" />
Expand Down
12 changes: 0 additions & 12 deletions src/mono/sample/wasm/blazor-frame/wwwroot/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ try {
window.muteErrors = () => {
mute = true;
}

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('memorySnapshot');

Blazor.start({
configureRuntime: dotnet => {
if (myParam === "true") {
dotnet.withStartupMemoryCache(true);
}
}
});

}
catch (err) {
if (!mute) {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/blazor-frame/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script type="module" src="_framework/blazor.webassembly.js" autostart="false"></script>
<script type="module" src="frame.js"></script>
<script type="module" src="./_framework/blazor.webassembly.js"></script>
<script type="module" src="./frame.js"></script>
</body>

</html>
33 changes: 33 additions & 0 deletions src/mono/sample/wasm/blazor-frame/wwwroot/start.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>blazor</title>
<base href="./" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap-icons/bootstrap-icons.min.css" />
<link rel="stylesheet" href="css/app.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<link href="blazor.styles.css" rel="stylesheet" />
</head>

<body>
<div id="app">
<svg class="loading-progress">
<circle r="40%" cx="50%" cy="50%" />
<circle r="40%" cx="50%" cy="50%" />
</svg>
<div class="loading-progress-text"></div>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script type="module" src="./_framework/blazor.webassembly.js" autostart="false"></script>
<script type="module" src="./start.js"></script>
</body>

</html>
49 changes: 49 additions & 0 deletions src/mono/sample/wasm/blazor-frame/wwwroot/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

"use strict";

class FrameApp {
reachedCallback() {
if (window.parent != window) {
window.parent.resolveAppStartEvent("reached");
}
}
}

let mute = false;
try {
globalThis.frameApp = new FrameApp();
globalThis.frameApp.ReachedCallback = globalThis.frameApp.reachedCallback.bind(globalThis.frameApp);
if (window.parent != window) {
window.addEventListener("pageshow", event => { window.parent.resolveAppStartEvent("pageshow"); })
}

// receive blazor benchmark event and forward it to resolveAppStartEvent
window.receiveBenchmarkEvent = function (name) {
if (window !== window.parent) {
window.parent.resolveAppStartEvent("blazor: " + name);
}
};

window.muteErrors = () => {
mute = true;
}

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('memorySnapshot');

Blazor.start({
configureRuntime: dotnet => {
if (myParam === "true") {
dotnet.withStartupMemoryCache(true);
}
}
});

}
catch (err) {
if (!mute) {
console.error(`WASM ERROR ${err}`);
}
}
3 changes: 2 additions & 1 deletion src/mono/sample/wasm/browser-bench/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class BlazorReachManagedSnapshot : BlazorAppStartMeasurement
public override string Name => "Blazor Reach managed snapshot";
public override int InitialSamples => 3;
public override bool HasRunStepAsync => true;
protected override string FramePage => "start.html?memorySnapshot=true";

public override async Task RunStepAsync()
{
Expand Down Expand Up @@ -224,7 +225,7 @@ class BrowserReachManagedSnapshot : BrowserAppStartMeasurement
public override string Name => "Browser Reach managed snapshot";
public override int InitialSamples => 3;
public override bool HasRunStepAsync => true;
protected override string FramePage => "?memorySnapshot=true";
protected override string FramePage => "start.html?memorySnapshot=true";

public override async Task RunStepAsync()
{
Expand Down
4 changes: 0 additions & 4 deletions src/mono/sample/wasm/browser-frame/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

import { dotnet } from './_framework/dotnet.js'

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('memorySnapshot');

const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withDiagnosticTracing(false)
.withStartupMemoryCache(myParam === "true")
.withApplicationArgumentsFromQuery()
.create();

Expand Down
18 changes: 18 additions & 0 deletions src/mono/sample/wasm/browser-frame/wwwroot/start.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<!-- Licensed to the .NET Foundation under one or more agreements. -->
<!-- The .NET Foundation licenses this file to you under the MIT license. -->
<html>

<head>
<title>browser-frame</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type='module' src="./start.js"></script>
<script type="module" src="./frame.js"></script>
</head>

<body>
<span id="out"></span>
</body>

</html>
29 changes: 29 additions & 0 deletions src/mono/sample/wasm/browser-frame/wwwroot/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { dotnet } from './_framework/dotnet.js'

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('memorySnapshot');

const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withDiagnosticTracing(false)
.withStartupMemoryCache(myParam === "true")
.withApplicationArgumentsFromQuery()
.create();

setModuleImports('main.js', {
window: {
location: {
href: () => globalThis.window.location.href
}
}
});

const config = getConfig();
const exports = await getAssemblyExports(config.mainAssemblyName);
const text = exports.MyClass.Greeting();
console.log(text);

document.getElementById('out').innerHTML = text;
await dotnet.run();
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</Target>

<Target Name="RunSample" DependsOnTargets="WebPack">
<Exec Command="dotnet serve --directory $(WasmAppDir)" WorkingDirectory="$(MSBuildProjectDirectory)"/>
<Exec Command="dotnet serve -S --directory $(WasmAppDir)" WorkingDirectory="$(MSBuildProjectDirectory)"/>
</Target>

</Project>
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/wasm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ run-browser:
echo "The tool dotnet-serve could not be found. Install with: $(DOTNET) tool install --global dotnet-serve"; \
exit 1; \
else \
$(DOTNET) serve -d:bin/$(CONFIG)/AppBundle $(CORS_HEADERS) $(OPEN_BROWSER) -p:8000; \
$(DOTNET) serve -S -d:bin/$(CONFIG)/AppBundle $(CORS_HEADERS) $(OPEN_BROWSER) -p:8000; \
fi

run-console:
Expand Down

0 comments on commit a30d6c9

Please sign in to comment.