13b7cb6eeSAlex Crichton# Profiling WebAssembly
23b7cb6eeSAlex Crichton
33b7cb6eeSAlex CrichtonOne of WebAssembly's major goals is to be quite close to native code in terms of
4c183e93bSAndrew Brownperformance, so typically when executing Wasm you'll be quite interested in how
5c183e93bSAndrew Brownwell your Wasm module is performing! From time to time you might want to dive a
6c183e93bSAndrew Brownbit deeper into the performance of your Wasm, and this is where profiling comes
73b7cb6eeSAlex Crichtoninto the picture.
83b7cb6eeSAlex Crichton
91b99b1faSJamey SharpFor best results, ideally you'd use hardware performance counters for your
101b99b1faSJamey Sharptiming measurements. However, that requires special support from your CPU and
111b99b1faSJamey Sharpoperating system. Because Wasmtime is a JIT, that also requires hooks from
121b99b1faSJamey SharpWasmtime to your platform's native profiling tools.
131b99b1faSJamey Sharp
141b99b1faSJamey SharpAs a result, Wasmtime support for native profiling is limited to certain
151b99b1faSJamey Sharpplatforms. See the following sections of this book if you're using these
161b99b1faSJamey Sharpplatforms:
171b99b1faSJamey Sharp
181b99b1faSJamey Sharp- On Linux, we support [perf](./examples-profiling-perf.md).
191b99b1faSJamey Sharp
201b99b1faSJamey Sharp- For Intel's x86 CPUs on Linux or Windows, we support
211b99b1faSJamey Sharp  [VTune](./examples-profiling-vtune.md).
221b99b1faSJamey Sharp
23*310e6677SRik Huijzer- For Linux and macOS, we support [samply](./examples-profiling-samply.md).
24*310e6677SRik Huijzer
25*310e6677SRik Huijzer- For everything else, see the [cross-platform
26*310e6677SRik Huijzer  profiler](./examples-profiling-guest.md).
271b99b1faSJamey Sharp
281b99b1faSJamey SharpThe native profilers can measure time spent in WebAssembly guest code as well as
291b99b1faSJamey Sharptime spent in the Wasmtime host and potentially even time spent in the kernel.
301b99b1faSJamey SharpThis provides a comprehensive view of performance.
311b99b1faSJamey Sharp
32*310e6677SRik HuijzerThe cross-platform-profiler can only measure time spent in WebAssembly guest
33*310e6677SRik Huijzercode, and its timing measurements are not as precise as the native profilers.
34*310e6677SRik HuijzerHowever, it works on every platform that Wasmtime supports.
35*310e6677SRik Huijzer
36