log timing and sum for the day
This commit is contained in:
parent
b6e74935f1
commit
b77395eb49
3 changed files with 72 additions and 3 deletions
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -2,6 +2,33 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d87d9d13be47a5b7c3907137f1290b0459a7f80efb26be8c52afb11963bccb02"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasted"
|
name = "wasted"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
]
|
||||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = { version = "0.4.29", default-features = false }
|
||||||
|
|
47
src/main.rs
47
src/main.rs
|
@ -1,7 +1,16 @@
|
||||||
use std::{env, process::Command, time::SystemTime};
|
use std::{
|
||||||
|
env,
|
||||||
|
fs::{self, File},
|
||||||
|
io::Write,
|
||||||
|
process::{exit, Command},
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let start_time = SystemTime::now();
|
let start_time = SystemTime::now();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
println!("{:?}", args);
|
println!("{:?}", args);
|
||||||
|
@ -14,11 +23,43 @@ fn main() {
|
||||||
println!("starting build");
|
println!("starting build");
|
||||||
let exit_status = Command::new(cmd).args(&args[2..]).status();
|
let exit_status = Command::new(cmd).args(&args[2..]).status();
|
||||||
println!("\n");
|
println!("\n");
|
||||||
let time_taken = start_time.elapsed().unwrap();
|
let time_taken = start_time.elapsed();
|
||||||
println!("Took {:?}", time_taken);
|
println!("Took {:?}", time_taken);
|
||||||
|
|
||||||
|
log(&start_time);
|
||||||
|
|
||||||
println!("{:?}", exit_status);
|
println!("{:?}", exit_status);
|
||||||
if let Some(status) = exit_status.ok().and_then(|s| s.code()) {
|
if let Some(status) = exit_status.ok().and_then(|s| s.code()) {
|
||||||
std::process::exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn log(start: &SystemTime) -> Option<()> {
|
||||||
|
let start_time = start.duration_since(UNIX_EPOCH).ok()?.as_millis();
|
||||||
|
let duration = start.elapsed().ok()?.as_millis();
|
||||||
|
let mut history = fs::read_to_string("compiler_history.txt").unwrap_or_default();
|
||||||
|
history.push_str(&format!("{}:{}\n", start_time, duration));
|
||||||
|
|
||||||
|
let today = NaiveDateTime::from_timestamp_millis(start_time as i64)?;
|
||||||
|
let mut wasted = 0;
|
||||||
|
for line in history.lines() {
|
||||||
|
let (time, duration) = line.split_once(':')?;
|
||||||
|
let time: i64 = time.parse().ok()?;
|
||||||
|
let duration: i64 = duration.parse().ok()?;
|
||||||
|
let date = NaiveDateTime::from_timestamp_millis(time)?;
|
||||||
|
if date.date() == today.date() {
|
||||||
|
wasted += duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let sec = wasted / 1000 % 60;
|
||||||
|
let min = wasted / (60 * 1000) % 60;
|
||||||
|
let h = wasted / (60 * 60 * 1000);
|
||||||
|
println!("Total wasted today: {}h {}m {}s", h, min, sec);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut f = File::create("compiler_history.txt").unwrap();
|
||||||
|
f.write_all(history.as_bytes()).unwrap();
|
||||||
|
}
|
||||||
|
Some(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue