Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

update fxprof-processed-profile to 0.8.1 (#11634)

Pat Hickeye0af5d7f0f07
diff --git a/Cargo.lock b/Cargo.lock
index e3b784fb2a..f488ae37d5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1558,25 +1558,17 @@ dependencies = [
"slab",
]
-[[package]]
-name = "fxhash"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
-dependencies = [
- "byteorder",
-]
-
[[package]]
name = "fxprof-processed-profile"
-version = "0.6.0"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "27d12c0aed7f1e24276a241aadc4cb8ea9f83000f34bc062b7cc2d51e3b0fabd"
+checksum = "25234f20a3ec0a962a61770cfe39ecf03cb529a6e474ad8cff025ed497eda557"
dependencies = [
"bitflags 2.6.0",
"debugid",
- "fxhash",
+ "rustc-hash",
"serde",
+ "serde_derive",
"serde_json",
]
diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml
index 7d99b62612..b55310ca77 100644
--- a/crates/wasmtime/Cargo.toml
+++ b/crates/wasmtime/Cargo.toml
@@ -53,7 +53,7 @@ object = { workspace = true, features = ['unaligned'] }
async-trait = { workspace = true, optional = true }
encoding_rs = { version = "0.8.31", optional = true }
bumpalo = "3.11.0"
-fxprof-processed-profile = { version = "0.6.0", optional = true }
+fxprof-processed-profile = { version = "0.8.1", optional = true }
gimli = { workspace = true, optional = true }
addr2line = { workspace = true, optional = true }
semver = { workspace = true, optional = true }
diff --git a/crates/wasmtime/src/runtime/profiling.rs b/crates/wasmtime/src/runtime/profiling.rs
index fcd343a3bb..2b183a68b7 100644
--- a/crates/wasmtime/src/runtime/profiling.rs
+++ b/crates/wasmtime/src/runtime/profiling.rs
@@ -7,8 +7,9 @@ use crate::{AsContext, CallHook, Module};
use core::cmp::Ordering;
use fxprof_processed_profile::debugid::DebugId;
use fxprof_processed_profile::{
- CategoryHandle, Frame, FrameFlags, FrameInfo, LibraryInfo, MarkerLocation, MarkerSchema,
- MarkerTiming, Profile, ProfilerMarker, ReferenceTimestamp, Symbol, SymbolTable, Timestamp,
+ CategoryHandle, Frame, FrameFlags, FrameInfo, LibraryInfo, MarkerLocations, MarkerTiming,
+ Profile, ReferenceTimestamp, StaticSchemaMarker, StaticSchemaMarkerField, StringHandle, Symbol,
+ SymbolTable, Timestamp,
};
use std::ops::Range;
use std::sync::Arc;
@@ -79,6 +80,7 @@ pub struct GuestProfiler {
process: fxprof_processed_profile::ProcessHandle,
thread: fxprof_processed_profile::ThreadHandle,
start: Instant,
+ marker: CallMarker,
}
#[derive(Debug)]
@@ -147,12 +149,14 @@ impl GuestProfiler {
let process = profile.add_process(module_name, 0, Timestamp::from_nanos_since_reference(0));
let thread = profile.add_thread(process, 0, Timestamp::from_nanos_since_reference(0), true);
let start = Instant::now();
+ let marker = CallMarker::new(&mut profile);
Self {
profile,
modules,
process,
thread,
start,
+ marker,
}
}
@@ -189,8 +193,11 @@ impl GuestProfiler {
);
let backtrace = Backtrace::new(store.as_context().0);
let frames = lookup_frames(&self.modules, &backtrace);
+ let stack = self
+ .profile
+ .intern_stack_frames(self.thread, frames.into_iter());
self.profile
- .add_sample(self.thread, now, frames, delta.into(), 1);
+ .add_sample(self.thread, now, stack, delta.into(), 1);
}
/// Add a marker for transitions between guest and host to the profile.
@@ -206,21 +213,19 @@ impl GuestProfiler {
CallHook::CallingHost => {
let backtrace = Backtrace::new(store.as_context().0);
let frames = lookup_frames(&self.modules, &backtrace);
- self.profile.add_marker_with_stack(
+ let marker = self.profile.add_marker(
self.thread,
- "hostcall",
- CallMarker,
MarkerTiming::IntervalStart(now),
- frames,
+ self.marker,
);
+ let stack = self
+ .profile
+ .intern_stack_frames(self.thread, frames.into_iter());
+ self.profile.set_marker_stack(self.thread, marker, stack);
}
CallHook::ReturningFromHost => {
- self.profile.add_marker(
- self.thread,
- "hostcall",
- CallMarker,
- MarkerTiming::IntervalEnd(now),
- );
+ self.profile
+ .add_marker(self.thread, MarkerTiming::IntervalEnd(now), self.marker);
}
}
}
@@ -312,27 +317,34 @@ fn lookup_frames<'a>(
})
}
-struct CallMarker;
-
-impl ProfilerMarker for CallMarker {
- const MARKER_TYPE_NAME: &'static str = "hostcall";
+#[derive(Debug, Clone, Copy)]
+struct CallMarker {
+ name: StringHandle,
+}
- fn schema() -> MarkerSchema {
- MarkerSchema {
- type_name: Self::MARKER_TYPE_NAME,
- locations: vec![
- MarkerLocation::MarkerChart,
- MarkerLocation::MarkerTable,
- MarkerLocation::TimelineOverview,
- ],
- chart_label: None,
- tooltip_label: None,
- table_label: None,
- fields: vec![],
- }
+impl CallMarker {
+ fn new(profile: &mut Profile) -> Self {
+ let name = profile.intern_string(Self::UNIQUE_MARKER_TYPE_NAME);
+ Self { name }
}
+}
+
+impl StaticSchemaMarker for CallMarker {
+ const UNIQUE_MARKER_TYPE_NAME: &'static str = "hostcall";
+ const FIELDS: &'static [StaticSchemaMarkerField] = &[];
+ const LOCATIONS: MarkerLocations = MarkerLocations::MARKER_CHART
+ .union(MarkerLocations::MARKER_TABLE.union(MarkerLocations::TIMELINE_OVERVIEW));
- fn json_marker_data(&self) -> serde_json::Value {
- serde_json::json!({ "type": Self::MARKER_TYPE_NAME })
+ fn name(&self, _profile: &mut Profile) -> StringHandle {
+ self.name
+ }
+ fn category(&self, _profile: &mut Profile) -> CategoryHandle {
+ CategoryHandle::OTHER
+ }
+ fn string_field_value(&self, _field_index: u32) -> StringHandle {
+ unreachable!("no fields")
+ }
+ fn number_field_value(&self, _field_index: u32) -> f64 {
+ unreachable!("no fields")
}
}
diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml
index 49a833e89c..7632920d1d 100644
--- a/supply-chain/audits.toml
+++ b/supply-chain/audits.toml
@@ -2321,6 +2321,11 @@ serialization support. All logic is trivial: either unit conversion, or
hash-consing to support de-duplication required by the format.
"""
+[[audits.fxprof-processed-profile]]
+who = "Pat Hickey <[email protected]>"
+criteria = "safe-to-deploy"
+delta = "0.6.0 -> 0.8.1"
+
[[audits.gimli]]
who = "Alex Crichton <[email protected]>"
criteria = "safe-to-deploy"
diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs
index b09dc6fd2f..29f899972b 100644
--- a/tests/all/cli_tests.rs
+++ b/tests/all/cli_tests.rs
@@ -2273,6 +2273,32 @@ fn is_vtune_available() -> bool {
Command::new("vtune").arg("-version").output().is_ok()
}
+#[test]
+fn profile_guest() -> Result<()> {
+ let tmpdir = std::env::temp_dir();
+ let dir = tmpdir.to_string_lossy();
+
+ let output = run_wasmtime_for_output(
+ &[
+ &format!("--profile=guest,{dir}/out.json"),
+ "--env",
+ "FOO=bar",
+ "tests/all/cli_tests/print_env.wat",
+ ],
+ None,
+ )?;
+
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ println!("> stdout:\n{stdout}");
+ println!("> stderr:\n{stderr}");
+ assert!(!stderr.contains("Error"));
+ let out_json = std::fs::read_to_string(format!("{dir}/out.json")).unwrap();
+ println!("> out.json:\n{out_json}");
+ Ok(())
+}
+
#[test]
fn unreachable_without_wasi() -> Result<()> {
let output = run_wasmtime_for_output(