Skip to content

Commit

Permalink
Log versions tried from batch prefetch
Browse files Browse the repository at this point in the history
This is required for evaluating #3087

Closes #2270 - This is less invasive compared to the other PR, we can revisit number of network/build request tracking later
  • Loading branch information
konstin committed Apr 17, 2024
1 parent 64b545d commit 1825004
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions crates/uv-resolver/src/resolver/batch_prefetch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cmp::min;

use itertools::Itertools;
use pubgrub::range::Range;
use rustc_hash::FxHashMap;
use tokio::sync::mpsc::Sender;
Expand Down Expand Up @@ -173,4 +174,23 @@ impl BatchPrefetcher {
|| (num_tried >= 20 && num_tried - previous_prefetch >= 20);
(num_tried, do_prefetch)
}

/// Log stats about how many versions we tried.
///
/// Note that they may be inflated when we count the same version repeatedly during
/// backtracking.
pub(crate) fn log_tried_versions(&self) {
let total_versions: usize = self.tried_versions.values().sum();
let mut tried_versions: Vec<_> = self.tried_versions.iter().collect();
tried_versions.sort_by(|(p1, c1), (p2, c2)| {
c1.cmp(c2)
.reverse()
.then(p1.to_string().cmp(&p2.to_string()))
});
let counts = tried_versions
.iter()
.map(|(package, count)| format!("{package} {count}"))
.join(", ");
debug!("Tried {total_versions} versions: {counts}");
}
}
8 changes: 7 additions & 1 deletion crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use pubgrub::range::Range;
use pubgrub::solver::{Incompatibility, State};
use rustc_hash::{FxHashMap, FxHashSet};
use tokio_stream::wrappers::ReceiverStream;
use tracing::{debug, info_span, instrument, trace, warn, Instrument};
use tracing::{debug, enabled, info_span, instrument, trace, warn, Instrument, Level};

use distribution_types::{
BuiltDist, Dist, DistributionMetadata, IncompatibleDist, IncompatibleSource, IncompatibleWheel,
Expand Down Expand Up @@ -323,6 +323,9 @@ impl<
priorities.get(package).unwrap_or_default()
})
else {
if enabled!(Level::DEBUG) {
prefetcher.log_tried_versions();
}
let selection = state.partial_solution.extract_solution();
return ResolutionGraph::from_state(
&selection,
Expand Down Expand Up @@ -482,6 +485,9 @@ impl<
.iter()
.any(|(dependency, _)| dependency == package) =>
{
if enabled!(Level::DEBUG) {
prefetcher.log_tried_versions();
}
return Err(PubGrubError::SelfDependency {
package: package.clone(),
version: version.clone(),
Expand Down

0 comments on commit 1825004

Please sign in to comment.