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
1055
Cargo.lock
generated
1055
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
11
Cargo.toml
11
Cargo.toml
|
|
@ -12,12 +12,19 @@ name = "microfetch"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.175"
|
hotpath = { optional = true, version = "0.6" }
|
||||||
nix = { default-features = false, features = [ "fs", "hostname", "feature" ], version = "0.30.1" }
|
libc = "0.2.175"
|
||||||
|
nix = { default-features = false, features = [ "fs", "hostname", "feature" ], version = "0.30.1" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.7"
|
criterion = "0.7"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
hotpath = [ "dep:hotpath", "hotpath/hotpath" ]
|
||||||
|
hotpath-alloc-bytes-total = [ "hotpath/hotpath-alloc-bytes-total" ]
|
||||||
|
hotpath-alloc-count-total = [ "hotpath/hotpath-alloc-count-total" ]
|
||||||
|
hotpath-off = [ "hotpath/hotpath-off" ]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
harness = false
|
harness = false
|
||||||
name = "benchmark"
|
name = "benchmark"
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
|
||||||
});
|
});
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn print_dots() -> String {
|
pub fn print_dots() -> String {
|
||||||
format!(
|
format!(
|
||||||
"{} {} {} {} {} {} {}",
|
"{} {} {} {} {} {} {}",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn get_desktop_info() -> String {
|
pub fn get_desktop_info() -> String {
|
||||||
// Retrieve the environment variables and handle Result types
|
// Retrieve the environment variables and handle Result types
|
||||||
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
|
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ use crate::{
|
||||||
uptime::get_current,
|
uptime::get_current,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::main)]
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if Some("--version") == std::env::args().nth(1).as_deref() {
|
if Some("--version") == std::env::args().nth(1).as_deref() {
|
||||||
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));
|
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
@ -56,6 +57,7 @@ struct Fields {
|
||||||
colors: String,
|
colors: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
fn print_system_info(
|
fn print_system_info(
|
||||||
fields: &Fields,
|
fields: &Fields,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use std::{
|
||||||
use nix::sys::utsname::UtsName;
|
use nix::sys::utsname::UtsName;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn get_system_info(utsname: &UtsName) -> String {
|
pub fn get_system_info(utsname: &UtsName) -> String {
|
||||||
format!(
|
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> {
|
pub fn get_os_pretty_name() -> Result<String, io::Error> {
|
||||||
let file = File::open("/etc/os-release")?;
|
let file = File::open("/etc/os-release")?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
||||||
use crate::colors::COLORS;
|
use crate::colors::COLORS;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
||||||
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_owned());
|
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_owned());
|
||||||
let hostname = utsname
|
let hostname = utsname
|
||||||
|
|
@ -26,6 +27,7 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn get_shell() -> String {
|
pub fn get_shell() -> String {
|
||||||
let shell_path =
|
let shell_path =
|
||||||
env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_owned());
|
env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_owned());
|
||||||
|
|
@ -33,6 +35,7 @@ pub fn get_shell() -> String {
|
||||||
shell_name.to_owned()
|
shell_name.to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
||||||
let vfs = statvfs("/")?;
|
let vfs = statvfs("/")?;
|
||||||
let block_size = vfs.block_size() as u64;
|
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> {
|
pub fn get_memory_usage() -> Result<String, io::Error> {
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
fn parse_memory_info() -> Result<(f64, f64), io::Error> {
|
fn parse_memory_info() -> Result<(f64, f64), io::Error> {
|
||||||
let mut total_memory_kb = 0.0;
|
let mut total_memory_kb = 0.0;
|
||||||
let mut available_memory_kb = 0.0;
|
let mut available_memory_kb = 0.0;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{io, mem::MaybeUninit};
|
use std::{io, mem::MaybeUninit};
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||||
pub fn get_current() -> Result<String, io::Error> {
|
pub fn get_current() -> Result<String, io::Error> {
|
||||||
let uptime_seconds = {
|
let uptime_seconds = {
|
||||||
let mut info = MaybeUninit::uninit();
|
let mut info = MaybeUninit::uninit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue