diff --git a/Cargo.toml b/Cargo.toml index a0b45dc..130c455 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ measureme_10 = { version = "10.1.3", package = "measureme" } memchr = "2" memmap2 = "0.2.1" parking_lot = "0.12.0" -perf-event-open-sys2 = "5.0.6" +perf-event-open-sys = "3.0.0" prettytable-rs = "0.10" rustc-hash = "1.0.1" serde = { version = "1.0", features = ["derive"] } diff --git a/measureme/Cargo.toml b/measureme/Cargo.toml index 5e67442..059d7f2 100644 --- a/measureme/Cargo.toml +++ b/measureme/Cargo.toml @@ -16,6 +16,6 @@ smallvec.workspace = true [features] nightly = [] -[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dependencies] +[target.'cfg(all(target_arch = "x86_64", target_os = "linux", not(target_env = "ohos")))'.dependencies] memmap2.workspace = true -perf-event-open-sys2.workspace = true +perf-event-open-sys.workspace = true diff --git a/measureme/src/counters.rs b/measureme/src/counters.rs index dd9cd64..18d5e63 100644 --- a/measureme/src/counters.rs +++ b/measureme/src/counters.rs @@ -303,7 +303,7 @@ const BUG_REPORT_MSG: &str = "please report this to https://github.com/rust-lang/measureme/issues/new"; /// Linux x86_64 implementation based on `perf_event_open` and `rdpmc`. -#[cfg(all(target_arch = "x86_64", target_os = "linux"))] +#[cfg(all(target_arch = "x86_64", target_os = "linux", not(target_env = "ohos")))] mod hw { use memmap2::{Mmap, MmapOptions}; use perf_event_open_sys::{bindings::*, perf_event_open}; @@ -349,10 +349,12 @@ mod hw { type_: perf_type_id, hw_id: u32, ) -> Result> { - let mut attrs = perf_event_attr::default(); - attrs.size = mem::size_of::().try_into().unwrap(); - attrs.type_ = type_; - attrs.config = hw_id.into(); + let mut attrs = perf_event_attr { + size: mem::size_of::().try_into().unwrap(), + type_, + config: hw_id.into(), + ..perf_event_attr::default() + }; // Only record same-thread, any CPUs, and only userspace (no kernel/hypervisor). // NOTE(eddyb) `pid = 0`, despite talking about "process id", means @@ -933,7 +935,7 @@ mod hw { } } -#[cfg(not(all(target_arch = "x86_64", target_os = "linux")))] +#[cfg(not(all(target_arch = "x86_64", target_os = "linux", not(target_env = "ohos"))))] mod hw { use std::error::Error; @@ -992,6 +994,10 @@ mod hw { add_error("only supported OS is Linux"); } + if cfg!(target_env = "ohos") { + add_error("unsupported OHOS environment"); + } + Err(msg.into()) } }