Skip to content

Commit ead7904

Browse files
committed
Add gc tracing target.
1 parent 89b870e commit ead7904

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/cargo/core/gc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ pub fn auto_gc(config: &Config) {
5555
// As a conservative choice, auto-gc is disabled when offline. If the
5656
// user is indefinitely offline, we don't want to delete things they
5757
// may later depend on.
58-
tracing::trace!("running offline, auto gc disabled");
58+
tracing::trace!(target: "gc", "running offline, auto gc disabled");
5959
return;
6060
}
6161

6262
if let Err(e) = auto_gc_inner(config) {
6363
if global_cache_tracker::is_silent_error(&e) && !config.extra_verbose() {
64-
tracing::warn!("failed to auto-clean cache data: {e:?}");
64+
tracing::warn!(target: "gc", "failed to auto-clean cache data: {e:?}");
6565
} else {
6666
crate::display_warning_with_error(
6767
"failed to auto-clean cache data",
@@ -76,7 +76,7 @@ fn auto_gc_inner(config: &Config) -> CargoResult<()> {
7676
let _lock = match config.try_acquire_package_cache_lock(CacheLockMode::MutateExclusive)? {
7777
Some(lock) => lock,
7878
None => {
79-
tracing::debug!("unable to acquire mutate lock, auto gc disabled");
79+
tracing::debug!(target: "gc", "unable to acquire mutate lock, auto gc disabled");
8080
return Ok(());
8181
}
8282
};
@@ -341,7 +341,7 @@ impl<'a, 'config> Gc<'a, 'config> {
341341
.unwrap_or_default();
342342
let Some(freq) = parse_frequency(auto_config.frequency.as_deref().unwrap_or("1 day"))?
343343
else {
344-
tracing::trace!("auto gc disabled");
344+
tracing::trace!(target: "gc", "auto gc disabled");
345345
return Ok(());
346346
};
347347
if !self.global_cache_tracker.should_run_auto_gc(freq)? {

src/cargo/core/global_cache_tracker.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,15 @@ impl GlobalCacheTracker {
512512
/// Returns whether or not an auto GC should be performed, compared to the
513513
/// last time it was recorded in the database.
514514
pub fn should_run_auto_gc(&mut self, frequency: Duration) -> CargoResult<bool> {
515-
trace!("should_run_auto_gc");
515+
trace!(target: "gc", "should_run_auto_gc");
516516
if self.auto_gc_checked_this_session {
517517
return Ok(false);
518518
}
519519
let last_auto_gc: Timestamp =
520520
self.conn
521521
.query_row("SELECT last_auto_gc FROM global_data", [], |row| row.get(0))?;
522522
let should_run = last_auto_gc + frequency.as_secs() < now();
523-
trace!(
523+
trace!(target: "gc",
524524
"last auto gc was {}, {}",
525525
last_auto_gc,
526526
if should_run { "running" } else { "skipping" }
@@ -559,7 +559,7 @@ impl GlobalCacheTracker {
559559
src: config.registry_source_path().into_path_unlocked(),
560560
};
561561
let now = now();
562-
trace!("cleaning {gc_opts:?}");
562+
trace!(target: "gc", "cleaning {gc_opts:?}");
563563
let tx = self.conn.transaction()?;
564564
let mut delete_paths = Vec::new();
565565
// This can be an expensive operation, so only perform it if necessary.
@@ -701,7 +701,7 @@ impl GlobalCacheTracker {
701701
delete_paths: &mut Vec<PathBuf>,
702702
) -> CargoResult<()> {
703703
let _p = crate::util::profile::start("global cache db sync");
704-
debug!("starting db sync");
704+
debug!(target: "gc", "starting db sync");
705705
// For registry_index and git_db, add anything that is missing in the db.
706706
Self::update_parent_for_missing_from_db(conn, REGISTRY_INDEX_TABLE, &base.index)?;
707707
Self::update_parent_for_missing_from_db(conn, GIT_DB_TABLE, &base.git_db)?;
@@ -797,7 +797,7 @@ impl GlobalCacheTracker {
797797
let _p = crate::util::profile::start(format!(
798798
"update parent db for missing from db {parent_table_name}"
799799
));
800-
trace!("checking for untracked parent to add to {parent_table_name}");
800+
trace!(target: "gc", "checking for untracked parent to add to {parent_table_name}");
801801
let names = Self::names_from(base_path)?;
802802

803803
let mut stmt = conn.prepare_cached(&format!(
@@ -824,7 +824,7 @@ impl GlobalCacheTracker {
824824
base_path: &Path,
825825
) -> CargoResult<()> {
826826
let _p = crate::util::profile::start(format!("update db for removed {table_name}"));
827-
trace!("checking for db entries to remove from {table_name}");
827+
trace!(target: "gc", "checking for db entries to remove from {table_name}");
828828
let mut select_stmt = conn.prepare_cached(&format!(
829829
"SELECT {table_name}.rowid, {parent_table_name}.name, {table_name}.name
830830
FROM {parent_table_name}, {table_name}
@@ -855,7 +855,7 @@ impl GlobalCacheTracker {
855855
let _p = crate::util::profile::start(format!(
856856
"update db parent for removed from disk {parent_table_name}"
857857
));
858-
trace!("checking for db entries to remove from {parent_table_name}");
858+
trace!(target: "gc", "checking for db entries to remove from {parent_table_name}");
859859
let mut select_stmt =
860860
conn.prepare_cached(&format!("SELECT rowid, name FROM {parent_table_name}"))?;
861861
let mut delete_stmt =
@@ -870,7 +870,7 @@ impl GlobalCacheTracker {
870870
for child_base in child_base_paths {
871871
let child_path = child_base.join(&id_name);
872872
if child_path.exists() {
873-
debug!("removing orphaned path {child_path:?}");
873+
debug!(target: "gc", "removing orphaned path {child_path:?}");
874874
delete_paths.push(child_path);
875875
}
876876
}
@@ -884,7 +884,7 @@ impl GlobalCacheTracker {
884884
/// cargo).
885885
fn populate_untracked_crate(conn: &Connection, base_path: &Path) -> CargoResult<()> {
886886
let _p = crate::util::profile::start("populate untracked crate");
887-
trace!("populating untracked crate files");
887+
trace!(target: "gc", "populating untracked crate files");
888888
let mut insert_stmt = conn.prepare_cached(
889889
"INSERT INTO registry_crate (registry_id, name, size, timestamp)
890890
VALUES (?1, ?2, ?3, ?4)
@@ -923,7 +923,7 @@ impl GlobalCacheTracker {
923923
populate_size: bool,
924924
) -> CargoResult<()> {
925925
let _p = crate::util::profile::start(format!("populate untracked {table_name}"));
926-
trace!("populating untracked files for {table_name}");
926+
trace!(target: "gc", "populating untracked files for {table_name}");
927927
// Gather names (and make sure they are in the database).
928928
let id_names = Self::names_from(&base_path)?;
929929

@@ -987,7 +987,7 @@ impl GlobalCacheTracker {
987987
base_path: &Path,
988988
) -> CargoResult<()> {
989989
let _p = crate::util::profile::start(format!("update NULL sizes {table_name}"));
990-
trace!("updating NULL size information in {table_name}");
990+
trace!(target: "gc", "updating NULL size information in {table_name}");
991991
let mut null_stmt = conn.prepare_cached(&format!(
992992
"SELECT {table_name}.rowid, {table_name}.name, {parent_table_name}.name
993993
FROM {table_name}, {parent_table_name}
@@ -1024,7 +1024,7 @@ impl GlobalCacheTracker {
10241024
base_path: &Path,
10251025
delete_paths: &mut Vec<PathBuf>,
10261026
) -> CargoResult<()> {
1027-
debug!("cleaning {table_name} since {max_age:?}");
1027+
debug!(target: "gc", "cleaning {table_name} since {max_age:?}");
10281028
let mut stmt = conn.prepare_cached(&format!(
10291029
"DELETE FROM {table_name} WHERE timestamp < ?1
10301030
RETURNING registry_id, name"
@@ -1054,7 +1054,7 @@ impl GlobalCacheTracker {
10541054
base_path: &Path,
10551055
delete_paths: &mut Vec<PathBuf>,
10561056
) -> CargoResult<()> {
1057-
debug!("cleaning {table_name} till under {max_size:?}");
1057+
debug!(target: "gc", "cleaning {table_name} till under {max_size:?}");
10581058
let total_size: u64 = conn.query_row(
10591059
&format!("SELECT coalesce(SUM(size), 0) FROM {table_name}"),
10601060
[],
@@ -1111,7 +1111,7 @@ impl GlobalCacheTracker {
11111111
base: &BasePaths,
11121112
delete_paths: &mut Vec<PathBuf>,
11131113
) -> CargoResult<()> {
1114-
debug!("cleaning download till under {max_size:?}");
1114+
debug!(target: "gc", "cleaning download till under {max_size:?}");
11151115

11161116
// This SQL statement selects from both registry_src and
11171117
// registry_crate so that sorting of timestamps incorporates both of
@@ -1149,7 +1149,7 @@ impl GlobalCacheTracker {
11491149
})?
11501150
.collect::<Result<Vec<(i64, i64, String, String, u64)>, _>>()?;
11511151
let mut total_size: u64 = rows.iter().map(|r| r.4).sum();
1152-
debug!("total download cache size appears to be {total_size}");
1152+
debug!(target: "gc", "total download cache size appears to be {total_size}");
11531153
for (table, rowid, name, index_name, size) in rows {
11541154
if total_size <= max_size {
11551155
break;
@@ -1177,7 +1177,7 @@ impl GlobalCacheTracker {
11771177
base: &BasePaths,
11781178
delete_paths: &mut Vec<PathBuf>,
11791179
) -> CargoResult<()> {
1180-
debug!("cleaning git till under {max_size:?}");
1180+
debug!(target: "gc", "cleaning git till under {max_size:?}");
11811181

11821182
// Collect all the sizes from git_db and git_checkouts, and then sort them by timestamp.
11831183
let mut stmt = conn.prepare_cached("SELECT rowid, name, timestamp FROM git_db")?;
@@ -1224,7 +1224,7 @@ impl GlobalCacheTracker {
12241224
let mut delete_co_stmt =
12251225
conn.prepare_cached("DELETE FROM git_checkout WHERE rowid = ?1")?;
12261226
let mut total_size: u64 = git_info.iter().map(|r| r.4).sum();
1227-
debug!("total git cache size appears to be {total_size}");
1227+
debug!(target: "gc", "total git cache size appears to be {total_size}");
12281228
while let Some((_timestamp, rowid, db_name, name, size)) = git_info.pop() {
12291229
if total_size <= max_size {
12301230
break;
@@ -1262,7 +1262,7 @@ impl GlobalCacheTracker {
12621262
base: &BasePaths,
12631263
delete_paths: &mut Vec<PathBuf>,
12641264
) -> CargoResult<()> {
1265-
debug!("cleaning index since {max_age:?}");
1265+
debug!(target: "gc", "cleaning index since {max_age:?}");
12661266
let mut stmt = conn.prepare_cached(
12671267
"DELETE FROM registry_index WHERE timestamp < ?1
12681268
RETURNING name",
@@ -1287,7 +1287,7 @@ impl GlobalCacheTracker {
12871287
base_path: &Path,
12881288
delete_paths: &mut Vec<PathBuf>,
12891289
) -> CargoResult<()> {
1290-
debug!("cleaning git co since {max_age:?}");
1290+
debug!(target: "gc", "cleaning git co since {max_age:?}");
12911291
let mut stmt = conn.prepare_cached(
12921292
"DELETE FROM git_checkout WHERE timestamp < ?1
12931293
RETURNING git_id, name",
@@ -1316,7 +1316,7 @@ impl GlobalCacheTracker {
13161316
base: &BasePaths,
13171317
delete_paths: &mut Vec<PathBuf>,
13181318
) -> CargoResult<()> {
1319-
debug!("cleaning git db since {max_age:?}");
1319+
debug!(target: "gc", "cleaning git db since {max_age:?}");
13201320
let mut stmt = conn.prepare_cached(
13211321
"DELETE FROM git_db WHERE timestamp < ?1
13221322
RETURNING name",
@@ -1361,7 +1361,7 @@ macro_rules! insert_or_update_parent {
13611361
" SET timestamp = ?1 WHERE id = ?2"
13621362
))?;
13631363
for (parent, new_timestamp) in std::mem::take(&mut $self.$timestamps_field) {
1364-
trace!(
1364+
trace!(target: "gc",
13651365
concat!("insert ", $table_name, " {:?} {}"),
13661366
parent,
13671367
new_timestamp
@@ -1553,7 +1553,7 @@ impl DeferredGlobalLastUse {
15531553
/// This will also clear the state of `self`.
15541554
pub fn save(&mut self, tracker: &mut GlobalCacheTracker) -> CargoResult<()> {
15551555
let _p = crate::util::profile::start("saving last-use data");
1556-
trace!("saving last-use data");
1556+
trace!(target: "gc", "saving last-use data");
15571557
if self.is_empty() {
15581558
return Ok(());
15591559
}
@@ -1565,7 +1565,7 @@ impl DeferredGlobalLastUse {
15651565
self.insert_registry_src_from_cache(&tx)?;
15661566
self.insert_git_checkout_from_cache(&tx)?;
15671567
tx.commit()?;
1568-
trace!("last-use save complete");
1568+
trace!(target: "gc", "last-use save complete");
15691569
Ok(())
15701570
}
15711571

@@ -1632,7 +1632,7 @@ impl DeferredGlobalLastUse {
16321632
fn insert_registry_crate_from_cache(&mut self, conn: &Connection) -> CargoResult<()> {
16331633
let registry_crate_timestamps = std::mem::take(&mut self.registry_crate_timestamps);
16341634
for (registry_crate, timestamp) in registry_crate_timestamps {
1635-
trace!("insert registry crate {registry_crate:?} {timestamp}");
1635+
trace!(target: "gc", "insert registry crate {registry_crate:?} {timestamp}");
16361636
let registry_id = self.registry_id(conn, registry_crate.encoded_registry_name)?;
16371637
let mut stmt = conn.prepare_cached(
16381638
"INSERT INTO registry_crate (registry_id, name, size, timestamp)
@@ -1657,7 +1657,7 @@ impl DeferredGlobalLastUse {
16571657
fn insert_registry_src_from_cache(&mut self, conn: &Connection) -> CargoResult<()> {
16581658
let registry_src_timestamps = std::mem::take(&mut self.registry_src_timestamps);
16591659
for (registry_src, timestamp) in registry_src_timestamps {
1660-
trace!("insert registry src {registry_src:?} {timestamp}");
1660+
trace!(target: "gc", "insert registry src {registry_src:?} {timestamp}");
16611661
let registry_id = self.registry_id(conn, registry_src.encoded_registry_name)?;
16621662
let mut stmt = conn.prepare_cached(
16631663
"INSERT INTO registry_src (registry_id, name, size, timestamp)

tests/testsuite/global_cache_tracker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ fn package_cache_lock_during_build() {
12251225
.cargo("check -Zgc")
12261226
.masquerade_as_nightly_cargo(&["gc"])
12271227
.env("CARGO_GC_AUTO_FREQUENCY", "always")
1228-
.env("CARGO_LOG", "cargo::core::gc=debug")
1228+
.env("CARGO_LOG", "gc=debug")
12291229
.with_stderr_contains("[UPDATING] `dummy-registry` index")
12301230
.with_stderr_contains("[CHECKING] bar v1.0.0")
12311231
.with_stderr_contains("[CHECKING] foo2 v0.1.0 [..]")

0 commit comments

Comments
 (0)