From c183e93b80f88d49b47bb48ff3116b371037e8d4 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 22 Feb 2022 08:32:09 -0800 Subject: [PATCH] x64: enable VTune support by default (#3821) * x64: enable VTune support by default After significant work in the `ittapi-rs` crate, this dependency should build without issue on Wasmtime's supported operating systems: Windows, Linux, and macOS. The difference in the release binary is <20KB, so this change makes `vtune` a default build feature. This change upgrades `ittapi-rs` to v0.2.0 and updates the documentation. * review: add configuration for defaults in more places * review: remove OS conditional compilation, add architecture * review: do not default vtune feature in wasmtime-jit --- Cargo.lock | 4 ++-- Cargo.toml | 1 + crates/jit/Cargo.toml | 2 +- crates/jit/src/profiling.rs | 4 ++-- .../jit/src/profiling/{vtune_linux.rs => vtune.rs} | 10 +++------- crates/wasmtime/Cargo.toml | 1 + crates/wasmtime/src/lib.rs | 4 ++-- docs/examples-profiling-vtune.md | 13 +++++-------- docs/examples-profiling.md | 12 ++++++++---- 9 files changed, 25 insertions(+), 26 deletions(-) rename crates/jit/src/profiling/{vtune_linux.rs => vtune.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index ea52ae6aeb..c3c97d1e63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1497,9 +1497,9 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "ittapi-rs" -version = "0.1.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265ed25cd5b53e9b02bf97a1f66ab7af1af7ab61f5d9ce1e05aeaed098723658" +checksum = "f712648a1ad72fbfb7adc2772c331e8d90f022f8cf30cbabefba2878dd3172b0" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 1938792fb8..06184baafc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,6 +95,7 @@ default = [ "jitdump", "wasmtime/wat", "wasmtime/parallel-compilation", + "vtune", "wasi-nn", "pooling-allocator", "memfd", diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index 8da6d75502..44c52dc306 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -22,7 +22,7 @@ gimli = { version = "0.26.0", default-features = false, features = ["std", "read object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "elf"] } serde = { version = "1.0.94", features = ["derive"] } addr2line = { version = "0.17.0", default-features = false } -ittapi-rs = { version = "0.1.6", optional = true } +ittapi-rs = { version = "0.2.0", optional = true } bincode = "1.2.1" rustc-demangle = "0.1.16" cpp_demangle = "0.3.2" diff --git a/crates/jit/src/profiling.rs b/crates/jit/src/profiling.rs index e6fefcccdf..b9741fa36f 100644 --- a/crates/jit/src/profiling.rs +++ b/crates/jit/src/profiling.rs @@ -12,8 +12,8 @@ cfg_if::cfg_if! { } cfg_if::cfg_if! { - if #[cfg(all(feature = "vtune", target_os = "linux"))] { - #[path = "profiling/vtune_linux.rs"] + if #[cfg(all(feature = "vtune", target_arch = "x86_64"))] { + #[path = "profiling/vtune.rs"] mod vtune; } else { #[path = "profiling/vtune_disabled.rs"] diff --git a/crates/jit/src/profiling/vtune_linux.rs b/crates/jit/src/profiling/vtune.rs similarity index 96% rename from crates/jit/src/profiling/vtune_linux.rs rename to crates/jit/src/profiling/vtune.rs index 8f236ea4d1..2e6f0eebf6 100644 --- a/crates/jit/src/profiling/vtune_linux.rs +++ b/crates/jit/src/profiling/vtune.rs @@ -1,10 +1,6 @@ -//! Adds support for profiling JIT-ed code using VTune. -//! -//! ### Build -//! -//! ```ignore -//! cargo build --features=vtune -//! ``` +//! Adds support for profiling JIT-ed code using VTune. By default, VTune +//! support is built in to Wasmtime (configure with the `vtune` feature flag). +//! To enable it at runtime, use the `--vtune` CLI flag. //! //! ### Profile //! diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index f49343d66a..51ef1cdfde 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -60,6 +60,7 @@ default = [ 'cranelift', 'pooling-allocator', 'memfd', + 'vtune', ] # An on-by-default feature enabling runtime compilation of WebAssembly modules diff --git a/crates/wasmtime/src/lib.rs b/crates/wasmtime/src/lib.rs index a67d7dda4f..7e8cd20e7e 100644 --- a/crates/wasmtime/src/lib.rs +++ b/crates/wasmtime/src/lib.rs @@ -262,8 +262,8 @@ //! jitdump runtime profiling format. The profiler can be selected with //! [`Config::profiler`]. //! -//! * `vtune` - Not enabled by default, this feature compiles in support for -//! supporting VTune profiling of JIT code. +//! * `vtune` - Enabled by default, this feature compiles in support for VTune +//! profiling of JIT code. //! //! * `uffd` - Not enabled by default. This feature enables `userfaultfd` support //! when using the pooling instance allocator. As handling page faults in user space diff --git a/docs/examples-profiling-vtune.md b/docs/examples-profiling-vtune.md index 385b8edd08..ff945a8991 100644 --- a/docs/examples-profiling-vtune.md +++ b/docs/examples-profiling-vtune.md @@ -30,13 +30,10 @@ For more information on VTune and the analysis tools it provides see its ### Turn on VTune support -For JIT profiling with VTune, first build with the `vtune` feature enabled: - -```sh -$ cargo build --features=vtune -``` - -Then, enable runtime support based on how you use Wasmtime: +For JIT profiling with VTune, Wasmtime currently builds with the `vtune` feature +enabled by default. This ensures the compiled binary understands how to inform +the `ittapi` library of JIT events. But it must still be enabled at +runtime--enable runtime support based on how you use Wasmtime: * **Rust API** - call the [`Config::profiler`] method with `ProfilingStrategy::VTune` to enable profiling of your wasm modules. @@ -62,7 +59,7 @@ future. With VTune [properly installed][download], if you are using the CLI execute: ```sh -$ cargo build --features=vtune +$ cargo build $ vtune -run-pass-thru=--no-altstack -collect hotspots target/debug/wasmtime --vtune foo.wasm ``` diff --git a/docs/examples-profiling.md b/docs/examples-profiling.md index 1c5136cc7c..d040dc27ba 100644 --- a/docs/examples-profiling.md +++ b/docs/examples-profiling.md @@ -1,9 +1,13 @@ # Profiling WebAssembly One of WebAssembly's major goals is to be quite close to native code in terms of -performance, so typically when executing wasm you'll be quite interested in how -well your wasm module is performing! From time to time you might want to dive a -bit deeper into the performance of your wasm, and this is where profiling comes +performance, so typically when executing Wasm you'll be quite interested in how +well your Wasm module is performing! From time to time you might want to dive a +bit deeper into the performance of your Wasm, and this is where profiling comes into the picture. -Profiling support in Wasmtime is still under development, but if you're using either [perf](./examples-profiling-perf.md) or [Vtune](./examples-profiling-vtune.md) the examples in these sections are targeted at helping you get some information about the performance of your wasm modules. +Profiling support in Wasmtime is still under development, but if you're using +either [perf](./examples-profiling-perf.md) or +[VTune](./examples-profiling-vtune.md) the examples in these sections are +targeted at helping you get some information about the performance of your Wasm +modules.