Skip to content

Commit 6049732

Browse files
committed
Trace (most) installation disk operations
Adds a new environment variable to control tracing. Tracing is manual and can be expanded. We can probably get better systemic tracing from a suite of platform specific tools over time, but for now this was low hanging fruit that allows pretty good insight without too much code intrusion. Runtime overhead when disabled is extremely low (I can unpack rust-docs on Linux in 1s).
1 parent d3a0c0e commit 6049732

File tree

7 files changed

+68
-11
lines changed

7 files changed

+68
-11
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ xz2 = "0.1.3"
5959
version = "0.5"
6060
default-features = false
6161

62+
[dependencies.rs_tracing]
63+
version = "1.0.1"
64+
features = ["rs_tracing"]
65+
6266
[target."cfg(windows)".dependencies]
6367
cc = "1"
6468
winreg = "0.6"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,13 @@ Command | Description
616616
single-threaded IO for troubleshooting, or an arbitrary number to
617617
override automatic detection.
618618

619+
- `RUSTUP_TRACE_DIR` (default: no tracing)
620+
Enables tracing and determines the directory that traces will be
621+
written too. Traces are of the form PID.trace. Traces can be read
622+
by the Catapult project [tracing viewer][tv].
623+
624+
[tv]: (https://github.com/catapult-project/catapult/blob/master/tracing/README.md)
625+
619626
## Other installation methods
620627

621628
The primary installation method, as described at https://rustup.rs, differs by platform:

src/cli/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ mod term2;
3030

3131
use crate::errors::*;
3232
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
33+
3334
use std::env;
3435
use std::path::PathBuf;
3536

37+
use rs_tracing::*;
38+
3639
fn main() {
3740
if let Err(ref e) = run_rustup() {
3841
common::report_error(e);
@@ -41,6 +44,17 @@ fn main() {
4144
}
4245

4346
fn run_rustup() -> Result<()> {
47+
if let Ok(dir) = env::var("RUSTUP_TRACE_DIR") {
48+
open_trace_file!(dir)?;
49+
}
50+
let result = run_rustup_inner();
51+
if let Ok(_) = env::var("RUSTUP_TRACE_DIR") {
52+
close_trace_file!();
53+
}
54+
result
55+
}
56+
57+
fn run_rustup_inner() -> Result<()> {
4458
// Guard against infinite proxy recursion. This mostly happens due to
4559
// bugs in rustup.
4660
do_recursion_guard()?;

src/diskio/mod.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ impl Item {
9191
kind: Kind::Directory,
9292
start: 0.0,
9393
finish: 0.0,
94-
size:None,
94+
size: None,
9595
result: Ok(()),
96-
mode
96+
mode,
9797
}
9898
}
9999

@@ -104,9 +104,9 @@ impl Item {
104104
kind: Kind::File(content),
105105
start: 0.0,
106106
finish: 0.0,
107-
size:Some(len),
107+
size: Some(len),
108108
result: Ok(()),
109-
mode
109+
mode,
110110
}
111111
}
112112
}
@@ -123,7 +123,7 @@ pub trait Executor {
123123
/// Actually dispatch a operation. Feedback from the operation
124124
/// is given via the mpsc completion queue or immediately.
125125
/// This is called by the default execute() implementation.
126-
fn dispatch(& mut self, item: Item) -> Option<Item>;
126+
fn dispatch(&mut self, item: Item) -> Option<Item>;
127127

128128
/// True if the executor is ready for more work. Executors MUST
129129
/// always be ready for work if they have no in-progress work.
@@ -158,13 +158,28 @@ pub fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
158158
use std::os::unix::fs::OpenOptionsExt;
159159
opts.mode(mode);
160160
}
161-
opts.write(true)
162-
.create(true)
163-
.truncate(true)
164-
.open(path.as_ref())?
165-
.write_all(contents.as_ref())
161+
let path = path.as_ref();
162+
let path_display = format!("{}", path.display());
163+
let mut f = {
164+
trace_scoped!("creat", "name": path_display);
165+
opts.write(true).create(true).truncate(true).open(path)?
166+
};
167+
let contents = contents.as_ref();
168+
let len = contents.len();
169+
{
170+
trace_scoped!("write", "name": path_display, "len": len);
171+
f.write_all(contents)?;
172+
}
173+
{
174+
trace_scoped!("close", "name:": path_display);
175+
drop(f);
176+
}
177+
Ok(())
166178
}
167179

168180
pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
169-
std::fs::create_dir(path.as_ref())
181+
let path = path.as_ref();
182+
let path_display = format!("{}", path.display());
183+
trace_scoped!("create_dir", "name": path_display);
184+
std::fs::create_dir(path)
170185
}

src/dist/component/package.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ fn unpack_without_first_dir<'a, R: Read>(
316316
// leave till later.
317317

318318
if !parent.exists() {
319+
let path_display = format!("{}", parent.display());
320+
trace_scoped!("create_dir_all", "name": path_display);
319321
std::fs::create_dir_all(&parent).chain_err(|| ErrorKind::ExtractingPackage)?
320322
}
321323
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub use crate::notifications::*;
77
pub use crate::toolchain::*;
88
pub use crate::utils::{notify, toml_utils};
99

10+
#[macro_use]
11+
extern crate rs_tracing;
12+
1013
// A list of all binaries which Rustup will proxy.
1114
pub static TOOLS: &[&str] = &[
1215
"rustc",

0 commit comments

Comments
 (0)