-
Notifications
You must be signed in to change notification settings - Fork 26
Perform some housekeeping #95
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,12 +70,10 @@ pub fn read_analyis_incremental<L: AnalysisLoader>( | |
} | ||
|
||
match timestamps.get(&path) { | ||
Some(t) => if time > t { | ||
read_crate_data(&path) | ||
.map(|a| result.push(Crate::new(a, *time, Some(path)))); | ||
}, | ||
// A crate we've never seen before. | ||
None => { | ||
// We have fresher data than what we can read. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wanted to get rid of defining the same block twice for two cases, is this okay? |
||
Some(t) => if time <= t {}, | ||
// We have old data or it's a crate we've never seen before. | ||
_ => { | ||
read_crate_data(&path) | ||
.map(|a| result.push(Crate::new(a, *time, Some(path)))); | ||
} | ||
|
@@ -105,14 +103,21 @@ fn ignore_data(file_name: &str, crate_blacklist: Blacklist) -> bool { | |
false | ||
} | ||
|
||
fn read_file_contents(path: &Path) -> Result<String, ::std::io::Error> { | ||
let mut file = File::open(&path)?; | ||
let mut buf = String::new(); | ||
file.read_to_string(&mut buf)?; | ||
Ok(buf) | ||
} | ||
|
||
fn read_crate_data(path: &Path) -> Option<Analysis> { | ||
trace!("read_crate_data {:?}", path); | ||
// TODO unwraps | ||
let t = Instant::now(); | ||
let mut file = File::open(&path).unwrap(); | ||
let mut buf = String::new(); | ||
file.read_to_string(&mut buf).unwrap(); | ||
|
||
let buf = read_file_contents(path).or_else(|err| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separated into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, seems good to acknowledge the error |
||
info!("couldn't read file: {}", err); | ||
Err(err) | ||
}).ok()?; | ||
let s = ::rustc_serialize::json::decode(&buf); | ||
|
||
let d = t.elapsed(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,17 @@ | |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
macro_rules! option_try( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. impl Try for Option has landed! 🎉 |
||
($e:expr) => (match $e { Some(e) => e, None => return None }) | ||
); | ||
|
||
#[cfg(unix)] | ||
pub fn get_resident() -> Option<usize> { | ||
use std::fs::File; | ||
use std::io::Read; | ||
|
||
let field = 1; | ||
let mut f = option_try!(File::open("/proc/self/statm").ok()); | ||
let mut f = File::open("/proc/self/statm").ok()?; | ||
let mut contents = String::new(); | ||
option_try!(f.read_to_string(&mut contents).ok()); | ||
let s = option_try!(contents.split_whitespace().nth(field)); | ||
let npages = option_try!(s.parse::<usize>().ok()); | ||
f.read_to_string(&mut contents).ok()?; | ||
let s = contents.split_whitespace().nth(field)?; | ||
let npages = s.parse::<usize>().ok()?; | ||
Some(npages * 4096) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, since the previous link was invalid