Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [ "crates/*", "microfetch", "crates/benchmarks" ]
members = [ "crates/asm", "crates/benchmarks", "crates/lib", "microfetch" ]
resolver = "3"

[workspace.package]
Expand All @@ -9,9 +9,8 @@ rust-version = "1.95.0"
version = "1.2.0"

[workspace.dependencies]
microfetch-alloc = { path = "./crates/alloc", version = "1.2.0" }
microfetch-asm = { path = "./crates/asm", version = "1.2.0" }
microfetch-lib = { path = "./crates/lib", version = "1.2.0" }
microfetch-asm = { path = "./crates/asm", version = "1.2.0" }
microfetch-lib = { path = "./crates/lib", version = "1.2.0" }

criterion = { default-features = false, features = [ "cargo_bench_support" ], version = "0.8.2" }
criterion-cycles-per-byte = "0.8.0"
Expand Down
11 changes: 0 additions & 11 deletions crates/alloc/Cargo.toml

This file was deleted.

106 changes: 0 additions & 106 deletions crates/alloc/src/lib.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/asm/src/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const HOST_VM_INFO64: c_int = 4;
/// `host_statistics64` matches the kernel's expectation exactly (38 ints).
#[repr(C)]
#[derive(Default)]
#[expect(dead_code, reason = "most fields exist only to fix the struct layout")]
#[allow(dead_code, reason = "most fields exist only to fix the struct layout")]
struct VmStatistics64 {
free_count: u32,
active_count: u32,
Expand Down Expand Up @@ -240,7 +240,7 @@ pub fn macos_meminfo() -> Option<(u64, u64)> {
/// `struct timeval` (`time_t` is 64-bit, `suseconds_t` is 32-bit on macOS).
#[repr(C)]
#[derive(Default)]
#[expect(
#[allow(
dead_code,
reason = "tv_usec/_pad exist only to fix the struct layout"
)]
Expand Down
90 changes: 70 additions & 20 deletions crates/benchmarks/benches/microfetch.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,82 @@
use criterion::{Criterion, criterion_group, criterion_main};
use microfetch_lib::{
StackWriter,
UtsName,
colors::print_dots,
desktop::get_desktop_info,
release::{get_os_pretty_name, get_system_info},
system::{
get_memory_usage,
get_root_disk_usage,
get_shell,
get_username_and_hostname,
},
uptime::get_current,
colors::{self, Colors},
cpu,
desktop,
release,
system,
uptime,
};

fn main_benchmark(c: &mut Criterion) {
let utsname = UtsName::uname().expect("Failed to get uname");
let colors = Colors::new(false);

c.bench_function("user_info", |b| {
b.iter(|| get_username_and_hostname(&utsname));
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
system::write_username_and_hostname(&mut w, &colors, &utsname);
});
});
c.bench_function("os_name", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
let _ = release::write_os_pretty_name(&mut w);
});
});
c.bench_function("kernel_version", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
release::write_system_info(&mut w, &utsname);
});
});
c.bench_function("shell", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
system::write_shell(&mut w);
});
});
c.bench_function("desktop", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
desktop::write_desktop_info(&mut w);
});
});
c.bench_function("uptime", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
let _ = uptime::write_uptime(&mut w);
});
});
c.bench_function("memory_usage", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
let _ = system::write_memory_usage(&mut w, &colors);
});
});
c.bench_function("storage", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
let _ = system::write_root_disk_usage(&mut w, &colors);
});
});
c.bench_function("colors", |b| {
b.iter(|| {
let mut buf = [0u8; 256];
let mut w = StackWriter::new(&mut buf);
colors::write_dots(&mut w, &colors);
});
});
c.bench_function("os_name", |b| b.iter(get_os_pretty_name));
c.bench_function("kernel_version", |b| b.iter(|| get_system_info(&utsname)));
c.bench_function("shell", |b| b.iter(get_shell));

c.bench_function("desktop", |b| b.iter(get_desktop_info));
c.bench_function("uptime", |b| b.iter(get_current));
c.bench_function("memory_usage", |b| b.iter(get_memory_usage));
c.bench_function("storage", |b| b.iter(get_root_disk_usage));
c.bench_function("colors", |b| b.iter(print_dots));
}

criterion_group!(benches, main_benchmark);
Expand Down
64 changes: 22 additions & 42 deletions crates/lib/src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::string::String;
use crate::StackWriter;

/// Color codes for terminal output
pub struct Colors {
Expand Down Expand Up @@ -59,47 +59,27 @@ pub(crate) fn is_no_color() -> bool {
is_set
}

#[must_use]
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub fn print_dots() -> String {
const GLYPH: &str = "";
pub fn write_dots(w: &mut StackWriter, colors: &Colors) {
const GLYPH: &str = "";

let colors = if is_no_color() {
Colors::new(true)
} else {
Colors::new(false)
};

// Pre-calculate capacity: 6 color codes + " " (glyph + 2 spaces) per color
let capacity = colors.blue.len()
+ colors.cyan.len()
+ colors.green.len()
+ colors.yellow.len()
+ colors.red.len()
+ colors.magenta.len()
+ colors.reset.len()
+ (GLYPH.len() + 2) * 6;

let mut result = String::with_capacity(capacity);
result.push_str(colors.blue);
result.push_str(GLYPH);
result.push_str(" ");
result.push_str(colors.cyan);
result.push_str(GLYPH);
result.push_str(" ");
result.push_str(colors.green);
result.push_str(GLYPH);
result.push_str(" ");
result.push_str(colors.yellow);
result.push_str(GLYPH);
result.push_str(" ");
result.push_str(colors.red);
result.push_str(GLYPH);
result.push_str(" ");
result.push_str(colors.magenta);
result.push_str(GLYPH);
result.push_str(" ");
result.push_str(colors.reset);

result
w.push_str(colors.blue);
w.push_str(GLYPH);
w.push_str(" ");
w.push_str(colors.cyan);
w.push_str(GLYPH);
w.push_str(" ");
w.push_str(colors.green);
w.push_str(GLYPH);
w.push_str(" ");
w.push_str(colors.yellow);
w.push_str(GLYPH);
w.push_str(" ");
w.push_str(colors.red);
w.push_str(GLYPH);
w.push_str(" ");
w.push_str(colors.magenta);
w.push_str(GLYPH);
w.push_str(" ");
w.push_str(colors.reset);
}
Loading
Loading