Add support for generating perf maps for simple perf profiling (#6030)
* Add support for generating perf maps for simple perf profiling * add missing enum entry in C code * bugfix: use hexa when printing the code region's length too (thanks bjorn3!) * sanitize file name + use bufwriter * introduce --profile CLI flag for wasmtime * Update doc and doc comments for new --profile option * remove redundant FromStr import * Apply review feedback: make_line receives a Write impl, report errors * fix tests? * better docs
This commit is contained in:
@@ -6,13 +6,14 @@ use std::collections::{HashMap, HashSet};
|
||||
use std::fmt;
|
||||
#[cfg(feature = "cache")]
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use target_lexicon::Architecture;
|
||||
use wasmparser::WasmFeatures;
|
||||
#[cfg(feature = "cache")]
|
||||
use wasmtime_cache::CacheConfig;
|
||||
use wasmtime_environ::Tunables;
|
||||
use wasmtime_jit::{JitDumpAgent, NullProfilerAgent, ProfilingAgent, VTuneAgent};
|
||||
use wasmtime_jit::{JitDumpAgent, NullProfilerAgent, PerfMapAgent, ProfilingAgent, VTuneAgent};
|
||||
use wasmtime_runtime::{InstanceAllocator, OnDemandInstanceAllocator, RuntimeMemoryCreator};
|
||||
|
||||
pub use wasmtime_environ::CacheStore;
|
||||
@@ -221,7 +222,6 @@ impl Config {
|
||||
#[cfg(compiler)]
|
||||
#[cfg_attr(nightlydoc, doc(cfg(feature = "cranelift")))] // see build.rs
|
||||
pub fn target(&mut self, target: &str) -> Result<&mut Self> {
|
||||
use std::str::FromStr;
|
||||
self.compiler_config.target =
|
||||
Some(target_lexicon::Triple::from_str(target).map_err(|e| anyhow::anyhow!(e))?);
|
||||
|
||||
@@ -1536,6 +1536,7 @@ impl Config {
|
||||
|
||||
pub(crate) fn build_profiler(&self) -> Result<Box<dyn ProfilingAgent>> {
|
||||
Ok(match self.profiling_strategy {
|
||||
ProfilingStrategy::PerfMap => Box::new(PerfMapAgent::new()?) as Box<dyn ProfilingAgent>,
|
||||
ProfilingStrategy::JitDump => Box::new(JitDumpAgent::new()?) as Box<dyn ProfilingAgent>,
|
||||
ProfilingStrategy::VTune => Box::new(VTuneAgent::new()?) as Box<dyn ProfilingAgent>,
|
||||
ProfilingStrategy::None => Box::new(NullProfilerAgent),
|
||||
@@ -1727,11 +1728,14 @@ pub enum OptLevel {
|
||||
}
|
||||
|
||||
/// Select which profiling technique to support.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum ProfilingStrategy {
|
||||
/// No profiler support.
|
||||
None,
|
||||
|
||||
/// Collect function name information as the "perf map" file format, used with `perf` on Linux.
|
||||
PerfMap,
|
||||
|
||||
/// Collect profiling info for "jitdump" file format, used with `perf` on
|
||||
/// Linux.
|
||||
JitDump,
|
||||
@@ -1740,6 +1744,20 @@ pub enum ProfilingStrategy {
|
||||
VTune,
|
||||
}
|
||||
|
||||
impl FromStr for ProfilingStrategy {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
match s {
|
||||
"none" => Ok(Self::None),
|
||||
"perfmap" => Ok(Self::PerfMap),
|
||||
"jitdump" => Ok(Self::JitDump),
|
||||
"vtune" => Ok(Self::VTune),
|
||||
_ => anyhow::bail!("unknown value for profiling strategy"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Select how wasm backtrace detailed information is handled.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum WasmBacktraceDetails {
|
||||
|
||||
Reference in New Issue
Block a user