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)],

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub fn compile_with_exec<'a>(
142142
}
143143

144144
/// Like [`compile_with_exec`] but without warnings from manifest parsing.
145+
#[tracing::instrument(skip_all)]
145146
pub fn compile_ws<'a>(
146147
ws: &Workspace<'a>,
147148
options: &CompileOptions,
@@ -197,6 +198,7 @@ pub fn print<'a>(
197198
///
198199
/// For how it works and what data it collects,
199200
/// please see the [module-level documentation](self).
201+
#[tracing::instrument(skip_all)]
200202
pub fn create_bcx<'a, 'cfg>(
201203
ws: &'a Workspace<'cfg>,
202204
options: &'a CompileOptions,

src/cargo/ops/lockfile.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::util::Filesystem;
66

77
use anyhow::Context as _;
88

9+
#[tracing::instrument(skip_all)]
910
pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult<Option<Resolve>> {
1011
let lock_root = lock_root(ws);
1112
if !lock_root.as_path_unlocked().join("Cargo.lock").exists() {
@@ -32,6 +33,7 @@ pub fn resolve_to_string(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoResu
3233
Ok(out)
3334
}
3435

36+
#[tracing::instrument(skip_all)]
3537
pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoResult<()> {
3638
let (orig, mut out, lock_root) = resolve_to_string_orig(ws, resolve);
3739

src/cargo/ops/resolve.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ pub fn resolve_ws_with_opts<'cfg>(
239239
})
240240
}
241241

242+
#[tracing::instrument(skip_all)]
242243
fn resolve_with_registry<'cfg>(
243244
ws: &Workspace<'cfg>,
244245
registry: &mut PackageRegistry<'cfg>,
@@ -278,6 +279,7 @@ fn resolve_with_registry<'cfg>(
278279
///
279280
/// If `register_patches` is true, then entries from the `[patch]` table in
280281
/// the manifest will be added to the given `PackageRegistry`.
282+
#[tracing::instrument(skip_all)]
281283
pub fn resolve_with_previous<'cfg>(
282284
registry: &mut PackageRegistry<'cfg>,
283285
ws: &Workspace<'cfg>,
@@ -536,6 +538,7 @@ pub fn resolve_with_previous<'cfg>(
536538

537539
/// Read the `paths` configuration variable to discover all path overrides that
538540
/// have been configured.
541+
#[tracing::instrument(skip_all)]
539542
pub fn add_overrides<'a>(
540543
registry: &mut PackageRegistry<'a>,
541544
ws: &Workspace<'a>,

src/cargo/util/command_prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ pub trait ArgMatchesExt {
500500
root_manifest(self._value_of("manifest-path").map(Path::new), config)
501501
}
502502

503+
#[tracing::instrument(skip_all)]
503504
fn workspace<'a>(&self, config: &'a Config) -> CargoResult<Workspace<'a>> {
504505
let root = self.root_manifest(config)?;
505506
let mut ws = Workspace::new(&root, config)?;

src/cargo/util/config/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,7 @@ impl Config {
19171917
/// Locks are usually acquired via [`Config::acquire_package_cache_lock`]
19181918
/// or [`Config::try_acquire_package_cache_lock`].
19191919
#[track_caller]
1920+
#[tracing::instrument(skip_all)]
19201921
pub fn assert_package_cache_locked<'a>(
19211922
&self,
19221923
mode: CacheLockMode,
@@ -1937,6 +1938,7 @@ impl Config {
19371938
///
19381939
/// See [`crate::util::cache_lock`] for an in-depth discussion of locking
19391940
/// and lock modes.
1941+
#[tracing::instrument(skip_all)]
19401942
pub fn acquire_package_cache_lock(&self, mode: CacheLockMode) -> CargoResult<CacheLock<'_>> {
19411943
self.package_cache_lock.lock(self, mode)
19421944
}
@@ -1946,6 +1948,7 @@ impl Config {
19461948
///
19471949
/// See [`crate::util::cache_lock`] for an in-depth discussion of locking
19481950
/// and lock modes.
1951+
#[tracing::instrument(skip_all)]
19491952
pub fn try_acquire_package_cache_lock(
19501953
&self,
19511954
mode: CacheLockMode,

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use self::targets::targets;
4242
/// within the manifest. For virtual manifests, these paths can only
4343
/// come from patched or replaced dependencies. These paths are not
4444
/// canonicalized.
45+
#[tracing::instrument(skip(config))]
4546
pub fn read_manifest(
4647
path: &Path,
4748
source_id: SourceId,

0 commit comments

Comments
 (0)