main.rs

 1use std::{
 2    path::Path,
 3    sync::{Arc, atomic::AtomicUsize},
 4};
 5
 6use fs::RealFs;
 7use gpui::Application;
 8use settings::Settings;
 9use worktree::{Worktree, WorktreeSettings};
10
11fn main() {
12    let Some(worktree_root_path) = std::env::args().nth(1) else {
13        println!(
14            "Missing path to worktree root\nUsage: bench_background_scan PATH_TO_WORKTREE_ROOT"
15        );
16        return;
17    };
18    let app = Application::headless();
19
20    app.run(|cx| {
21        settings::init(cx);
22        WorktreeSettings::register(cx);
23        let fs = Arc::new(RealFs::new(None, cx.background_executor().clone()));
24
25        cx.spawn(async move |cx| {
26            let worktree = Worktree::local(
27                Path::new(&worktree_root_path),
28                true,
29                fs,
30                Arc::new(AtomicUsize::new(0)),
31                cx,
32            )
33            .await
34            .expect("Worktree initialization to succeed");
35            let did_finish_scan = worktree
36                .update(cx, |this, _| this.as_local().unwrap().scan_complete())
37                .unwrap();
38            let start = std::time::Instant::now();
39            did_finish_scan.await;
40            let elapsed = start.elapsed();
41            let (files, directories) = worktree
42                .read_with(cx, |this, _| (this.file_count(), this.dir_count()))
43                .unwrap();
44            println!(
45                "{:?} for {directories} directories and {files} files",
46                elapsed
47            );
48            cx.update(|cx| {
49                cx.quit();
50            })
51        })
52        .detach();
53    })
54}