mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-11-25 16:52:50 +00:00
treewide: set up Hotpath for benchmarking individual allocations
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0351e5753996e6d0391fc9e2f329878a6a6a6964
This commit is contained in:
parent
9bd4c9a70a
commit
2a6fe2a3f1
8 changed files with 1075 additions and 3 deletions
|
|
@ -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!(
|
||||
"{} {} {} {} {} {} {}",
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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>> {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue