Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 0d44d83

Browse files
libreloispepyakinbkchr
authored
add feature wasmtime-jitdump (#9871)
* add feature wasmtime-jitdump * remove unwrap * always enable wasmtime/jitdump feature * env WASMTIME_PROFILING_STRATEGY: retun an error for unknown value * Add doc for env var WASMTIME_PROFILING_STRATEGY * Update client/executor/wasmtime/Cargo.toml Co-authored-by: Sergei Shulepov <[email protected]> * warning instead of error * Update client/executor/wasmtime/src/runtime.rs Co-authored-by: Bastian Köcher <[email protected]> * update doc: unknown value cause warning instead of error * log warning only once * static right next to the usage Co-authored-by: Sergei Shulepov <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 4ecbb1f commit 0d44d83

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/executor/wasmtime/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ sp-wasm-interface = { version = "4.0.0-dev", path = "../../../primitives/wasm-in
2323
sp-runtime-interface = { version = "4.0.0-dev", path = "../../../primitives/runtime-interface" }
2424
sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" }
2525
sc-allocator = { version = "4.0.0-dev", path = "../../allocator" }
26-
wasmtime = { version = "0.29.0", default-features = false, features = ["cache", "parallel-compilation"] }
26+
wasmtime = { version = "0.29.0", default-features = false, features = [
27+
"cache",
28+
"jitdump",
29+
"parallel-compilation",
30+
] }
2731

2832
[dev-dependencies]
2933
sc-runtime-test = { version = "2.0.0", path = "../runtime-test" }

client/executor/wasmtime/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
// You should have received a copy of the GNU General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
/// ! Defines a `WasmRuntime` that uses the Wasmtime JIT to execute.
19+
//! Defines a `WasmRuntime` that uses the Wasmtime JIT to execute.
20+
//!
21+
//! You can choose a profiling strategy at runtime with
22+
//! environment variable `WASMTIME_PROFILING_STRATEGY`:
23+
//!
24+
//! | `WASMTIME_PROFILING_STRATEGY` | Effect |
25+
//! |-------------|-------------------------|
26+
//! | undefined | No profiling |
27+
//! | `"jitdump"` | jitdump profiling |
28+
//! | other value | No profiling (warning) |
29+
2030
mod host;
2131
mod imports;
2232
mod instance_wrapper;

client/executor/wasmtime/src/runtime.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ use sp_wasm_interface::{Function, Pointer, Value, WordSize};
3838
use std::{
3939
path::{Path, PathBuf},
4040
rc::Rc,
41-
sync::Arc,
41+
sync::{
42+
atomic::{AtomicBool, Ordering},
43+
Arc,
44+
},
4245
};
4346
use wasmtime::{AsContext, AsContextMut, Engine, StoreLimits};
4447

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

328+
let profiler = match std::env::var_os("WASMTIME_PROFILING_STRATEGY") {
329+
Some(os_string) if os_string == "jitdump" => wasmtime::ProfilingStrategy::JitDump,
330+
None => wasmtime::ProfilingStrategy::None,
331+
Some(_) => {
332+
// Remember if we have already logged a warning due to an unknown profiling strategy.
333+
static UNKNOWN_PROFILING_STRATEGY: AtomicBool = AtomicBool::new(false);
334+
// Make sure that the warning will not be relogged regularly.
335+
if !UNKNOWN_PROFILING_STRATEGY.swap(true, Ordering::Relaxed) {
336+
log::warn!("WASMTIME_PROFILING_STRATEGY is set to unknown value, ignored.");
337+
}
338+
wasmtime::ProfilingStrategy::None
339+
},
340+
};
341+
config
342+
.profiler(profiler)
343+
.map_err(|e| WasmError::Instantiation(format!("fail to set profiler: {}", e)))?;
344+
325345
if let Some(DeterministicStackLimit { native_stack_max, .. }) =
326346
semantics.deterministic_stack_limit
327347
{

0 commit comments

Comments
 (0)