OXYGENHUB

Coverage / src/main.rs 100.0%

14 of 14 lines run, 1 of 2 functions · run #269 on main · run missed

1
//! `oxy`: command-line interface for Oxygen.
2
//!
3
//! Command definitions and dispatch live in `cli`; each command group has
4
//! its own module there.
5
6
mod cli;
7
8
#[cfg(feature = "alloc-stats")]
9
#[global_allocator]
10
static ALLOC: oxy_core::alloc_stats::Counting = oxy_core::alloc_stats::Counting;
11
12
// Many small allocations from every thread (paths, entries, atoms): mimalloc
13
// serves them from per-thread pages without the arena locks of glibc's.
14
#[cfg(not(feature = "alloc-stats"))]
15
#[global_allocator]
16
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
17
18145×
fn main() {
19
    // Behave like other CLI tools when output is piped into `head`: die
20
    // quietly on SIGPIPE instead of panicking on a failed write.
21
    #[cfg(unix)]
22145×
    unsafe {
23145×
        libc::signal(libc::SIGPIPE, libc::SIG_DFL);
24145×
    }
25
    // With the counting allocator (over glibc's): glibc gives each thread
26
    // that allocates an arena of its own and keeps what is freed there: the
27
    // first commit of the Linux tree, read and hashed across threads, held
28
    // 4.3 GB for 2.7 GB in use. Two arenas hold 3.1 GB, no slower.
29
    // MALLOC_ARENA_MAX still has the last word.
30
    #[cfg(all(target_os = "linux", target_env = "gnu", feature = "alloc-stats"))]
31
    if std::env::var_os("MALLOC_ARENA_MAX").is_none() {
32
        unsafe {
33
            libc::mallopt(libc::M_ARENA_MAX, 2);
34
        }
35
    }
36145×
    let command = oxy_core::timing::phase("command");
37145×
    let result = cli::run();
38145×
    drop(command);
39145×
    oxy_core::timing::memory_summary();
40145×
    match result {
41138×
        Ok(code) => std::process::exit(code),
427×
        Err(e) => {
437×
            cli::ui::init(false);
447×
            eprintln!("{} {e:#}", cli::ui::err("error:"));
457×
            std::process::exit(1);
46
        }
47
    }
48
}