Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/profile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ doctest = false
cfg-if = "1.0.1"
jemalloc-ctl = { version = "0.5.4", package = "tikv-jemalloc-ctl", optional = true }

[target.'cfg(all(target_os = "linux", not(target_env = "ohos")))'.dependencies]
perf-event = "=0.4.7"
[target.'cfg(all(target_os = "linux", not(target_env = "ohos"), any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))'.dependencies]
perf-event = "=0.4.8"

[target.'cfg(all(target_os = "linux", target_env = "gnu"))'.dependencies]
libc.workspace = true
Expand Down
32 changes: 25 additions & 7 deletions crates/profile/src/stop_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use crate::MemoryUsage;

pub struct StopWatch {
time: Instant,
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
#[cfg(all(
target_os = "linux",
not(target_env = "ohos"),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
counter: Option<perf_event::Counter>,
memory: MemoryUsage,
}
Expand All @@ -24,7 +28,11 @@ pub struct StopWatchSpan {

impl StopWatch {
pub fn start() -> StopWatch {
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
#[cfg(all(
target_os = "linux",
not(target_env = "ohos"),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
let counter = {
// When debugging rust-analyzer using rr, the perf-related syscalls cause it to abort.
// We allow disabling perf by setting the env var `RA_DISABLE_PERF`.
Expand All @@ -51,7 +59,11 @@ impl StopWatch {
let time = Instant::now();
StopWatch {
time,
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
#[cfg(all(
target_os = "linux",
not(target_env = "ohos"),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
counter,
memory,
}
Expand All @@ -60,13 +72,19 @@ impl StopWatch {
pub fn elapsed(&mut self) -> StopWatchSpan {
let time = self.time.elapsed();

#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
#[cfg(all(
target_os = "linux",
not(target_env = "ohos"),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
let instructions = self.counter.as_mut().and_then(|it| {
it.read().map_err(|err| eprintln!("Failed to read perf counter: {err}")).ok()
});
#[cfg(all(target_os = "linux", target_env = "ohos"))]
let instructions = None;
#[cfg(not(target_os = "linux"))]
#[cfg(not(all(
target_os = "linux",
not(target_env = "ohos"),
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
)))]
let instructions = None;

let memory = MemoryUsage::now() - self.memory;
Expand Down