Skip to content

Commit e9b5e24

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 0ddcf1c commit e9b5e24

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

Cargo.lock

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4
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

+7
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

+14
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

+21-6
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,30 @@ pub fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
166166
use std::os::unix::fs::OpenOptionsExt;
167167
opts.mode(mode);
168168
}
169-
opts.write(true)
170-
.create(true)
171-
.truncate(true)
172-
.open(path.as_ref())?
173-
.write_all(contents.as_ref())
169+
let path = path.as_ref();
170+
let path_display = format!("{}", path.display());
171+
let mut f = {
172+
trace_scoped!("creat", "name": path_display);
173+
opts.write(true).create(true).truncate(true).open(path)?
174+
};
175+
let contents = contents.as_ref();
176+
let len = contents.len();
177+
{
178+
trace_scoped!("write", "name": path_display, "len": len);
179+
f.write_all(contents)?;
180+
}
181+
{
182+
trace_scoped!("close", "name:": path_display);
183+
drop(f);
184+
}
185+
Ok(())
174186
}
175187

176188
pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
177-
std::fs::create_dir(path.as_ref())
189+
let path = path.as_ref();
190+
let path_display = format!("{}", path.display());
191+
trace_scoped!("create_dir", "name": path_display);
192+
std::fs::create_dir(path)
178193
}
179194

180195
/// Get the executor for disk IO.

src/dist/component/package.rs

+2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ fn unpack_without_first_dir<'a, R: Read>(
297297
// leave till later.
298298

299299
if !parent.exists() {
300+
let path_display = format!("{}", parent.display());
301+
trace_scoped!("create_dir_all", "name": path_display);
300302
std::fs::create_dir_all(&parent).chain_err(|| ErrorKind::ExtractingPackage)?
301303
}
302304
}

src/lib.rs

+3
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)