Skip to content

Commit 8ff0399

Browse files
committed
fix(cli): Improve chrome traces
I tried to focus on either hot spots or high level operations that cover a large span of time.
1 parent 60fb710 commit 8ff0399

File tree

16 files changed

+31
-1
lines changed

16 files changed

+31
-1
lines changed

src/bin/cargo/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::command_prelude::*;
1515
use crate::util::is_rustup;
1616
use cargo::util::style;
1717

18+
#[tracing::instrument(skip_all)]
1819
pub fn main(config: &mut LazyConfig) -> CliResult {
1920
let args = cli().try_get_matches()?;
2021

@@ -258,6 +259,7 @@ fn add_ssl(version_string: &mut String) {
258259
/// [`GlobalArgs`] need to be extracted before expanding aliases because the
259260
/// clap code for extracting a subcommand discards global options
260261
/// (appearing before the subcommand).
262+
#[tracing::instrument(skip_all)]
261263
fn expand_aliases(
262264
config: &mut Config,
263265
args: ArgMatches,
@@ -363,6 +365,7 @@ For more information, see issue #12207 <https://github.com/rust-lang/cargo/issue
363365
Ok((args, GlobalArgs::default()))
364366
}
365367

368+
#[tracing::instrument(skip_all)]
366369
fn config_configure(
367370
config: &mut Config,
368371
args: &ArgMatches,
@@ -443,6 +446,7 @@ impl Exec {
443446
}
444447
}
445448

449+
#[tracing::instrument(skip_all)]
446450
fn exec(self, config: &mut Config, subcommand_args: &ArgMatches) -> CliResult {
447451
match self {
448452
Self::Builtin(exec) => exec(config, subcommand_args),
@@ -514,6 +518,7 @@ impl GlobalArgs {
514518
}
515519
}
516520

521+
#[tracing::instrument(skip_all)]
517522
pub fn cli() -> Command {
518523
let usage = if is_rustup() {
519524
color_print::cstr!("<cyan,bold>cargo</> <cyan>[+toolchain] [OPTIONS] [COMMAND]</>\n <cyan,bold>cargo</> <cyan>[+toolchain] [OPTIONS]</> <cyan,bold>-Zscript</> <cyan><<MANIFEST_RS>> [ARGS]...</>")

src/bin/cargo/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ fn main() {
3636
}
3737

3838
fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
39+
#![allow(clippy::disallowed_methods)]
40+
3941
use tracing_subscriber::prelude::*;
4042

4143
let env = tracing_subscriber::EnvFilter::from_env("CARGO_LOG");
@@ -46,7 +48,6 @@ fn setup_logger() -> Option<tracing_chrome::FlushGuard> {
4648
.with_filter(env);
4749

4850
let (profile_layer, profile_guard) =
49-
#[allow(clippy::disallowed_methods)]
5051
if env_to_bool(std::env::var_os("_CARGO_LOG_PROFILE").as_deref()) {
5152
let capture_args =
5253
env_to_bool(std::env::var_os("_CARGO_LOG_PROFILE_CAPTURE_ARGS").as_deref());
@@ -303,6 +304,7 @@ fn search_directories(config: &Config) -> Vec<PathBuf> {
303304
}
304305

305306
/// Initialize libgit2.
307+
#[tracing::instrument(skip_all)]
306308
fn init_git(config: &Config) {
307309
// Disabling the owner validation in git can, in theory, lead to code execution
308310
// vulnerabilities. However, libgit2 does not launch executables, which is the foundation of

src/cargo/core/compiler/context/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
324324
.map(|output| output.bin_dst().clone()))
325325
}
326326

327+
#[tracing::instrument(skip_all)]
327328
pub fn prepare_units(&mut self) -> CargoResult<()> {
328329
let dest = self.bcx.profiles.get_dir_name();
329330
let host_layout = Layout::new(self.bcx.ws, None, &dest)?;
@@ -349,6 +350,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
349350

350351
/// Prepare this context, ensuring that all filesystem directories are in
351352
/// place.
353+
#[tracing::instrument(skip_all)]
352354
pub fn prepare(&mut self) -> CargoResult<()> {
353355
let _p = profile::start("preparing layout");
354356

@@ -451,6 +453,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
451453

452454
/// Check if any output file name collision happens.
453455
/// See <https://github.com/rust-lang/cargo/issues/6313> for more.
456+
#[tracing::instrument(skip_all)]
454457
fn check_collisions(&self) -> CargoResult<()> {
455458
let mut output_collisions = HashMap::new();
456459
let describe_collision = |unit: &Unit, other_unit: &Unit, path: &PathBuf| -> String {
@@ -633,6 +636,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
633636
/// If the current crate has reverse-dependencies, such a Check unit should exist, and so
634637
/// we use that crate's metadata. If not, we use the crate's Doc unit so at least examples
635638
/// scraped from the current crate can be used when documenting the current crate.
639+
#[tracing::instrument(skip_all)]
636640
pub fn compute_metadata_for_doc_units(&mut self) {
637641
for unit in self.bcx.unit_graph.keys() {
638642
if !unit.mode.is_doc() && !unit.mode.is_doc_scrape() {

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ impl<'cfg> JobQueue<'cfg> {
462462
/// This function will spawn off `config.jobs()` workers to build all of the
463463
/// necessary dependencies, in order. Freshness is propagated as far as
464464
/// possible along each dependency chain.
465+
#[tracing::instrument(skip_all)]
465466
pub fn execute(mut self, cx: &mut Context<'_, '_>, plan: &mut BuildPlan) -> CargoResult<()> {
466467
let _p = profile::start("executing the job graph");
467468
self.queue.queue_finished();

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl Executor for DefaultExecutor {
158158
/// Note that **no actual work is executed as part of this**, that's all done
159159
/// next as part of [`JobQueue::execute`] function which will run everything
160160
/// in order with proper parallelism.
161+
#[tracing::instrument(skip(cx, jobs, plan, exec))]
161162
fn compile<'cfg>(
162163
cx: &mut Context<'_, 'cfg>,
163164
jobs: &mut JobQueue<'cfg>,

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl IsArtifact {
8181
/// Then entry point for building a dependency graph of compilation units.
8282
///
8383
/// You can find some information for arguments from doc of [`State`].
84+
#[tracing::instrument(skip_all)]
8485
pub fn build_unit_dependencies<'a, 'cfg>(
8586
ws: &'a Workspace<'cfg>,
8687
package_set: &'a PackageSet<'cfg>,

src/cargo/core/global_cache_tracker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,7 @@ impl DeferredGlobalLastUse {
15671567
/// Saves all of the deferred information to the database.
15681568
///
15691569
/// This will also clear the state of `self`.
1570+
#[tracing::instrument(skip_all)]
15701571
pub fn save(&mut self, tracker: &mut GlobalCacheTracker) -> CargoResult<()> {
15711572
let _p = crate::util::profile::start("saving last-use data");
15721573
trace!(target: "gc", "saving last-use data");

src/cargo/core/package.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ impl<'cfg> PackageSet<'cfg> {
497497
}
498498

499499
/// Downloads any packages accessible from the give root ids.
500+
#[tracing::instrument(skip_all)]
500501
pub fn download_accessible(
501502
&self,
502503
resolve: &Resolve,

src/cargo/core/resolver/features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ pub struct FeatureResolver<'a, 'cfg> {
444444
impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
445445
/// Runs the resolution algorithm and returns a new [`ResolvedFeatures`]
446446
/// with the result.
447+
#[tracing::instrument(skip_all)]
447448
pub fn resolve(
448449
ws: &Workspace<'cfg>,
449450
target_data: &'a mut RustcTargetData<'cfg>,

src/cargo/core/resolver/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ mod version_prefs;
120120
///
121121
/// * `config` - a location to print warnings and such, or `None` if no warnings
122122
/// should be printed
123+
#[tracing::instrument(skip_all)]
123124
pub fn resolve(
124125
summaries: &[(Summary, ResolveOpts)],
125126
replacements: &[(PackageIdSpec, Dependency)],

0 commit comments

Comments
 (0)