Skip to content
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
18 changes: 10 additions & 8 deletions src/mono/sample/mbr/browser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;
using MonoDelta;

namespace Sample
{
public class Test
public partial class Test
{
static DeltaHelper replacer = DeltaHelper.Make ();
static DeltaHelper replacer = DeltaHelper.Make ();

public static void Main(string[] args)
{
Console.WriteLine ("Hello, World!");
}

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static int TestMeaning()
{
return 42;
}

public static void Update()
{
Assembly assm = typeof (Test).Assembly;
replacer.Update (assm);
}
[JSExport]
public static void Update()
{
Assembly assm = typeof (Test).Assembly;
replacer.Update (assm);
}
}
}
18 changes: 10 additions & 8 deletions src/mono/sample/mbr/browser/Program_v1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;
using MonoDelta;

namespace Sample
{
public class Test
public partial class Test
{
static DeltaHelper replacer = DeltaHelper.Make ();
static DeltaHelper replacer = DeltaHelper.Make ();

public static void Main(string[] args)
{
Console.WriteLine ("Hello, World!");
}

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static int TestMeaning()
{
return 43;
}

public static void Update()
{
Assembly assm = typeof (Test).Assembly;
replacer.Update (assm);
}
[JSExport]
public static void Update()
{
Assembly assm = typeof (Test).Assembly;
replacer.Update (assm);
}
}
}
18 changes: 10 additions & 8 deletions src/mono/sample/mbr/browser/Program_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;
using MonoDelta;

namespace Sample
{
public class Test
public partial class Test
{
static DeltaHelper replacer = DeltaHelper.Make ();
static DeltaHelper replacer = DeltaHelper.Make ();

public static void Main(string[] args)
{
Console.WriteLine ("Hello, World!");
}

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static int TestMeaning()
{
return 128;
}

public static void Update()
{
Assembly assm = typeof (Test).Assembly;
replacer.Update (assm);
}
[JSExport]
public static void Update()
{
Assembly assm = typeof (Test).Assembly;
replacer.Update (assm);
}
}
}
5 changes: 5 additions & 0 deletions src/mono/sample/mbr/browser/WasmDelta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@
<Target Name="RunSample" DependsOnTargets="Build">
<Exec Command="$(_Dotnet) serve -o -d:bin/$(Configuration)/AppBundle -p:8000 --mime .mjs=text/javascript" IgnoreExitCode="true" YieldDuringToolExecution="true" />
</Target>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
11 changes: 7 additions & 4 deletions src/mono/sample/mbr/browser/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import createDotnetRuntime from './dotnet.js'

try {
const { BINDING } = await createDotnetRuntime(({ MONO }) => ({
const { getAssemblyExports } = await createDotnetRuntime({
configSrc: "./mono-config.json",
onConfigLoaded: (config) => {
config.environmentVariables["DOTNET_MODIFIABLE_ASSEMBLIES"] = "debug";
},
}));
const update = BINDING.bind_static_method("[WasmDelta] Sample.Test:Update");
const testMeaning = BINDING.bind_static_method("[WasmDelta] Sample.Test:TestMeaning");
});

const exports = await getAssemblyExports("WasmDelta.dll");
const update = exports.Sample.Test.Update;
const testMeaning = exports.Sample.Test.TestMeaning;

const outElement = document.getElementById("out");
document.getElementById("update").addEventListener("click", function () {
update();
Expand Down
1 change: 0 additions & 1 deletion src/mono/sample/wasm/browser-bench/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public partial class FrameApp
[JSImport("globalThis.frameApp.ReachedCallback")]
public static partial Task ReachedCallback();

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static void ReachedManaged()
{
Expand Down
3 changes: 0 additions & 3 deletions src/mono/sample/wasm/browser-bench/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public partial class Test
static Test instance = new Test();
Formatter formatter = new HTMLFormatter();

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static Task<string> RunBenchmark()
{
return instance.RunTasks();
}

[MethodImpl(MethodImplOptions.NoInlining)]
// the constructors of the task we care about are already used when createing tasks field
[UnconditionalSuppressMessage("Trim analysis error", "IL2057")]
[UnconditionalSuppressMessage("Trim analysis error", "IL2072")]
Expand Down Expand Up @@ -76,7 +74,6 @@ public static void SetTasks(string taskNames)
}

[JSExport]
[MethodImpl(MethodImplOptions.NoInlining)]
public static string GetFullJsonResults()
{
return instance.GetJsonResults();
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/browser-bench/frame-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ try {
mute = true;
}

const runtime = await createDotnetRuntime(() => ({
const runtime = await createDotnetRuntime({
disableDotnet6Compatibility: true,
configSrc: "./mono-config.json",
printErr: function () {
Expand All @@ -47,7 +47,7 @@ try {
onAbort: (error) => {
wasm_exit(1, error);
},
}));
});

if (window.parent != window) {
window.parent.resolveAppStartEvent("onDotnetReady");
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/browser-bench/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ try {
globalThis.mainApp.FrameReachedManaged = globalThis.mainApp.frameReachedManaged.bind(globalThis.mainApp);
globalThis.mainApp.PageShow = globalThis.mainApp.pageShow.bind(globalThis.mainApp);

const runtime = await createDotnetRuntime(() => ({
const runtime = await createDotnetRuntime({
disableDotnet6Compatibility: true,
configSrc: "./mono-config.json",
onAbort: (error) => {
wasm_exit(1, error);
}
}));
});
await mainApp.init(runtime);
}
catch (err) {
Expand Down
6 changes: 5 additions & 1 deletion src/mono/sample/wasm/browser-eventpipe/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics.Tracing;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void StopFib(int n, string result)
}
}

public class Test
public partial class Test
{
public static void Main(string[] args)
{
Expand Down Expand Up @@ -104,6 +105,7 @@ public static void Meth() {
}
#endif

[JSExport]
public static async Task<double> StartAsyncWork(int N)
{
CancellationToken ct = GetCancellationToken();
Expand Down Expand Up @@ -133,11 +135,13 @@ public static async Task<double> StartAsyncWork(int N)
}
}

[JSExport]
public static void StopWork()
{
cts.Cancel();
}

[JSExport]
public static string GetIterationsDone()
{
return iterations.ToString();
Expand Down
16 changes: 4 additions & 12 deletions src/mono/sample/wasm/browser-eventpipe/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,17 @@ function getOnClickHandler(startWork, stopWork, getIterationsDone) {
}

async function main() {
const { MONO, BINDING, Module } = await createDotnetRuntime(() => {
return {
disableDotnet6Compatibility: true,
configSrc: "./mono-config.json",
}
const { MONO, Module, getAssemblyExports } = await createDotnetRuntime({
configSrc: "./mono-config.json",
});
globalThis.__Module = Module;
globalThis.MONO = MONO;

const startWork = BINDING.bind_static_method("[Wasm.Browser.EventPipe.Sample] Sample.Test:StartAsyncWork");
const stopWork = BINDING.bind_static_method("[Wasm.Browser.EventPipe.Sample] Sample.Test:StopWork");
const getIterationsDone = BINDING.bind_static_method("[Wasm.Browser.EventPipe.Sample] Sample.Test:GetIterationsDone");

const exports = await getAssemblyExports("Wasm.Browser.EventPipe.Sample.dll");

const btn = document.getElementById("startWork");

btn.style.backgroundColor = "rgb(192,255,192)";
btn.onclick = getOnClickHandler(startWork, stopWork, getIterationsDone);

btn.onclick = getOnClickHandler(exports.Sample.Test.StartAsyncWork, exports.Sample.Test.StopWork, exports.Sample.Test.GetIterationsDone);
}

main();
4 changes: 3 additions & 1 deletion src/mono/sample/wasm/browser-nextjs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;

namespace Sample
{
public class Test
public partial class Test
{
[JSExport]
public static int Main()
{
return 42;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ async function dotnetMeaning() {
if (!dotnetRuntimePromise) {
dotnetRuntimePromise = createRuntime();
}
const { BINDING } = await dotnetRuntimePromise;
meaningFunction = BINDING.bind_static_method("[Wasm.Browser.NextJs.Sample] Sample.Test:Main");
return meaningFunction();
const { getAssemblyExports } = await dotnetRuntimePromise;
const exports = await getAssemblyExports("Wasm.Browser.NextJs.Sample.dll");
return exports.Sample.Test.Main();
}

export default function DeepThought() {
Expand Down
7 changes: 4 additions & 3 deletions src/mono/sample/wasm/browser-profile/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.JavaScript;

namespace Sample
{
public class Test
public partial class Test
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello, World!");
}

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static int TestMeaning()
{
return 42;
}

[MethodImpl(MethodImplOptions.NoInlining)]
[JSExport]
public static void StopProfile(){}
}
}
12 changes: 8 additions & 4 deletions src/mono/sample/wasm/browser-profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
1. Define a `write_at` method. By default it is:

```
[JSExport]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void StopProfile(){}
public static void StopProfile(){}
```

2. Initialize the profiler in the main javascript (e.g. main.js)

```
await createDotnetRuntime(() => ({
await createDotnetRuntime({
onConfigLoaded: () => {
if (config.enableProfiler) {
config.aotProfilerOptions = {
Expand All @@ -21,12 +22,15 @@ await createDotnetRuntime(() => ({
}
}
},
}));
});
```

3. Call the `write_at` method at the end of the app, either in C# or in JS. To call the `write_at` method in JS, make use of bindings:

`BINDING.bind_static_method("<[ProjectName] Namespace.Class::StopProfile">)();`
```
const exports = await getAssemblyExports("<ProjectName>");
exports.<Namespace.Class.StopProfile>();
```

When the `write_at` method is called, the `send_to` method `DumpAotProfileData` stores the profile data into `INTERNAL.aotProfileData`

Expand Down
Loading