Skip to content

Commit d1224fc

Browse files
authored
[wasm][docs] Add docs for using AOT profiler (#47170)
* add instructions for using profiler * [wasm][docs] add link to wasm/build/README.md
1 parent f80b057 commit d1224fc

File tree

1 file changed

+69
-0
lines changed
  • src/mono/netcore/sample/wasm/browser-profile

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## How to run a sample app with AOT profiling enabled
2+
3+
### Setting up a project with profiling
4+
5+
1. Define a `write_at` method. By default it is:
6+
7+
```
8+
[MethodImpl(MethodImplOptions.NoInlining)]
9+
public static void StopProfile(){}
10+
```
11+
12+
2. Initialize the profiler in the main javascript (e.g. runtime.js)
13+
14+
```
15+
var Module = {
16+
onRuntimeInitialized: function () {
17+
...
18+
19+
if (config.enable_profiler)
20+
{
21+
config.aot_profiler_options = {
22+
write_at: "<Namespace.Class::StopProfile>",
23+
send_to: "System.Runtime.InteropServices.JavaScript.Runtime::DumpAotProfileData"
24+
}
25+
}
26+
```
27+
28+
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:
29+
30+
`BINDING.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 `Module.aot_profile_data`
33+
34+
4. Download `Module.aot_profile_data` in JS, using something similar to:
35+
36+
```
37+
function saveProfile() {
38+
var a = document.createElement('a');
39+
var blob = new Blob([Module.aot_profile_data]);
40+
a.href = URL.createObjectURL(blob);
41+
a.download = "data.aotprofile";
42+
// Append anchor to body.
43+
document.body.appendChild(a);
44+
a.click();
45+
46+
// Remove anchor from body
47+
document.body.removeChild(a);
48+
}
49+
```
50+
51+
### Build and Run a project with profiling
52+
1. To enable profiling during a build, we need to make use of WasmApp.InTree.targets/props by importing into the project file:
53+
54+
`<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/build/README.md)
58+
59+
2. To get the profile data, run:
60+
61+
`make get-aot-profile`
62+
63+
Which will build and run the current project with AOT disabled and the AOT profiler enabled.
64+
65+
3. Go to localhost:8000 and the profile will automatically download.
66+
67+
4. To use the profile data in the project, run:
68+
69+
`make use-aot-profile PROFILE_PATH=<path to profile file>`

0 commit comments

Comments
 (0)