Skip to content

Commit

Permalink
cfg out ohos platform in dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
LuuuXXX committed Dec 17, 2024
1 parent 80567bf commit 2694c03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions measureme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 12 additions & 6 deletions measureme/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -349,10 +349,12 @@ mod hw {
type_: perf_type_id,
hw_id: u32,
) -> Result<Self, Box<dyn Error + Send + Sync>> {
let mut attrs = perf_event_attr::default();
attrs.size = mem::size_of::<perf_event_attr>().try_into().unwrap();
attrs.type_ = type_;
attrs.config = hw_id.into();
let mut attrs = perf_event_attr {
size: mem::size_of::<perf_event_attr>().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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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())
}
}
Expand Down

0 comments on commit 2694c03

Please sign in to comment.