Skip to content

Commit 8d18be4

Browse files
committed
fix: gate memsim example to Windows and fix clippy counter loop
The example uses the mimalloc allocator, libmimalloc-sys, and goz_winfs::self_memory, all Windows-only, so it failed to compile on the Ubuntu CI leg. Gate the whole example behind cfg(windows) with a non-Windows main stub, and fold the insertion counter into the iterator to satisfy clippy::explicit_counter_loop.
1 parent f27589f commit 8d18be4

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

crates/goz-daemon/examples/memsim.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,58 @@
44
//! hold for that volume set without needing to restart the service.
55
//!
66
//! Usage: `cargo run --release -p goz-daemon --example memsim -- <all.csv>`
7+
//!
8+
//! Windows only: it uses the mimalloc allocator and `goz_winfs::self_memory` to
9+
//! read the process's real footprint. On other targets it is an empty stub so
10+
//! `cargo build --all-targets` stays green everywhere.
11+
12+
#[cfg(not(windows))]
13+
fn main() {
14+
eprintln!("memsim is Windows-only (it measures the daemon's real footprint).");
15+
}
716

17+
#[cfg(windows)]
818
#[global_allocator]
919
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
1020

21+
#[cfg(windows)]
1122
use goz_core::index::{FrnMap, NTFS_ROOT_FRN, VolumeIndex};
23+
#[cfg(windows)]
1224
use goz_core::types::Frn;
25+
#[cfg(windows)]
1326
use goz_core::usn::record::{FILE_ATTRIBUTE_DIRECTORY, ParsedUsnRecord, USN_REASON_FILE_CREATE};
27+
#[cfg(windows)]
1428
use std::collections::{HashMap, HashSet};
29+
#[cfg(windows)]
1530
use std::io::BufRead;
1631

32+
#[cfg(windows)]
1733
fn mb(b: u64) -> f64 {
1834
b as f64 / 1e6
1935
}
2036

37+
#[cfg(windows)]
2138
fn private_mb() -> f64 {
2239
goz_winfs::self_memory()
2340
.map(|m| mb(m.private_bytes))
2441
.unwrap_or(0.0)
2542
}
2643

44+
#[cfg(windows)]
2745
fn purge() {
2846
// SAFETY: mi_collect takes no pointers and is safe from any thread.
2947
unsafe { libmimalloc_sys::mi_collect(true) };
3048
}
3149

3250
/// One entry to insert: parent record, name, is_dir.
51+
#[cfg(windows)]
3352
struct Row {
3453
parent_rec: u64,
3554
name: Vec<u8>,
3655
is_dir: bool,
3756
}
3857

58+
#[cfg(windows)]
3959
fn main() {
4060
let csv = std::env::args().nth(1).expect("usage: memsim <all.csv>");
4161
let t0 = std::time::Instant::now();
@@ -110,8 +130,7 @@ fn main() {
110130
// Insert everything, exactly as bootstrap ENUM would.
111131
let t1 = std::time::Instant::now();
112132
let mut idx = VolumeIndex::new(NTFS_ROOT_FRN, FrnMap::sparse());
113-
let mut rec_no: u64 = 1000;
114-
for row in &rows {
133+
for (rec_no, row) in (1000_u64..).zip(rows.iter()) {
115134
let r = ParsedUsnRecord {
116135
major_version: 3,
117136
frn: Frn(rec_no | (1u64 << 48)),
@@ -128,7 +147,6 @@ fn main() {
128147
name_lossy: false,
129148
};
130149
idx.insert_enum(&r);
131-
rec_no += 1;
132150
}
133151
eprintln!("inserted {} entries in {:?}", idx.len(), t1.elapsed());
134152

0 commit comments

Comments
 (0)