Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion client/executor/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ sp-wasm-interface = { version = "4.0.0-dev", path = "../../../primitives/wasm-in
sp-runtime-interface = { version = "4.0.0-dev", path = "../../../primitives/runtime-interface" }
sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" }
sc-allocator = { version = "4.0.0-dev", path = "../../allocator" }
wasmtime = { version = "0.29.0", default-features = false, features = ["cache", "parallel-compilation"] }
wasmtime = { version = "0.29.0", default-features = false, features = [
"cache",
"jitdump",
"parallel-compilation",
] }

[dev-dependencies]
sc-runtime-test = { version = "2.0.0", path = "../runtime-test" }
Expand Down
12 changes: 11 additions & 1 deletion client/executor/wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

/// ! Defines a `WasmRuntime` that uses the Wasmtime JIT to execute.
//! Defines a `WasmRuntime` that uses the Wasmtime JIT to execute.
//!
//! You can choose a profiling strategy at runtime with
//! environment variable `WASMTIME_PROFILING_STRATEGY`:
//!
//! | `WASMTIME_PROFILING_STRATEGY` | Effect |
//! |-------------|-------------------------|
//! | undefined | No profiling |
//! | `"jitdump"` | jitdump profiling |
//! | other value | No profiling (warning) |

mod host;
mod imports;
mod instance_wrapper;
Expand Down
22 changes: 21 additions & 1 deletion client/executor/wasmtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ use sp_wasm_interface::{Function, Pointer, Value, WordSize};
use std::{
path::{Path, PathBuf},
rc::Rc,
sync::Arc,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
use wasmtime::{AsContext, AsContextMut, Engine, StoreLimits};

Expand Down Expand Up @@ -322,6 +325,23 @@ fn common_config(semantics: &Semantics) -> std::result::Result<wasmtime::Config,
config.cranelift_opt_level(wasmtime::OptLevel::SpeedAndSize);
config.cranelift_nan_canonicalization(semantics.canonicalize_nans);

let profiler = match std::env::var_os("WASMTIME_PROFILING_STRATEGY") {
Some(os_string) if os_string == "jitdump" => wasmtime::ProfilingStrategy::JitDump,
None => wasmtime::ProfilingStrategy::None,
Some(_) => {
// Remember if we have already logged a warning due to an unknown profiling strategy.
static UNKNOWN_PROFILING_STRATEGY: AtomicBool = AtomicBool::new(false);
// Make sure that the warning will not be relogged regularly.
if !UNKNOWN_PROFILING_STRATEGY.swap(true, Ordering::Relaxed) {
log::warn!("WASMTIME_PROFILING_STRATEGY is set to unknown value, ignored.");
}
wasmtime::ProfilingStrategy::None
},
};
config
.profiler(profiler)
.map_err(|e| WasmError::Instantiation(format!("fail to set profiler: {}", e)))?;

if let Some(DeterministicStackLimit { native_stack_max, .. }) =
semantics.deterministic_stack_limit
{
Expand Down