Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created April 5, 2016 17:43
Show Gist options
  • Save alexcrichton/70a80cef34c5c5d92e9a9a8bfc146276 to your computer and use it in GitHub Desktop.
Save alexcrichton/70a80cef34c5c5d92e9a9a8bfc146276 to your computer and use it in GitHub Desktop.
use std::io::prelude::*;
// use std::collections::HashMap;
use std::io;
#[derive(Debug)]
struct Instance {
name: String,
start: Option<String>,
end: Option<String>,
}
fn main() {
let input = io::stdin();
let mut input = input.lock();
let mut map = HashMap::new();
for line in input.lines() {
let line = line.unwrap();
println!("process: {}", line);
let mut parts = line.splitn(2, ":");
let _logfile = parts.next().unwrap();
let rest = parts.next().unwrap();
let mut parts = line.split(" [-] ");
let stamp = parts.next().unwrap();
let rest = parts.next().unwrap();
let words = rest.split_whitespace().collect::<Vec<_>>();
let instance = words.iter().find(|a| a.starts_with("i-")).unwrap();
let name = words[1].to_owned();
let mut entry = map.entry(instance.to_owned()).or_insert(Instance {
name: name,
start: None,
end: None,
});
if rest.contains("terminating") {
assert!(entry.end.is_none());
entry.end = Some(stamp.to_string());
}
if rest.contains("waiting for") {
assert!(entry.start.is_none());
entry.start = Some(stamp.to_string());
}
}
println!("{:?}", map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment