From 80567bfd70240b120e9517c3b0e7d90cff96e8c8 Mon Sep 17 00:00:00 2001 From: LuuuXXX Date: Thu, 21 Nov 2024 09:16:11 +0800 Subject: [PATCH 1/2] update perf-event-open-sys to perf-event-open-sys2 --- Cargo.toml | 2 +- measureme/Cargo.toml | 2 +- measureme/src/counters.rs | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 130c455..a0b45dc 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-sys = "3.0.0" +perf-event-open-sys2 = "5.0.6" 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 9c9f879..5e67442 100644 --- a/measureme/Cargo.toml +++ b/measureme/Cargo.toml @@ -18,4 +18,4 @@ nightly = [] [target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dependencies] memmap2.workspace = true -perf-event-open-sys.workspace = true +perf-event-open-sys2.workspace = true diff --git a/measureme/src/counters.rs b/measureme/src/counters.rs index f513527..dd9cd64 100644 --- a/measureme/src/counters.rs +++ b/measureme/src/counters.rs @@ -349,12 +349,10 @@ mod hw { type_: perf_type_id, hw_id: u32, ) -> Result> { - let mut attrs = perf_event_attr { - size: mem::size_of::().try_into().unwrap(), - type_, - config: hw_id.into(), - ..perf_event_attr::default() - }; + let mut attrs = perf_event_attr::default(); + attrs.size = mem::size_of::().try_into().unwrap(); + attrs.type_ = type_; + attrs.config = hw_id.into(); // Only record same-thread, any CPUs, and only userspace (no kernel/hypervisor). // NOTE(eddyb) `pid = 0`, despite talking about "process id", means From 2694c03ba7ac121bd8e370dbac7b1aa85753cef0 Mon Sep 17 00:00:00 2001 From: LuuuXXX Date: Mon, 16 Dec 2024 16:08:16 +0800 Subject: [PATCH 2/2] cfg out ohos platform in dependencies --- Cargo.toml | 2 +- measureme/Cargo.toml | 4 ++-- measureme/src/counters.rs | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) 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()) } }