Skip to content

Commit e72bda1

Browse files
committed
feat(engine): implement run_engine function and update command handling
fix(logging): change debug logs to info for better visibility in MFT processing refactor(fixup): enhance logging format for entry size and count in apply_fixups_parallel
1 parent c9407ec commit e72bda1

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

src/cli/command/engine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::cli::to_args::ToArgs;
2+
use crate::engine::run::run_engine;
23
use arbitrary::Arbitrary;
34
use clap::Args;
45
use clap::Subcommand;
@@ -18,7 +19,7 @@ impl EngineArgs {
1819
pub fn invoke(self) -> eyre::Result<()> {
1920
match self.command {
2021
EngineCommand::Run => {
21-
println!("Engine command is a work in progress.");
22+
run_engine()?;
2223
Ok(())
2324
}
2425
}

src/engine/mft_file_plugin.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn on_sync_dir_added_emit_loads(
5454
.map(|ext| ext.eq_ignore_ascii_case("mft"))
5555
.unwrap_or(false);
5656
if is_mft && path.is_file() {
57-
debug!(?path, "Queueing MFT load from path");
57+
info!(?path, "Queueing MFT load from path");
5858
messages.write(MftFileMessage::LoadFromPath(path));
5959
}
6060
}
@@ -101,7 +101,7 @@ pub fn finish_mft_file_tasks(
101101
if let Some(result) = block_on(poll_once(task)) {
102102
match result {
103103
Ok(mft) => {
104-
debug!(?path, mft=?format!("{:?}", &mft), "Loaded MFT file from disk");
104+
info!(?path, mft=?format!("{:?}", &mft), "Loaded MFT file from disk");
105105
commands.spawn(mft);
106106
}
107107
Err(e) => {
@@ -111,6 +111,13 @@ pub fn finish_mft_file_tasks(
111111
completed.push(path.clone());
112112
}
113113
}
114+
if !completed.is_empty() {
115+
debug!(
116+
"Completed {} MFT load tasks, {} remaining",
117+
completed.len(),
118+
tasks.loading_from_disk.len() - completed.len()
119+
);
120+
}
114121
for path in completed {
115122
tasks.loading_from_disk.remove(&path);
116123
}

src/engine/run.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use bevy::log::LogPlugin;
44
use bevy::prelude::*;
55
use bevy::window::ExitCondition;
66
use compact_str::CompactString;
7+
use tracing::debug;
78

89
#[derive(Component, Reflect)]
910
pub struct PhysicalDiskLabel(pub CompactString);
1011

1112
pub fn run_engine() -> eyre::Result<()> {
13+
debug!("Building Bevy engine");
1214
let mut app = App::new();
1315
app.add_plugins(
1416
DefaultPlugins
@@ -21,6 +23,9 @@ pub fn run_engine() -> eyre::Result<()> {
2123
);
2224
app.add_plugins(SyncDirectoryPlugin);
2325
app.add_plugins(MftFilePlugin);
26+
debug!("Bevy engine built");
27+
28+
info!("Running Bevy engine");
2429
app.run();
2530
Ok(())
2631
}

src/engine/sync_dir_plugin.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use bevy::tasks::IoTaskPool;
55
use bevy::tasks::Task;
66
use bevy::tasks::block_on;
77
use bevy::tasks::poll_once;
8+
use std::any::type_name;
89
use std::ops::Deref;
910
use std::path::PathBuf;
1011

1112
pub struct SyncDirectoryPlugin;
1213
impl Plugin for SyncDirectoryPlugin {
1314
fn build(&self, app: &mut App) {
14-
app.register_type::<SyncDirectory>();
15+
app.register_type::<SyncDirectory>();
1516
app.register_type::<SyncDirectoryEvents>();
1617
app.init_resource::<SyncDirectoryTasks>();
1718
app.add_message::<SyncDirectoryEvents>();
@@ -61,6 +62,7 @@ pub fn read_sync_directory_events_and_launch_task(
6162
mut tasks: ResMut<SyncDirectoryTasks>,
6263
) -> Result<()> {
6364
for ev in events.read() {
65+
info!(event=?ev, "Processing {}", type_name::<SyncDirectoryEvents>());
6466
match ev {
6567
SyncDirectoryEvents::ReadSyncDirectory => {
6668
if tasks.get_sync_dir.is_some() {
@@ -75,7 +77,7 @@ pub fn read_sync_directory_events_and_launch_task(
7577
let path = try_get_sync_dir()?;
7678
Ok(SyncDirectory(path))
7779
});
78-
debug!(task=?task, "Spawned task to load sync dir from preferences");
80+
info!(task=?task, "Spawned task to load sync dir from preferences");
7981
tasks.get_sync_dir = Some(task);
8082
}
8183
}
@@ -91,7 +93,7 @@ pub fn finish_load_sync_dir_from_preferences(
9193
if let Some(task) = tasks.get_sync_dir.as_mut() {
9294
if let Some(result) = block_on(poll_once(task)) {
9395
let sync_dir = result?;
94-
debug!(sync_dir=?sync_dir, "Loaded sync dir from preferences");
96+
info!(sync_dir=?sync_dir, "Loaded sync dir from preferences");
9597
if let Ok(entity) = existing.single() {
9698
commands.entity(entity).insert(sync_dir);
9799
} else {

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(btree_cursors)]
2-
pub mod engine;
32
pub mod cli;
43
pub mod drive_letter_pattern;
4+
pub mod engine;
55
pub mod mft;
66
pub mod mft_check;
77
pub mod mft_process;
@@ -25,15 +25,16 @@ use tracing_subscriber::util::SubscriberInitExt;
2525
/// In debug builds, include file and line number without timestamp.
2626
/// In release builds, include timestamp and log level.
2727
pub fn init_tracing(level: Level) {
28-
let builder = tracing_subscriber::fmt().with_env_filter(
29-
EnvFilter::try_from_default_env().unwrap_or_else(|_| {
28+
let builder = tracing_subscriber::fmt()
29+
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| {
3030
EnvFilter::builder().parse_lossy(format!(
3131
"{default_log_level},{bevy_defaults}",
3232
default_log_level = level,
3333
bevy_defaults = DEFAULT_FILTER
3434
))
35-
}),
36-
);
35+
}))
36+
.with_writer(std::io::stderr)
37+
.pretty();
3738
#[cfg(debug_assertions)]
3839
let subscriber = builder
3940
.with_target(false)

src/mft/fast_fixup.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ pub fn apply_fixups_parallel(buf: &mut [u8], entry_size: usize) -> FixupStats {
174174
let entry_count = buf.len() / entry_size;
175175
debug!(
176176
"Detected entry size: {} bytes, total entries: {}",
177-
entry_size,
178-
entry_count
177+
entry_size.separate_with_commas(),
178+
entry_count.separate_with_commas()
179179
);
180180

181181
let start = Instant::now();
@@ -203,12 +203,13 @@ pub fn apply_fixups_parallel(buf: &mut [u8], entry_size: usize) -> FixupStats {
203203
let total_size = Information::new::<byte>(buf.len() as f64);
204204
let rate = total_size / elapsed;
205205
debug!(
206-
"Took {} ({}/s) applied/already/invalid={}/{}/{}",
207-
elapsed.get_human(),
208-
rate.get::<hertz>().trunc().separate_with_commas(),
209-
stats.applied.separate_with_commas(),
210-
stats.already_applied.separate_with_commas(),
211-
stats.invalid.separate_with_commas()
206+
"Took {elapsed} to process {count} records ({rate}/s) - fixup stats: applied={applied} already-applied={already_applied} invalid={invalid}",
207+
elapsed = elapsed.get_human(),
208+
count = entry_count.separate_with_commas(),
209+
rate = rate.get::<hertz>().trunc().separate_with_commas(),
210+
applied = stats.applied.separate_with_commas(),
211+
already_applied = stats.already_applied.separate_with_commas(),
212+
invalid = stats.invalid.separate_with_commas()
212213
);
213214

214215
stats

src/mft/mft_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ impl MftFile {
9898

9999
// Log summary
100100
debug!(
101-
"Read {} in {:.2?}, found entry size {} and {} entries",
101+
"Read {} in {:.2?}, found entry size {} bytes and {} entries",
102102
mft_file_size.get_human(),
103103
read_start.elapsed(),
104-
rtn.entry_size().get_human(),
104+
rtn.entry_size().get::<byte>().separate_with_commas(),
105105
rtn.entry_count().separate_with_commas()
106106
);
107107

0 commit comments

Comments
 (0)