treewide: set up Hotpath for benchmarking individual allocations

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I0351e5753996e6d0391fc9e2f329878a6a6a6964
This commit is contained in:
raf 2025-11-17 17:39:21 +03:00
commit 2a6fe2a3f1
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
8 changed files with 1075 additions and 3 deletions

View file

@ -43,6 +43,7 @@ pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
});
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn print_dots() -> String {
format!(
"{} {} {} {} {} {} {}",

View file

@ -1,4 +1,5 @@
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_desktop_info() -> String {
// Retrieve the environment variables and handle Result types
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");

View file

@ -19,6 +19,7 @@ use crate::{
uptime::get_current,
};
#[cfg_attr(feature = "hotpath", hotpath::main)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
if Some("--version") == std::env::args().nth(1).as_deref() {
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));
@ -56,6 +57,7 @@ struct Fields {
colors: String,
}
#[cfg_attr(feature = "hotpath", hotpath::measure)]
fn print_system_info(
fields: &Fields,
) -> Result<(), Box<dyn std::error::Error>> {

View file

@ -6,6 +6,7 @@ use std::{
use nix::sys::utsname::UtsName;
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_system_info(utsname: &UtsName) -> String {
format!(
"{} {} ({})",
@ -15,6 +16,7 @@ pub fn get_system_info(utsname: &UtsName) -> String {
)
}
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_os_pretty_name() -> Result<String, io::Error> {
let file = File::open("/etc/os-release")?;
let reader = BufReader::new(file);

View file

@ -9,6 +9,7 @@ use nix::sys::{statvfs::statvfs, utsname::UtsName};
use crate::colors::COLORS;
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_owned());
let hostname = utsname
@ -26,6 +27,7 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
}
#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_shell() -> String {
let shell_path =
env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_owned());
@ -33,6 +35,7 @@ pub fn get_shell() -> String {
shell_name.to_owned()
}
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_root_disk_usage() -> Result<String, io::Error> {
let vfs = statvfs("/")?;
let block_size = vfs.block_size() as u64;
@ -53,7 +56,9 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
))
}
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_memory_usage() -> Result<String, io::Error> {
#[cfg_attr(feature = "hotpath", hotpath::measure)]
fn parse_memory_info() -> Result<(f64, f64), io::Error> {
let mut total_memory_kb = 0.0;
let mut available_memory_kb = 0.0;

View file

@ -1,5 +1,6 @@
use std::{io, mem::MaybeUninit};
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn get_current() -> Result<String, io::Error> {
let uptime_seconds = {
let mut info = MaybeUninit::uninit();