README.md 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
## 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(){}
```

12
2. Initialize the profiler in the main javascript (e.g. main.js)
13 14 15

```
var Module = {
16
  onConfigLoaded: () => {
17
    ...
18

19 20 21 22 23 24 25 26 27 28 29
    if (config.enable_profiler)
    {
      config.aot_profiler_options = {
        write_at: "<Namespace.Class::StopProfile>",
        send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
    }
  }
```

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:

30
`INTERNAL.call_static_method("<[ProjectName] Namespace.Class::StopProfile">, []);`
31

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

34
4. Download `INTERNAL.aot_profile_data` in JS, using something similar to:
35 36 37 38

```
function saveProfile() {
  var a = document.createElement('a');
39
  var blob = new Blob([INTERNAL.aot_profile_data]);
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  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" />` <br/>
55
`<Import Project="$(MonoProjectRoot)wasm\build\WasmApp.InTree.props" />`
56

57
For more information on how to utilize WasmApp.InTree.targets/props consult the wasm build directory [README.md](../../../wasm/README.md)
58

59
2. To get the profile data, run:
60 61 62 63 64

`make get-aot-profile`

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

65
3. Go to localhost:8000 and the profile will automatically download.
66 67 68 69

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

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