1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 03:27:04 +09:00
Satori/src/mono/sample/wasm/browser-profile/README.md
Youssef Victor 5d5c3e7a58
Enable markdownlint rule (MD009) (#40887)
* Create markdownlint.yml

* Create markdownlint-problem-matcher.json

* Create .markdownlint.json

* Update .markdownlint.json

* fix violations

* fixes

* Remove "push" section

As advised by @viktorhofer so it's quite clear it only runs in CI.

Co-authored-by: Dan Moseley <danmose@microsoft.com>
2021-02-08 10:43:40 -08:00

2.1 KiB

How to run a sample app with AOT profiling enabled

Setting up a project with profiling

  1. Define a write_at method. By default it is:
[MethodImpl(MethodImplOptions.NoInlining)]
 public static void StopProfile(){}
  1. Initialize the profiler in the main javascript (e.g. runtime.js)
var Module = {
  onRuntimeInitialized: function () {
    ...

    if (config.enable_profiler)
    {
      config.aot_profiler_options = {
        write_at: "<Namespace.Class::StopProfile>",
        send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
    }
  }
  1. 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.call_static_method("<[ProjectName] Namespace.Class::StopProfile">, []);

When the write_at method is called, the send_to method DumpAotProfileData stores the profile data into Module.aot_profile_data

  1. Download Module.aot_profile_data in JS, using something similar to:
function saveProfile() {
  var a = document.createElement('a');
  var blob = new Blob([Module.aot_profile_data]);
  a.href = URL.createObjectURL(blob);
  a.download = "data.aotprofile";
  // Append anchor to body.
  document.body.appendChild(a);
  a.click();

  // Remove anchor from body
  document.body.removeChild(a);
}

Build and Run a project with profiling

  1. To enable profiling during a build, we need to make use of WasmApp.InTree.targets/props by importing into the project file:

<Import Project="$(MonoProjectRoot)\wasm\build\WasmApp.InTree.targets" />
<Import Project="$(MonoProjectRoot)wasm\build\WasmApp.InTree.props" />

For more information on how to utilize WasmApp.InTree.targets/props consult the wasm build directory README.md

  1. To get the profile data, run:

make get-aot-profile

Which will build and run the current project with AOT disabled and the AOT profiler enabled.

  1. Go to localhost:8000 and the profile will automatically download.

  2. To use the profile data in the project, run:

make use-aot-profile PROFILE_PATH=<path to profile file>