Skip to content

Commit

Permalink
fix(cli): Improve chrome traces
Browse files Browse the repository at this point in the history
I tried to focus on either hot spots or high level operations that cover
a large span of time.
  • Loading branch information
epage committed Feb 5, 2024
1 parent 60fb710 commit a8b6087
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bin/cargo/cli.rs
Expand Up @@ -15,6 +15,7 @@ use crate::command_prelude::*;
use crate::util::is_rustup;
use cargo::util::style;

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

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

#[tracing::instrument(skip_all)]
fn config_configure(
config: &mut Config,
args: &ArgMatches,
Expand Down Expand Up @@ -443,6 +446,7 @@ impl Exec {
}
}

#[tracing::instrument(skip_all)]
fn exec(self, config: &mut Config, subcommand_args: &ArgMatches) -> CliResult {
match self {
Self::Builtin(exec) => exec(config, subcommand_args),
Expand Down Expand Up @@ -514,6 +518,7 @@ impl GlobalArgs {
}
}

#[tracing::instrument(skip_all)]
pub fn cli() -> Command {
let usage = if is_rustup() {
color_print::cstr!("<cyan,bold>cargo</> <cyan>[+toolchain] [OPTIONS] [COMMAND]</>\n <cyan,bold>cargo</> <cyan>[+toolchain] [OPTIONS]</> <cyan,bold>-Zscript</> <cyan><<MANIFEST_RS>> [ARGS]...</>")
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/main.rs
Expand Up @@ -303,6 +303,7 @@ fn search_directories(config: &Config) -> Vec<PathBuf> {
}

/// Initialize libgit2.
#[tracing::instrument(skip_all)]
fn init_git(config: &Config) {
// Disabling the owner validation in git can, in theory, lead to code execution
// vulnerabilities. However, libgit2 does not launch executables, which is the foundation of
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/core/compiler/context/mod.rs
Expand Up @@ -324,6 +324,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
.map(|output| output.bin_dst().clone()))
}

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

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

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

/// Check if any output file name collision happens.
/// See <https://github.com/rust-lang/cargo/issues/6313> for more.
#[tracing::instrument(skip_all)]
fn check_collisions(&self) -> CargoResult<()> {
let mut output_collisions = HashMap::new();
let describe_collision = |unit: &Unit, other_unit: &Unit, path: &PathBuf| -> String {
Expand Down Expand Up @@ -633,6 +636,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
/// If the current crate has reverse-dependencies, such a Check unit should exist, and so
/// we use that crate's metadata. If not, we use the crate's Doc unit so at least examples
/// scraped from the current crate can be used when documenting the current crate.
#[tracing::instrument(skip_all)]
pub fn compute_metadata_for_doc_units(&mut self) {
for unit in self.bcx.unit_graph.keys() {
if !unit.mode.is_doc() && !unit.mode.is_doc_scrape() {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/job_queue/mod.rs
Expand Up @@ -462,6 +462,7 @@ impl<'cfg> JobQueue<'cfg> {
/// This function will spawn off `config.jobs()` workers to build all of the
/// necessary dependencies, in order. Freshness is propagated as far as
/// possible along each dependency chain.
#[tracing::instrument(skip_all)]
pub fn execute(mut self, cx: &mut Context<'_, '_>, plan: &mut BuildPlan) -> CargoResult<()> {
let _p = profile::start("executing the job graph");
self.queue.queue_finished();
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/mod.rs
Expand Up @@ -158,6 +158,7 @@ impl Executor for DefaultExecutor {
/// Note that **no actual work is executed as part of this**, that's all done
/// next as part of [`JobQueue::execute`] function which will run everything
/// in order with proper parallelism.
#[tracing::instrument(skip(cx, jobs, plan, exec))]
fn compile<'cfg>(
cx: &mut Context<'_, 'cfg>,
jobs: &mut JobQueue<'cfg>,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/unit_dependencies.rs
Expand Up @@ -81,6 +81,7 @@ impl IsArtifact {
/// Then entry point for building a dependency graph of compilation units.
///
/// You can find some information for arguments from doc of [`State`].
#[tracing::instrument(skip_all)]
pub fn build_unit_dependencies<'a, 'cfg>(
ws: &'a Workspace<'cfg>,
package_set: &'a PackageSet<'cfg>,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/global_cache_tracker.rs
Expand Up @@ -1567,6 +1567,7 @@ impl DeferredGlobalLastUse {
/// Saves all of the deferred information to the database.
///
/// This will also clear the state of `self`.
#[tracing::instrument(skip_all)]
pub fn save(&mut self, tracker: &mut GlobalCacheTracker) -> CargoResult<()> {
let _p = crate::util::profile::start("saving last-use data");
trace!(target: "gc", "saving last-use data");
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/package.rs
Expand Up @@ -497,6 +497,7 @@ impl<'cfg> PackageSet<'cfg> {
}

/// Downloads any packages accessible from the give root ids.
#[tracing::instrument(skip_all)]
pub fn download_accessible(
&self,
resolve: &Resolve,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/resolver/features.rs
Expand Up @@ -444,6 +444,7 @@ pub struct FeatureResolver<'a, 'cfg> {
impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
/// Runs the resolution algorithm and returns a new [`ResolvedFeatures`]
/// with the result.
#[tracing::instrument(skip_all)]
pub fn resolve(
ws: &Workspace<'cfg>,
target_data: &'a mut RustcTargetData<'cfg>,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/resolver/mod.rs
Expand Up @@ -120,6 +120,7 @@ mod version_prefs;
///
/// * `config` - a location to print warnings and such, or `None` if no warnings
/// should be printed
#[tracing::instrument(skip_all)]
pub fn resolve(
summaries: &[(Summary, ResolveOpts)],
replacements: &[(PackageIdSpec, Dependency)],
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/cargo_compile/mod.rs
Expand Up @@ -142,6 +142,7 @@ pub fn compile_with_exec<'a>(
}

/// Like [`compile_with_exec`] but without warnings from manifest parsing.
#[tracing::instrument(skip_all)]
pub fn compile_ws<'a>(
ws: &Workspace<'a>,
options: &CompileOptions,
Expand Down Expand Up @@ -197,6 +198,7 @@ pub fn print<'a>(
///
/// For how it works and what data it collects,
/// please see the [module-level documentation](self).
#[tracing::instrument(skip_all)]
pub fn create_bcx<'a, 'cfg>(
ws: &'a Workspace<'cfg>,
options: &'a CompileOptions,
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/lockfile.rs
Expand Up @@ -6,6 +6,7 @@ use crate::util::Filesystem;

use anyhow::Context as _;

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

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

Expand Down
3 changes: 3 additions & 0 deletions src/cargo/ops/resolve.rs
Expand Up @@ -239,6 +239,7 @@ pub fn resolve_ws_with_opts<'cfg>(
})
}

#[tracing::instrument(skip_all)]
fn resolve_with_registry<'cfg>(
ws: &Workspace<'cfg>,
registry: &mut PackageRegistry<'cfg>,
Expand Down Expand Up @@ -278,6 +279,7 @@ fn resolve_with_registry<'cfg>(
///
/// If `register_patches` is true, then entries from the `[patch]` table in
/// the manifest will be added to the given `PackageRegistry`.
#[tracing::instrument(skip_all)]
pub fn resolve_with_previous<'cfg>(
registry: &mut PackageRegistry<'cfg>,
ws: &Workspace<'cfg>,
Expand Down Expand Up @@ -536,6 +538,7 @@ pub fn resolve_with_previous<'cfg>(

/// Read the `paths` configuration variable to discover all path overrides that
/// have been configured.
#[tracing::instrument(skip_all)]
pub fn add_overrides<'a>(
registry: &mut PackageRegistry<'a>,
ws: &Workspace<'a>,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/command_prelude.rs
Expand Up @@ -500,6 +500,7 @@ pub trait ArgMatchesExt {
root_manifest(self._value_of("manifest-path").map(Path::new), config)
}

#[tracing::instrument(skip_all)]
fn workspace<'a>(&self, config: &'a Config) -> CargoResult<Workspace<'a>> {
let root = self.root_manifest(config)?;
let mut ws = Workspace::new(&root, config)?;
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/util/config/mod.rs
Expand Up @@ -1917,6 +1917,7 @@ impl Config {
/// Locks are usually acquired via [`Config::acquire_package_cache_lock`]
/// or [`Config::try_acquire_package_cache_lock`].
#[track_caller]
#[tracing::instrument(skip_all)]
pub fn assert_package_cache_locked<'a>(
&self,
mode: CacheLockMode,
Expand All @@ -1937,6 +1938,7 @@ impl Config {
///
/// See [`crate::util::cache_lock`] for an in-depth discussion of locking
/// and lock modes.
#[tracing::instrument(skip_all)]
pub fn acquire_package_cache_lock(&self, mode: CacheLockMode) -> CargoResult<CacheLock<'_>> {
self.package_cache_lock.lock(self, mode)
}
Expand All @@ -1946,6 +1948,7 @@ impl Config {
///
/// See [`crate::util::cache_lock`] for an in-depth discussion of locking
/// and lock modes.
#[tracing::instrument(skip_all)]
pub fn try_acquire_package_cache_lock(
&self,
mode: CacheLockMode,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/toml/mod.rs
Expand Up @@ -42,6 +42,7 @@ use self::targets::targets;
/// within the manifest. For virtual manifests, these paths can only
/// come from patched or replaced dependencies. These paths are not
/// canonicalized.
#[tracing::instrument(skip(config))]
pub fn read_manifest(
path: &Path,
source_id: SourceId,
Expand Down

0 comments on commit a8b6087

Please sign in to comment.