Skip to content

Commit 6083780

Browse files
committed
Remove dependency on time in favor of std::time
1 parent 7199e24 commit 6083780

4 files changed

Lines changed: 8 additions & 20 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ semver = "0.2.2"
4141
tar = "0.4"
4242
tempdir = "0.3"
4343
term = "0.4.4"
44-
time = "0.1"
4544
toml = "0.1"
4645
url = "1.1"
4746
winapi = "0.2"

src/cargo/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extern crate semver;
2222
extern crate tar;
2323
extern crate tempdir;
2424
extern crate term;
25-
extern crate time;
2625
extern crate toml;
2726
extern crate url;
2827

src/cargo/util/profile.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::env;
22
use std::fmt;
33
use std::mem;
4-
use time;
4+
use std::time;
55
use std::iter::repeat;
66
use std::cell::RefCell;
77

8-
thread_local!(static PROFILE_STACK: RefCell<Vec<u64>> = RefCell::new(Vec::new()));
8+
thread_local!(static PROFILE_STACK: RefCell<Vec<time::Instant>> = RefCell::new(Vec::new()));
99
thread_local!(static MESSAGES: RefCell<Vec<Message>> = RefCell::new(Vec::new()));
1010

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

24-
PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::precise_time_ns()));
24+
PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::Instant::now()));
2525

2626
Profiler {
2727
desc: desc.to_string(),
@@ -36,7 +36,8 @@ impl Drop for Profiler {
3636
};
3737

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

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

5253
print(lvl + 1, &msgs[last..i], enabled);
5354
last = i;
@@ -56,14 +57,14 @@ impl Drop for Profiler {
5657
}
5758
MESSAGES.with(|msgs_rc| {
5859
let mut msgs = msgs_rc.borrow_mut();
59-
msgs.push((0, end - start,
60+
msgs.push((0, duration_ms,
6061
mem::replace(&mut self.desc, String::new())));
6162
print(0, &msgs, enabled);
6263
});
6364
} else {
6465
MESSAGES.with(|msgs| {
6566
let msg = mem::replace(&mut self.desc, String::new());
66-
msgs.borrow_mut().push((stack_len, end - start, msg));
67+
msgs.borrow_mut().push((stack_len, duration_ms, msg));
6768
});
6869
}
6970
}

0 commit comments

Comments
 (0)