Skip to content

Commit

Permalink
Merge pull request #1076 from googlefonts/crater-show-elapsed
Browse files Browse the repository at this point in the history
[crater] Show runtime in html
  • Loading branch information
cmyr authored Oct 30, 2024
2 parents 49f16f9 + 19f6db1 commit 0a5482f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion fontc_crater/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ td {
font-size: 0.8em;
}

.elapsed {
color: #888;
font-size: 0.8em;
}

td.rev {
font-family: monospace;
}
Expand Down Expand Up @@ -75,7 +80,6 @@ td.rev {
}

.changed_tag_list {
/*display: inline-block;*/
font-family: monospace;
font-size: 0.8em;
color: #888;
Expand Down
22 changes: 21 additions & 1 deletion fontc_crater/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

use std::{
collections::BTreeMap,
fmt::Write,
path::{Path, PathBuf},
};

use chrono::{DateTime, Utc};
use chrono::{DateTime, TimeZone, Utc};
use google_fonts_sources::{Config, RepoInfo};
use serde::de::DeserializeOwned;

Expand Down Expand Up @@ -103,13 +104,17 @@ fn run_crater_and_save_results(args: &CiArgs) -> Result<(), Error> {
log::info!("using cache dir {}", cache_dir.display());

let (targets, source_repos) = make_targets(&cache_dir, &inputs);
let n_targets = targets.len();
let began = Utc::now();
let results = super::run_all(targets, &cache_dir, super::ttx_diff_runner::run_ttx_diff)?
.into_iter()
.map(|(target, result)| (target.id(), result))
.collect();
let finished = Utc::now();

let elapsed = format_elapsed_time(&began, &finished);
log::info!("completed {n_targets} targets in {elapsed}");

let summary = super::ttx_diff_runner::Summary::new(&results);
if Some(&summary) == prev_runs.last().map(|run| &run.stats) {
log::info!("output identical to last run, skipping");
Expand Down Expand Up @@ -226,3 +231,18 @@ fn should_build_in_gftools_mode(src_path: &Path, config: &Config) -> bool {
.filter(|provider| *provider != "googlefonts")
.is_none()
}

fn format_elapsed_time<Tmz: TimeZone>(start: &DateTime<Tmz>, end: &DateTime<Tmz>) -> String {
let delta = end.clone().signed_duration_since(start);
let mut out = String::new();
let hours = delta.num_hours();
let mins = delta.num_minutes() - hours * 60;
let secs = delta.num_seconds() - (hours * 60 + mins) * 60;
assert!(!hours.is_negative() | mins.is_negative() | secs.is_negative());
if delta.num_hours() > 0 {
write!(&mut out, "{hours}h").unwrap();
}
write!(&mut out, "{mins}m").unwrap();
write!(&mut out, "{secs}s").unwrap();
out
}
3 changes: 2 additions & 1 deletion fontc_crater/src/ci/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ fn make_table_body(runs: &[RunSummary]) -> Markup {
td.other_err { (run.stats.other_failure) " " (other_err_diff) }
}
};
let elapsed = super::format_elapsed_time(&run.began, &run.finished);
html! {
tr.run {
td.date { (run.began.format("%Y-%m-%d %H:%M:%S")) }
td.date { (run.began.format("%Y-%m-%d %H%M")) span.elapsed { " (" (elapsed) ")"} }
td.rev { a href=(diff_url) { (short_rev) } }
td.total { ( run.stats.total_targets) " " (total_diff) }
td.identical { (run.stats.identical) " " (identical_diff) }
Expand Down

0 comments on commit 0a5482f

Please sign in to comment.