From 34c744c0829135183dc54d86fc7e735f557a443c Mon Sep 17 00:00:00 2001 From: tyrone-wu Date: Tue, 28 May 2024 02:59:49 +0000 Subject: [PATCH] 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. --- aya/src/programs/mod.rs | 16 ++++++++++++++++ test/integration-test/src/tests/smoke.rs | 2 ++ xtask/public-api/aya.txt | 2 ++ 3 files changed, 20 insertions(+) diff --git a/aya/src/programs/mod.rs b/aya/src/programs/mod.rs index 675e36f0..0b72b885 100644 --- a/aya/src/programs/mod.rs +++ b/aya/src/programs/mod.rs @@ -1099,6 +1099,22 @@ impl ProgramInfo { Ok(ProgramFd(fd)) } + /// The duration the program has been running, in nanoseconds. + /// + /// Note this field is only updated for as long as [`BPF_ENABLE_STATS`](crate::Ebpf::enable_stats_fd) + /// is enabled with [`BPF_STATS_RUN_TIME`](aya_obj::BpfStatsType::RunTime) type set. + pub fn run_time_ns(&self) -> u64 { + self.0.run_time_ns + } + + /// The number of times the program has ran. + /// + /// Note this field is only updated for as long as [`BPF_ENABLE_STATS`](crate::Ebpf::enable_stats_fd) + /// is enabled with [`BPF_STATS_RUN_TIME`](aya_obj::BpfStatsType::RunTime) type set. + pub fn run_cnt(&self) -> u64 { + self.0.run_cnt + } + /// Loads a program from a pinned path in bpffs. pub fn from_pin>(path: P) -> Result { use std::os::unix::ffi::OsStrExt as _; diff --git a/test/integration-test/src/tests/smoke.rs b/test/integration-test/src/tests/smoke.rs index 708b889b..3a0afd7c 100644 --- a/test/integration-test/src/tests/smoke.rs +++ b/test/integration-test/src/tests/smoke.rs @@ -98,6 +98,8 @@ fn list_loaded_programs() { prog.verified_instruction_count(); prog.loaded_at(); prog.fd().unwrap(); + prog.run_time_ns(); + prog.run_cnt(); } #[test] diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index 5b3bd197..2347711d 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -7930,6 +7930,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_cnt(&self) -> u64 +pub fn aya::programs::ProgramInfo::run_time_ns(&self) -> u64 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