Skip to content

Commit

Permalink
oxidd-cli: add option to output durations as seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
nhusung committed Feb 19, 2025
1 parent 97a18e1 commit 3d0fbff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/oxidd-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ struct Cli {
#[arg(long, default_value_t = 0)]
threads: u32,

/// Always output durations as seconds (floating point)
#[arg(long)]
durations_as_secs: bool,

/// Report progress
#[arg(long, short = 'p')]
progress: bool,
Expand Down Expand Up @@ -489,6 +493,7 @@ where

fn main() {
let cli = Cli::parse();
util::DURATIONS_AS_SECS.store(cli.durations_as_secs, std::sync::atomic::Ordering::Relaxed);

if let (GateBuildScheme::WorkStealing, false) = (cli.gate_build_scheme, cli.parallel) {
eprintln!("--gate-build-order=work-stealing requires --parallel");
Expand Down
6 changes: 6 additions & 0 deletions crates/oxidd-cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
use std::fmt;
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
use std::time::Duration;

use oxidd::util::AllocResult;

// spell-checker:ignore subsec

pub static DURATIONS_AS_SECS: AtomicBool = AtomicBool::new(false);

/// Human-readable durations
pub struct HDuration(pub Duration);

impl fmt::Display for HDuration {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let d = self.0;
if DURATIONS_AS_SECS.load(Relaxed) {
return write!(f, "{} s", d.as_secs_f64());
}
let s = d.as_secs();
if s >= 60 {
let (m, s) = (s / 60, s % 60);
Expand Down

0 comments on commit 3d0fbff

Please sign in to comment.