aya: expose run_time_ns and run_cnt fields in ProgramInfo

Added functions to expose `run_time_ns` & `run_cnt` statistics from
ProgramInfo/bpf_prog_info.
pull/959/head
tyrone-wu 2 months ago
parent fa6af6a204
commit a25f501ece
No known key found for this signature in database
GPG Key ID: 978B1A1B79210AD6

@ -1000,6 +1000,7 @@ impl_info!(
);
/// Provides information about a loaded program, like name, id and statistics
#[doc(alias = "bpf_prog_info")]
#[derive(Debug)]
pub struct ProgramInfo(bpf_prog_info);
@ -1099,6 +1100,27 @@ impl ProgramInfo {
Ok(ProgramFd(fd))
}
/// The accumulated time that the program has been actively running.
///
/// This is not to be confused with the duration since the program was
/// first loaded on the host.
///
/// Note this field is only updated for as long as
/// [`enable_stats`](crate::sys::enable_stats) is enabled
/// with [`Stats::RunTime`](crate::sys::Stats::RunTime).
pub fn run_time(&self) -> Duration {
Duration::from_nanos(self.0.run_time_ns)
}
/// The accumulated execution count of the program.
///
/// Note this field is only updated for as long as
/// [`enable_stats`](crate::sys::enable_stats) is enabled
/// with [`Stats::RunTime`](crate::sys::Stats::RunTime).
pub fn run_count(&self) -> u64 {
self.0.run_cnt
}
/// Loads a program from a pinned path in bpffs.
pub fn from_pin<P: AsRef<Path>>(path: P) -> Result<Self, ProgramError> {
use std::os::unix::ffi::OsStrExt as _;

@ -146,7 +146,8 @@ pub(crate) unsafe fn mmap(
#[doc(alias = "bpf_stats_type")]
#[derive(Copy, Clone, Debug)]
pub enum Stats {
/// Tracks `run_time_ns` and `run_cnt`.
/// Tracks [`run_time`](crate::programs::ProgramInfo::run_time) and
/// [`run_count`](crate::programs::ProgramInfo::run_count) fields.
#[doc(alias = "BPF_STATS_RUN_TIME")]
RunTime,
}

@ -98,6 +98,8 @@ fn list_loaded_programs() {
prog.verified_instruction_count();
prog.loaded_at();
prog.fd().unwrap();
prog.run_time();
prog.run_count();
}
#[test]

@ -7923,6 +7923,8 @@ pub fn aya::programs::ProgramInfo::memory_locked(&self) -> core::result::Result<
pub fn aya::programs::ProgramInfo::name(&self) -> &[u8]
pub fn aya::programs::ProgramInfo::name_as_str(&self) -> core::option::Option<&str>
pub fn aya::programs::ProgramInfo::program_type(&self) -> u32
pub fn aya::programs::ProgramInfo::run_count(&self) -> u64
pub fn aya::programs::ProgramInfo::run_time(&self) -> core::time::Duration
pub fn aya::programs::ProgramInfo::size_jitted(&self) -> u32
pub fn aya::programs::ProgramInfo::size_translated(&self) -> u32
pub fn aya::programs::ProgramInfo::tag(&self) -> u64

Loading…
Cancel
Save