Skip to content

Commit 2a6fe2a

Browse files
committed
treewide: set up Hotpath for benchmarking individual allocations
Signed-off-by: NotAShelf <[email protected]> Change-Id: I0351e5753996e6d0391fc9e2f329878a6a6a6964
1 parent 9bd4c9a commit 2a6fe2a

File tree

8 files changed

+1079
-7
lines changed

8 files changed

+1079
-7
lines changed

Cargo.lock

Lines changed: 1058 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ name = "microfetch"
1212
path = "src/main.rs"
1313

1414
[dependencies]
15-
libc = "0.2.175"
16-
nix = { default-features = false, features = [ "fs", "hostname", "feature" ], version = "0.30.1" }
15+
hotpath = { optional = true, version = "0.6" }
16+
libc = "0.2.175"
17+
nix = { default-features = false, features = [ "fs", "hostname", "feature" ], version = "0.30.1" }
1718

1819
[dev-dependencies]
1920
criterion = "0.7"
2021

22+
[features]
23+
hotpath = [ "dep:hotpath", "hotpath/hotpath" ]
24+
hotpath-alloc-bytes-total = [ "hotpath/hotpath-alloc-bytes-total" ]
25+
hotpath-alloc-count-total = [ "hotpath/hotpath-alloc-count-total" ]
26+
hotpath-off = [ "hotpath/hotpath-off" ]
27+
2128
[[bench]]
2229
harness = false
2330
name = "benchmark"

src/colors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
4343
});
4444

4545
#[must_use]
46+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
4647
pub fn print_dots() -> String {
4748
format!(
4849
"{} {} {} {} {} {} {}",

src/desktop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#[must_use]
2+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
23
pub fn get_desktop_info() -> String {
34
// Retrieve the environment variables and handle Result types
45
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
uptime::get_current,
2020
};
2121

22+
#[cfg_attr(feature = "hotpath", hotpath::main)]
2223
fn main() -> Result<(), Box<dyn std::error::Error>> {
2324
if Some("--version") == std::env::args().nth(1).as_deref() {
2425
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));
@@ -56,6 +57,7 @@ struct Fields {
5657
colors: String,
5758
}
5859

60+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
5961
fn print_system_info(
6062
fields: &Fields,
6163
) -> Result<(), Box<dyn std::error::Error>> {

src/release.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
use nix::sys::utsname::UtsName;
77

88
#[must_use]
9+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
910
pub fn get_system_info(utsname: &UtsName) -> String {
1011
format!(
1112
"{} {} ({})",
@@ -15,6 +16,7 @@ pub fn get_system_info(utsname: &UtsName) -> String {
1516
)
1617
}
1718

19+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
1820
pub fn get_os_pretty_name() -> Result<String, io::Error> {
1921
let file = File::open("/etc/os-release")?;
2022
let reader = BufReader::new(file);

src/system.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use nix::sys::{statvfs::statvfs, utsname::UtsName};
99
use crate::colors::COLORS;
1010

1111
#[must_use]
12+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
1213
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
1314
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_owned());
1415
let hostname = utsname
@@ -26,13 +27,15 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
2627
}
2728

2829
#[must_use]
30+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
2931
pub fn get_shell() -> String {
3032
let shell_path =
3133
env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_owned());
3234
let shell_name = shell_path.rsplit('/').next().unwrap_or("unknown_shell");
3335
shell_name.to_owned()
3436
}
3537

38+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
3639
pub fn get_root_disk_usage() -> Result<String, io::Error> {
3740
let vfs = statvfs("/")?;
3841
let block_size = vfs.block_size() as u64;
@@ -53,7 +56,9 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
5356
))
5457
}
5558

59+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
5660
pub fn get_memory_usage() -> Result<String, io::Error> {
61+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
5762
fn parse_memory_info() -> Result<(f64, f64), io::Error> {
5863
let mut total_memory_kb = 0.0;
5964
let mut available_memory_kb = 0.0;

src/uptime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{io, mem::MaybeUninit};
22

3+
#[cfg_attr(feature = "hotpath", hotpath::measure)]
34
pub fn get_current() -> Result<String, io::Error> {
45
let uptime_seconds = {
56
let mut info = MaybeUninit::uninit();

0 commit comments

Comments
 (0)