Skip to content

Commit

Permalink
Auto merge of #2691 - serprex:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Remove dependency on time in favor of std::time
  • Loading branch information
bors committed May 15, 2016
2 parents 5cb2bb1 + 6083780 commit 8bdec5e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ semver = "0.2.2"
tar = "0.4"
tempdir = "0.3"
term = "0.4.4"
time = "0.1"
toml = "0.1"
url = "1.1"
winapi = "0.2"
Expand Down
1 change: 0 additions & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern crate semver;
extern crate tar;
extern crate tempdir;
extern crate term;
extern crate time;
extern crate toml;
extern crate url;

Expand Down
15 changes: 8 additions & 7 deletions src/cargo/util/profile.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::env;
use std::fmt;
use std::mem;
use time;
use std::time;
use std::iter::repeat;
use std::cell::RefCell;

thread_local!(static PROFILE_STACK: RefCell<Vec<u64>> = RefCell::new(Vec::new()));
thread_local!(static PROFILE_STACK: RefCell<Vec<time::Instant>> = RefCell::new(Vec::new()));
thread_local!(static MESSAGES: RefCell<Vec<Message>> = RefCell::new(Vec::new()));

type Message = (usize, u64, String);
Expand All @@ -21,7 +21,7 @@ fn enabled_level() -> Option<usize> {
pub fn start<T: fmt::Display>(desc: T) -> Profiler {
if enabled_level().is_none() { return Profiler { desc: String::new() } }

PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::precise_time_ns()));
PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::Instant::now()));

Profiler {
desc: desc.to_string(),
Expand All @@ -36,7 +36,8 @@ impl Drop for Profiler {
};

let start = PROFILE_STACK.with(|stack| stack.borrow_mut().pop().unwrap());
let end = time::precise_time_ns();
let duration = start.elapsed();
let duration_ms = duration.as_secs() * 1000 + (duration.subsec_nanos() / 1000000) as u64;

let stack_len = PROFILE_STACK.with(|stack| stack.borrow().len());
if stack_len == 0 {
Expand All @@ -47,7 +48,7 @@ impl Drop for Profiler {
if l != lvl { continue }
println!("{} {:6}ms - {}",
repeat(" ").take(lvl + 1).collect::<String>(),
time / 1000000, msg);
time, msg);

print(lvl + 1, &msgs[last..i], enabled);
last = i;
Expand All @@ -56,14 +57,14 @@ impl Drop for Profiler {
}
MESSAGES.with(|msgs_rc| {
let mut msgs = msgs_rc.borrow_mut();
msgs.push((0, end - start,
msgs.push((0, duration_ms,
mem::replace(&mut self.desc, String::new())));
print(0, &msgs, enabled);
});
} else {
MESSAGES.with(|msgs| {
let msg = mem::replace(&mut self.desc, String::new());
msgs.borrow_mut().push((stack_len, end - start, msg));
msgs.borrow_mut().push((stack_len, duration_ms, msg));
});
}
}
Expand Down

0 comments on commit 8bdec5e

Please # to comment.