Skip to content

Commit 5ccb3f7

Browse files
committed
Build profile tweaks. Formatting tweaks.
1 parent d434d93 commit 5ccb3f7

File tree

7 files changed

+62
-33
lines changed

7 files changed

+62
-33
lines changed

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ tikv-jemallocator = "0.6.0"
3636
tikv-jemallocator = "0.6.0"
3737

3838
[profile.release]
39-
lto = "fat"
40-
strip = true
39+
opt-level = 3
40+
debug = "none"
41+
strip = "symbols"
42+
debug-assertions = false
4143
overflow-checks = true
42-
codegen-units = 1
44+
lto = "fat"
4345
panic = "abort"
46+
codegen-units = 1

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
max_width = 79
2+
use_small_heuristics = "max"

src/args.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ pub struct Args {
5858
fn parse_threads(x: &str) -> Result<usize, Error> {
5959
match x.parse::<usize>() {
6060
Ok(v) => match v {
61-
v if !(2..=65535).contains(&v) => Err(anyhow!("threads should be in (2..65536) range")),
61+
v if !(2..=65535).contains(&v) => {
62+
Err(anyhow!("threads should be in (2..65536) range"))
63+
}
6264
v => Ok(v),
6365
},
6466
Err(e) => Err(Error::from(e)),

src/calibrate.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ pub fn get_inode_ratio(
5858
shutdown: &Arc<AtomicBool>,
5959
args: &Arc<args::Args>,
6060
) -> Result<u64, Error> {
61-
println!(
62-
"Starting test directory calibration in {}",
63-
test_path.display(),
64-
);
61+
println!("Starting test directory calibration in {}", test_path.display(),);
6562

6663
// Thread pool for mass file creation
6764
let pool = rayon::ThreadPoolBuilder::new()
@@ -75,7 +72,8 @@ pub fn get_inode_ratio(
7572
pool.install(|| {
7673
(0..args.calibration_count).into_par_iter().for_each(|i| {
7774
if !shutdown.load(Ordering::Acquire) {
78-
File::create(test_path.join(i.to_string())).expect("Unable to create files");
75+
File::create(test_path.join(i.to_string()))
76+
.expect("Unable to create files");
7977
}
8078
});
8179
});
@@ -84,14 +82,20 @@ pub fn get_inode_ratio(
8482

8583
// Terminate on received interrupt signal
8684
if shutdown.load(Ordering::Acquire) {
87-
println!("Requested program exit, stopping and deleting temporary files...",);
88-
ensure_removed(test_path)
89-
.expect("Unable to completely delete calibration directory, exiting");
85+
println!(
86+
"Requested program exit, stopping and deleting temporary files...",
87+
);
88+
ensure_removed(test_path).expect(
89+
"Unable to completely delete calibration directory, exiting",
90+
);
9091
process::exit(ERROR_EXIT);
9192
}
9293

93-
let size_inode_ratio = fs::metadata(test_path)?.size() / args.calibration_count;
94-
println!("Calibration done. Calculated size-to-inode ratio: {size_inode_ratio}");
94+
let size_inode_ratio =
95+
fs::metadata(test_path)?.size() / args.calibration_count;
96+
println!(
97+
"Calibration done. Calculated size-to-inode ratio: {size_inode_ratio}"
98+
);
9599

96100
Ok(size_inode_ratio)
97101
}

src/interrupt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use anyhow::{Context, Error};
1515
///
1616
/// # Errors
1717
/// Returns an error if the Ctrl-C handler cannot be set, encapsulated in an `anyhow::Error`.
18-
pub fn setup_interrupt_handler(shutdown: Arc<AtomicBool>) -> Result<(), Error> {
18+
pub fn setup_interrupt_handler(
19+
shutdown: Arc<AtomicBool>,
20+
) -> Result<(), Error> {
1921
ctrlc::set_handler(move || {
2022
shutdown.store(true, Ordering::Release);
2123
})

src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ fn main() -> Result<(), Error> {
5252
let shutdown_scan = shutdown.clone();
5353
interrupt::setup_interrupt_handler(shutdown)?;
5454

55-
println!(
56-
"Using {} threads for calibration and scanning",
57-
args.threads
58-
);
55+
println!("Using {} threads for calibration and scanning", args.threads);
5956

6057
// Attempt to raise FD limit
6158
if let Ok(Outcome::LimitRaised { to: x, .. }) = raise_fd_limit() {
@@ -86,34 +83,37 @@ fn main() -> Result<(), Error> {
8683
} else if let Some(ref user_path) = args.calibration_path {
8784
// User has specified his calibration directory so attempt to check if it resides on
8885
// the same device
89-
if fs::metadata(user_path.as_path())?.dev() != path_metadata.dev() {
86+
if fs::metadata(user_path.as_path())?.dev() != path_metadata.dev()
87+
{
9088
println!(
9189
"Oops, test directory resides on a different device than path {}, results are possibly unreliable!",
9290
path.display()
9391
);
9492
}
9593

9694
// Prepare temporary calibration directory in user path
97-
let tmp_dir = Arc::new(
98-
TempDir::new_in(user_path.as_path())
99-
.context("Unable to setup/create calibration test directory")?,
100-
);
95+
let tmp_dir =
96+
Arc::new(TempDir::new_in(user_path.as_path()).context(
97+
"Unable to setup/create calibration test directory",
98+
)?);
10199

102100
calibrate::get_inode_ratio(tmp_dir.path(), &shutdown_scan, &args)
103101
.context("Unable to calibrate inode to size ratio")?
104102
} else {
105103
// Prepare temporary calibration directory in root of the search path
106-
let tmp_dir = Arc::new(
107-
TempDir::new_in(path.as_path())
108-
.context("Unable to setup/create calibration test directory")?,
109-
);
104+
let tmp_dir = Arc::new(TempDir::new_in(path.as_path()).context(
105+
"Unable to setup/create calibration test directory",
106+
)?);
110107

111108
calibrate::get_inode_ratio(tmp_dir.path(), &shutdown_scan, &args)
112109
.context("Unable to calibrate inode to size ratio")?
113110
};
114111

115112
let start = Instant::now();
116-
let pb = progress::new_spinner(format!("Scanning path {} in progress...", path.display()));
113+
let pb = progress::new_spinner(format!(
114+
"Scanning path {} in progress...",
115+
path.display()
116+
));
117117

118118
walk::parallel_search(
119119
&path,

src/walk.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ fn process_dir_entry<E>(
166166
dir_count_walk.fetch_add(1, Ordering::AcqRel);
167167

168168
// Ignore skip paths, typically being virtual filesystems (/proc, /dev, /sys, /run)
169-
if !skip_path.is_empty() && skip_path.contains(&full_path.to_path_buf()) {
169+
if !skip_path.is_empty()
170+
&& skip_path.contains(&full_path.to_path_buf())
171+
{
170172
println!(
171173
"Skipping further scan at {} as requested",
172174
full_path.display()
@@ -181,7 +183,9 @@ fn process_dir_entry<E>(
181183
// If `one_filesystem` flag has been set and if directory is not residing
182184
// on the same device as top search path, print warning and abort deeper
183185
// scanning
184-
if args.one_filesystem && (dir_entry_metadata.dev() != path_metadata.dev()) {
186+
if args.one_filesystem
187+
&& (dir_entry_metadata.dev() != path_metadata.dev())
188+
{
185189
println!(
186190
"Identified filesystem boundary at {}, skipping...",
187191
full_path.display()
@@ -197,10 +201,22 @@ fn process_dir_entry<E>(
197201

198202
// Print count warnings if necessary
199203
if approx_files > args.blacklist_threshold {
200-
print_offender(full_path, size, approx_files, args.accurate, true);
204+
print_offender(
205+
full_path,
206+
size,
207+
approx_files,
208+
args.accurate,
209+
true,
210+
);
201211
dir_entry.read_children_path = None;
202212
} else if approx_files > args.alert_threshold {
203-
print_offender(full_path, size, approx_files, args.accurate, false);
213+
print_offender(
214+
full_path,
215+
size,
216+
approx_files,
217+
args.accurate,
218+
false,
219+
);
204220
}
205221
}
206222
}

0 commit comments

Comments
 (0)