diff --git a/Cargo.lock b/Cargo.lock index 8ddc094..6b9019c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,6 +329,8 @@ dependencies = [ "anyhow", "cargo", "chrono", + "env_logger", + "log", "semver", "structopt", "termcolor", @@ -666,6 +668,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1528,6 +1543,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + [[package]] name = "hex" version = "0.4.3" @@ -1670,6 +1691,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "itertools" version = "0.10.5" diff --git a/Cargo.toml b/Cargo.toml index c6e5d50..5029fb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,5 @@ chrono = "0.4.6" structopt = { version = "^0.3", default-features = false } semver = "1.0" termcolor = "1.0" +env_logger = "0.10.0" +log = "0.4.20" diff --git a/src/app.rs b/src/app.rs index b161d9b..80d8458 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,6 +18,7 @@ use crate::opt::{AppConfig, CargoOpts, Target}; pub(crate) fn run(app_config: AppConfig) -> Result<()> { // 1. Detect the type of Xcode Instruments installation let xctrace_tool = instruments::XcodeInstruments::detect()?; + log::debug!("using {xctrace_tool}"); // 2. Render available templates if the user asked if app_config.list_templates { @@ -35,6 +36,8 @@ pub(crate) fn run(app_config: AppConfig) -> Result<()> { None => important_paths::find_root_manifest_for_wd(cargo_config.cwd()), }?; + log::debug!("using cargo manifest at {}", manifest_path.display()); + let workspace = Workspace::new(&manifest_path, &cargo_config)?; // 3.1: warn if --open passed. We do this here so we have access to cargo's @@ -48,6 +51,8 @@ pub(crate) fn run(app_config: AppConfig) -> Result<()> { } let cargo_options = app_config.to_cargo_opts()?; + + log::debug!("building profile target {}", cargo_options.target); let target_filepath = match build_target(&cargo_options, &workspace) { Ok(path) => path, Err(e) => { @@ -56,6 +61,8 @@ pub(crate) fn run(app_config: AppConfig) -> Result<()> { } }; + log::debug!("running against target {}", target_filepath.display()); + #[cfg(target_arch = "aarch64")] codesign(&target_filepath, &workspace)?; @@ -176,7 +183,7 @@ fn make_compile_opts(cargo_options: &CargoOpts, cfg: &Config) -> Result (vec![bin.clone()], vec![], vec![]), Target::Example(bin) => (vec![], vec![bin.clone()], vec![]), diff --git a/src/instruments.rs b/src/instruments.rs index c0050b9..16afa6c 100644 --- a/src/instruments.rs +++ b/src/instruments.rs @@ -1,6 +1,6 @@ //! interfacing with the `instruments` command line tool -use std::fmt::Write; +use std::fmt::{Display, Write}; use std::fs; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; @@ -485,6 +485,15 @@ fn get_tty() -> Result> { .map(|tty| format!("/dev/{}", tty))) } +impl Display for XcodeInstruments { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + XcodeInstruments::XcTrace => f.write_str("xctrace"), + XcodeInstruments::InstrumentsBinary => f.write_str("legacy instruments binary"), + } + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/main.rs b/src/main.rs index d1921c1..ca0f89f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ mod opt; compile_error!("cargo-instruments requires macOS."); fn main() { + env_logger::init(); use structopt::StructOpt; let opt::Cli::Instruments(args) = opt::Cli::from_args(); diff --git a/src/opt.rs b/src/opt.rs index b66db13..1138165 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -115,7 +115,7 @@ pub(crate) struct AppConfig { /// Represents the kind of target to profile. #[derive(Debug, PartialEq)] pub(crate) enum Target { - Main, + Default, Example(String), Bin(String), Bench(String), @@ -151,10 +151,10 @@ impl fmt::Display for Package { impl fmt::Display for Target { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Target::Main => write!(f, "src/main.rs"), - Target::Example(bin) => write!(f, "examples/{}.rs", bin), - Target::Bin(bin) => write!(f, "bin/{}.rs", bin), - Target::Bench(bench) => write!(f, "bench {}", bench), + Target::Default => write!(f, "default"), + Target::Example(bin) => write!(f, "{bin} (example)",), + Target::Bin(bin) => write!(f, "{bin} (bin)"), + Target::Bench(bench) => write!(f, "{bench} (bench)"), } } } @@ -201,7 +201,7 @@ impl AppConfig { } else if let Some(ref bench) = self.bench { Target::Bench(bench.clone()) } else { - Target::Main + Target::Default } } }