Skip to content

Commit e4f0662

Browse files
committed
Auto merge of #1395 - alexcrichton:profile, r=brson
* Don't use `{:?}` in profiling output, it's too noisy * Allow an integer to be specified with `CARGO_PROFILE` indicating how many levels deep should be printed.
2 parents 202131f + ffbb8cc commit e4f0662

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/cargo/core/resolver/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn resolve(summary: &Summary, method: Method,
138138
activations: HashMap::new(),
139139
visited: Rc::new(RefCell::new(HashSet::new())),
140140
});
141-
let _p = profile::start(format!("resolving: {:?}", summary));
141+
let _p = profile::start(format!("resolving: {}", summary.package_id()));
142142
match try!(activate(cx, registry, &summary, method)) {
143143
Ok(cx) => {
144144
debug!("resolved: {:?}", cx.resolve);

src/cargo/ops/cargo_rustc/fingerprint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>,
4444
pkg: &'a Package,
4545
target: &'a Target,
4646
kind: Kind) -> CargoResult<Preparation> {
47-
let _p = profile::start(format!("fingerprint: {} / {:?}",
48-
pkg.package_id(), target));
47+
let _p = profile::start(format!("fingerprint: {} / {}",
48+
pkg.package_id(), target.name()));
4949
let new = dir(cx, pkg, kind);
5050
let loc = new.join(&filename(target));
5151

src/cargo/util/profile.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ pub struct Profiler {
1414
desc: String,
1515
}
1616

17-
fn enabled() -> bool { env::var_os("CARGO_PROFILE").is_some() }
17+
fn enabled_level() -> Option<usize> {
18+
env::var("CARGO_PROFILE").ok().and_then(|s| s.parse().ok())
19+
}
1820

1921
pub fn start<T: fmt::Display>(desc: T) -> Profiler {
20-
if !enabled() { return Profiler { desc: String::new() } }
22+
if enabled_level().is_none() { return Profiler { desc: String::new() } }
2123

2224
PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::precise_time_ns()));
2325

@@ -28,22 +30,26 @@ pub fn start<T: fmt::Display>(desc: T) -> Profiler {
2830

2931
impl Drop for Profiler {
3032
fn drop(&mut self) {
31-
if !enabled() { return }
33+
let enabled = match enabled_level() {
34+
Some(i) => i,
35+
None => return,
36+
};
3237

3338
let start = PROFILE_STACK.with(|stack| stack.borrow_mut().pop().unwrap());
3439
let end = time::precise_time_ns();
3540

3641
let stack_len = PROFILE_STACK.with(|stack| stack.borrow().len());
3742
if stack_len == 0 {
38-
fn print(lvl: usize, msgs: &[Message]) {
43+
fn print(lvl: usize, msgs: &[Message], enabled: usize) {
44+
if lvl > enabled { return }
3945
let mut last = 0;
4046
for (i, &(l, time, ref msg)) in msgs.iter().enumerate() {
4147
if l != lvl { continue }
4248
println!("{} {:6}ms - {}",
4349
repeat(" ").take(lvl + 1).collect::<String>(),
4450
time / 1000000, msg);
4551

46-
print(lvl + 1, &msgs[last..i]);
52+
print(lvl + 1, &msgs[last..i], enabled);
4753
last = i;
4854
}
4955

@@ -52,7 +58,7 @@ impl Drop for Profiler {
5258
let mut msgs = msgs_rc.borrow_mut();
5359
msgs.push((0, end - start,
5460
mem::replace(&mut self.desc, String::new())));
55-
print(0, &msgs);
61+
print(0, &msgs, enabled);
5662
});
5763
} else {
5864
MESSAGES.with(|msgs| {

0 commit comments

Comments
 (0)