OXYGENHUB

Coverage / src/main.rs 100.0%

17 of 17 lines run, 1 of 2 functions · run #423 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
18187×
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)]
22187×
    unsafe {
23187×
        libc::signal(libc::SIGPIPE, libc::SIG_DFL);
24187×
    }
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
    }
36187×
    let command = oxy_core::timing::phase("command");
37187×
    let result = cli::run();
38187×
    if result.is_ok() {
39174×
        cli::after_command();
40174×
    }
41187×
    drop(command);
42187×
    oxy_core::timing::memory_summary();
43187×
    match result {
44176×
        Ok(code) => std::process::exit(code),
4511×
        Err(e) => {
4611×
            cli::ui::init(false);
4711×
            eprintln!("{} {e:#}", cli::ui::err("error:"));
4811×
            std::process::exit(1);
49
        }
50
    }
51
}