Skip to content

Commit 5e905e8

Browse files
authored
feat: add android schedstat support (#395)
* feat: add android schedstat support This PR updates the target_os flags to enable schedstat support for android. Android has the same /proc/self/task/<tid>/schedstat file descriptor as typical linux systems. The running process is able to access it without running into permissions issues. * fix: address target os inversion on schedstat test
1 parent fcf6ce1 commit 5e905e8

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

dial9-tokio-telemetry/src/telemetry/events.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,12 @@ pub(crate) struct CpuSampleData {
327327
}
328328

329329
/// Get the OS thread ID (tid) of the calling thread via `gettid()`.
330-
#[cfg(target_os = "linux")]
330+
#[cfg(any(target_os = "linux", target_os = "android"))]
331331
pub(crate) fn current_tid() -> u32 {
332332
unsafe { libc::syscall(libc::SYS_gettid) as u32 }
333333
}
334334

335-
#[cfg(not(target_os = "linux"))]
335+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
336336
pub(crate) fn current_tid() -> u32 {
337337
// No gettid on non-Linux; use a thread-local counter as a unique ID.
338338
use std::sync::atomic::{AtomicU32, Ordering};
@@ -425,11 +425,11 @@ pub(crate) fn clock_pair() -> (u64, u64) {
425425
pub(crate) struct SchedStat {
426426
pub wait_time_ns: u64,
427427
/// Raw fd backing this read, exposed for FD-lifecycle tests. Not used in production.
428-
#[cfg(all(test, target_os = "linux"))]
428+
#[cfg(all(test, any(target_os = "linux", target_os = "android")))]
429429
fd: std::os::fd::RawFd,
430430
}
431431

432-
#[cfg(target_os = "linux")]
432+
#[cfg(any(target_os = "linux", target_os = "android"))]
433433
impl SchedStat {
434434
/// Read schedstat for the current thread using a cached per-thread file descriptor.
435435
/// Opening `/proc/self/task/<tid>/schedstat` is done once per thread; subsequent reads
@@ -496,7 +496,7 @@ impl SchedStat {
496496
}
497497
}
498498

499-
#[cfg(not(target_os = "linux"))]
499+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
500500
impl SchedStat {
501501
pub(crate) fn read_current() -> std::io::Result<Self> {
502502
Err(std::io::Error::new(
@@ -607,7 +607,7 @@ mod tests {
607607
}
608608

609609
#[test]
610-
#[cfg(target_os = "linux")]
610+
#[cfg(any(target_os = "linux", target_os = "android"))]
611611
fn test_schedstat_fd_closed_on_thread_exit() {
612612
// fcntl(fd, F_GETFD) returns -1 with errno=EBADF for closed fds.
613613
// SAFETY: F_GETFD with a raw fd is side-effect free.

0 commit comments

Comments
 (0)