Add benchmarks for the global cache tracker.

This commit is contained in:
Eric Huss 2023-09-06 21:36:42 -07:00
parent da3ca05677
commit 8f327a7fd4
7 changed files with 851 additions and 3 deletions

2
Cargo.lock generated
View File

@ -129,8 +129,10 @@ name = "benchsuite"
version = "0.0.0"
dependencies = [
"cargo",
"cargo-util",
"criterion",
"flate2",
"rand",
"tar",
"url",
]

View File

@ -9,7 +9,23 @@ cd benches/benchsuite
cargo bench
```
The tests involve downloading the index and benchmarking against some
However, running all benchmarks would take many minutes, so in most cases it
is recommended to just run the benchmarks relevant to whatever section of code
you are working on.
## Benchmarks
There are several different kinds of benchmarks in the `benchsuite/benches` directory:
* `global_cache_tracker` — Benchmarks saving data to the global cache tracker
database using samples of real-world data.
* `resolve` — Benchmarks the resolver against simulations of real-world workspaces.
* `workspace_initialization` — Benchmarks initialization of a workspace
against simulations of real-world workspaces.
### Resolve benchmarks
The resolve benchmarks involve downloading the index and benchmarking against some
real-world and artificial workspaces located in the [`workspaces`](workspaces)
directory.
@ -21,7 +37,7 @@ faster. You can (and probably should) specify individual benchmarks to run to
narrow it down to a more reasonable set, for example:
```sh
cargo bench -- resolve_ws/rust
cargo bench -p benchsuite --bench resolve -- resolve_ws/rust
```
This will only download what's necessary for the rust-lang/rust workspace
@ -29,7 +45,24 @@ This will only download what's necessary for the rust-lang/rust workspace
about a minute). To get a list of all the benchmarks, run:
```sh
cargo bench -- --list
cargo bench -p benchsuite --bench resolve -- --list
```
### Global cache tracker
The `global_cache_tracker` benchmark tests saving data to the global cache
tracker database using samples of real-world data. This benchmark should run
relatively quickly.
The real-world data is based on a capture of my personal development
environment which has accumulated a large cache. So it is somewhat arbitrary,
but hopefully representative of a challenging environment. Capturing of the
data is done with the `capture-last-use` binary, which you can run if you need
to rebuild the database. Just try to run on a system with a relatively full
cache in your cargo home directory.
```sh
cargo bench -p benchsuite --bench global_cache_tracker
```
## Viewing reports

View File

@ -11,8 +11,10 @@ publish = false
[dependencies]
cargo.workspace = true
cargo-util.workspace = true
criterion.workspace = true
flate2.workspace = true
rand.workspace = true
tar.workspace = true
url.workspace = true
@ -26,3 +28,7 @@ harness = false
[[bench]]
name = "workspace_initialization"
harness = false
[[bench]]
name = "global_cache_tracker"
harness = false

View File

@ -0,0 +1,159 @@
//! Benchmarks for the global cache tracker.
use cargo::core::global_cache_tracker::{self, DeferredGlobalLastUse, GlobalCacheTracker};
use cargo::util::cache_lock::CacheLockMode;
use cargo::util::interning::InternedString;
use cargo::util::Config;
use criterion::{criterion_group, criterion_main, Criterion};
use std::fs;
use std::path::{Path, PathBuf};
// Samples of real-world data.
const GLOBAL_CACHE_SAMPLE: &str = "global-cache-tracker/global-cache-sample";
const GLOBAL_CACHE_RANDOM: &str = "global-cache-tracker/random-sample";
/// A scratch directory where the benchmark can place some files.
fn root() -> PathBuf {
let mut p = PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
p.push("bench_global_cache_tracker");
p
}
fn cargo_home() -> PathBuf {
let mut p = root();
p.push("chome");
p
}
fn initialize_config() -> Config {
// Set up config.
let shell = cargo::core::Shell::new();
let homedir = cargo_home();
if !homedir.exists() {
fs::create_dir_all(&homedir).unwrap();
}
let cwd = homedir.clone();
let mut config = Config::new(shell, cwd, homedir);
config.nightly_features_allowed = true;
config.set_search_stop_path(root());
config
.configure(
0,
false,
None,
false,
false,
false,
&None,
&["gc".to_string()],
&[],
)
.unwrap();
// Set up database sample.
let db_path = GlobalCacheTracker::db_path(&config).into_path_unlocked();
if db_path.exists() {
fs::remove_file(&db_path).unwrap();
}
let sample = Path::new(env!("CARGO_MANIFEST_DIR")).join(GLOBAL_CACHE_SAMPLE);
fs::copy(sample, &db_path).unwrap();
config
}
/// Benchmarks how long it takes to initialize `GlobalCacheTracker` with an already
/// existing full database.
fn global_tracker_init(c: &mut Criterion) {
let config = initialize_config();
let _lock = config
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
.unwrap();
c.bench_function("global_tracker_init", |b| {
b.iter(|| {
GlobalCacheTracker::new(&config).unwrap();
})
});
}
/// Benchmarks how long it takes to save a `GlobalCacheTracker` when there are zero
/// updates.
fn global_tracker_empty_save(c: &mut Criterion) {
let config = initialize_config();
let _lock = config
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
.unwrap();
let mut deferred = DeferredGlobalLastUse::new();
let mut tracker = GlobalCacheTracker::new(&config).unwrap();
c.bench_function("global_tracker_empty_save", |b| {
b.iter(|| {
deferred.save(&mut tracker).unwrap();
})
});
}
fn load_random_sample() -> Vec<(InternedString, InternedString, u64)> {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(GLOBAL_CACHE_RANDOM);
fs::read_to_string(path)
.unwrap()
.lines()
.map(|s| {
let mut s = s.split(',');
(
s.next().unwrap().into(),
s.next().unwrap().into(),
s.next().unwrap().parse().unwrap(),
)
})
.collect()
}
/// Tests performance of updating the last-use timestamps in an already
/// populated database.
///
/// This runs for different sizes of number of crates to update (selecting
/// from the random sample stored on disk).
fn global_tracker_update(c: &mut Criterion) {
let config = initialize_config();
let _lock = config
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
.unwrap();
let sample = Path::new(env!("CARGO_MANIFEST_DIR")).join(GLOBAL_CACHE_SAMPLE);
let db_path = GlobalCacheTracker::db_path(&config).into_path_unlocked();
let random_sample = load_random_sample();
let mut group = c.benchmark_group("global_tracker_update");
for size in [1, 10, 100, 500] {
if db_path.exists() {
fs::remove_file(&db_path).unwrap();
}
fs::copy(&sample, &db_path).unwrap();
let mut deferred = DeferredGlobalLastUse::new();
let mut tracker = GlobalCacheTracker::new(&config).unwrap();
group.bench_with_input(size.to_string(), &size, |b, &size| {
b.iter(|| {
for (encoded_registry_name, name, size) in &random_sample[..size] {
deferred.mark_registry_crate_used(global_cache_tracker::RegistryCrate {
encoded_registry_name: *encoded_registry_name,
crate_filename: format!("{}.crate", name).into(),
size: *size,
});
deferred.mark_registry_src_used(global_cache_tracker::RegistrySrc {
encoded_registry_name: *encoded_registry_name,
package_dir: *name,
size: Some(*size),
});
}
deferred.save(&mut tracker).unwrap();
})
});
}
}
criterion_group!(
benches,
global_tracker_init,
global_tracker_empty_save,
global_tracker_update
);
criterion_main!(benches);

View File

@ -0,0 +1,500 @@
github.com-1ecc6299db9ec823,tungstenite-0.18.0,218740
github.com-1ecc6299db9ec823,integer-encoding-1.1.5,30672
github.com-1ecc6299db9ec823,tungstenite-0.14.0,315676
github.com-1ecc6299db9ec823,oxcable-0.5.1,163196
github.com-1ecc6299db9ec823,swc_ecma_transforms_typescript-0.32.0,245522
github.com-1ecc6299db9ec823,hyper-0.12.35,601153
github.com-1ecc6299db9ec823,resiter-0.4.0,59880
github.com-1ecc6299db9ec823,net2-0.2.37,115813
github.com-1ecc6299db9ec823,str_inflector-0.12.0,182460
github.com-1ecc6299db9ec823,derive_builder_macro-0.10.2,16441
github.com-1ecc6299db9ec823,smol_str-0.1.23,42436
github.com-1ecc6299db9ec823,wasm-bindgen-multi-value-xform-0.2.83,35347
github.com-1ecc6299db9ec823,time-macros-0.1.0,1620
github.com-1ecc6299db9ec823,unicode-bidi-0.3.7,140153
github.com-1ecc6299db9ec823,socket2-0.4.0,167295
github.com-1ecc6299db9ec823,ppv-lite86-0.2.10,125234
github.com-1ecc6299db9ec823,tracing-wasm-0.2.1,31449
github.com-1ecc6299db9ec823,eframe-0.19.0,158130
github.com-1ecc6299db9ec823,block-modes-0.7.0,42530
github.com-1ecc6299db9ec823,rangemap-0.1.11,144157
github.com-1ecc6299db9ec823,metal-0.23.1,1038699
github.com-1ecc6299db9ec823,os_str_bytes-6.0.1,86390
github.com-1ecc6299db9ec823,plotters-backend-0.3.4,53018
github.com-1ecc6299db9ec823,spidev-0.4.0,45301
github.com-1ecc6299db9ec823,axum-macros-0.2.3,102058
github.com-1ecc6299db9ec823,embedded-time-0.12.1,246450
github.com-1ecc6299db9ec823,envmnt-0.10.4,2328079
github.com-1ecc6299db9ec823,camino-1.1.1,133976
github.com-1ecc6299db9ec823,siphasher-0.3.5,46666
github.com-1ecc6299db9ec823,lexical-write-integer-0.8.5,388374
github.com-1ecc6299db9ec823,reqwest-0.11.14,686608
github.com-1ecc6299db9ec823,enum-map-2.4.1,51184
github.com-1ecc6299db9ec823,sentry-panic-0.29.0,18211
github.com-1ecc6299db9ec823,msf-srtp-0.2.0,73164
github.com-1ecc6299db9ec823,near-sandbox-utils-0.4.1,7543
github.com-1ecc6299db9ec823,ablescript-0.5.2,129318
github.com-1ecc6299db9ec823,apecs-derive-0.2.3,10620
github.com-1ecc6299db9ec823,libc-0.2.133,3417382
github.com-1ecc6299db9ec823,tracing-0.1.35,380627
github.com-1ecc6299db9ec823,serde-wasm-bindgen-0.3.1,55371
github.com-1ecc6299db9ec823,compiler_builtins-0.1.71,692853
github.com-1ecc6299db9ec823,mockito-0.7.2,1179718
github.com-1ecc6299db9ec823,tonic-0.5.2,420299
github.com-1ecc6299db9ec823,tracing-core-0.1.30,240058
github.com-1ecc6299db9ec823,tower-timeout-0.3.0-alpha.2,7486
github.com-1ecc6299db9ec823,js-intern-0.3.1,7026
github.com-1ecc6299db9ec823,json-ld-context-processing-0.12.1,78101
github.com-1ecc6299db9ec823,generic-array-0.14.6,67349
github.com-1ecc6299db9ec823,synstructure-0.12.3,93523
github.com-1ecc6299db9ec823,version-compare-0.0.10,74950
github.com-1ecc6299db9ec823,dirs-1.0.5,51075
github.com-1ecc6299db9ec823,worker-kv-0.5.1,67351
github.com-1ecc6299db9ec823,vsimd-0.8.0,170805
github.com-1ecc6299db9ec823,mockall-0.9.1,187734
github.com-1ecc6299db9ec823,nan-preserving-float-0.1.0,6341
github.com-1ecc6299db9ec823,wasmer-types-2.3.0,192436
github.com-1ecc6299db9ec823,sodiumoxide-0.2.7,5131115
github.com-1ecc6299db9ec823,tracing-attributes-0.1.11,74857
github.com-1ecc6299db9ec823,treediff-4.0.2,72588
github.com-1ecc6299db9ec823,wiggle-generate-5.0.0,103044
github.com-1ecc6299db9ec823,lapin-1.6.6,497368
github.com-1ecc6299db9ec823,cranelift-entity-0.93.1,114206
github.com-1ecc6299db9ec823,pcap-parser-0.13.3,184131
github.com-1ecc6299db9ec823,rustfft-5.1.1,1638221
github.com-1ecc6299db9ec823,string_cache-0.7.5,75074
github.com-1ecc6299db9ec823,maybe-uninit-2.0.0,38492
github.com-1ecc6299db9ec823,diesel_full_text_search-2.0.0,10179
github.com-1ecc6299db9ec823,quinn-proto-0.8.4,687565
github.com-1ecc6299db9ec823,semver-0.5.1,73365
github.com-1ecc6299db9ec823,rocket_http-0.5.0-rc.2,409939
github.com-1ecc6299db9ec823,dialoguer-0.7.1,95159
github.com-1ecc6299db9ec823,fallible_collections-0.4.5,244152
github.com-1ecc6299db9ec823,parking_lot_core-0.9.0,138932
github.com-1ecc6299db9ec823,relative-path-1.6.0,103315
github.com-1ecc6299db9ec823,lua52-sys-0.1.2,584054
github.com-1ecc6299db9ec823,actix-files-0.6.0,126121
github.com-1ecc6299db9ec823,crates-io-0.35.1,29498
github.com-1ecc6299db9ec823,sentry-backtrace-0.19.1,20268
github.com-1ecc6299db9ec823,text_unit-0.1.10,26100
github.com-1ecc6299db9ec823,ascii-1.0.0,143025
github.com-1ecc6299db9ec823,crossbeam-utils-0.8.6,169542
github.com-1ecc6299db9ec823,nelf-0.1.0,28868
github.com-1ecc6299db9ec823,colorsys-0.6.5,86989
github.com-1ecc6299db9ec823,enum-iterator-1.2.0,31042
github.com-1ecc6299db9ec823,ansi-str-0.7.2,111689
github.com-1ecc6299db9ec823,anyhow-1.0.68,209123
github.com-1ecc6299db9ec823,gix-lock-5.0.1,65110
github.com-1ecc6299db9ec823,nom-supreme-0.8.0,147530
github.com-1ecc6299db9ec823,path-slash-0.1.4,28655
github.com-1ecc6299db9ec823,crates-io-0.35.0,29406
github.com-1ecc6299db9ec823,stb_truetype-0.2.8,22939
github.com-1ecc6299db9ec823,proc-macro2-1.0.50,185288
github.com-1ecc6299db9ec823,snapbox-0.4.1,169526
github.com-1ecc6299db9ec823,hyper-0.14.9,764075
github.com-1ecc6299db9ec823,ab_glyph-0.2.15,61722
github.com-1ecc6299db9ec823,uuid-0.1.18,47889
github.com-1ecc6299db9ec823,data-url-0.2.0,123480
github.com-1ecc6299db9ec823,threadpool-1.7.1,59558
github.com-1ecc6299db9ec823,thiserror-impl-1.0.29,65149
github.com-1ecc6299db9ec823,sha1-0.6.0,31102
github.com-1ecc6299db9ec823,tokio-tls-0.2.1,51467
github.com-1ecc6299db9ec823,locspan-derive-0.6.0,59360
github.com-1ecc6299db9ec823,ureq-1.5.1,249335
github.com-1ecc6299db9ec823,protoc-rust-2.24.1,13459
github.com-1ecc6299db9ec823,serde-1.0.159,509060
github.com-1ecc6299db9ec823,unescape-0.1.0,6047
github.com-1ecc6299db9ec823,data-encoding-2.2.0,113191
github.com-1ecc6299db9ec823,bytestring-1.1.0,23705
github.com-1ecc6299db9ec823,ab_glyph_rasterizer-0.1.8,34773
github.com-1ecc6299db9ec823,syn-0.12.15,912964
github.com-1ecc6299db9ec823,reqwest-0.11.9,656209
github.com-1ecc6299db9ec823,rustls-0.17.0,903717
github.com-1ecc6299db9ec823,term_size-0.3.2,36226
github.com-1ecc6299db9ec823,ordered-float-3.1.0,91357
github.com-1ecc6299db9ec823,cookie-0.2.5,44912
github.com-1ecc6299db9ec823,debugid-0.8.0,44521
github.com-1ecc6299db9ec823,conrod-0.51.1,2154016
github.com-1ecc6299db9ec823,indexmap-1.6.1,247801
github.com-1ecc6299db9ec823,target-spec-1.3.1,68315
github.com-1ecc6299db9ec823,lexical-parse-integer-0.8.6,139671
github.com-1ecc6299db9ec823,time-0.1.38,131629
github.com-1ecc6299db9ec823,glib-macros-0.14.1,102959
github.com-1ecc6299db9ec823,metrics-macros-0.6.0,37750
github.com-1ecc6299db9ec823,structopt-0.3.12,224213
github.com-1ecc6299db9ec823,criterion-0.3.2,439241
github.com-1ecc6299db9ec823,lyon_path-0.17.7,186745
github.com-1ecc6299db9ec823,miette-5.5.0,312945
github.com-1ecc6299db9ec823,tokio-codec-0.2.0-alpha.6,118193
github.com-1ecc6299db9ec823,structopt-derive-0.4.14,84883
github.com-1ecc6299db9ec823,objekt-0.1.2,24191
github.com-1ecc6299db9ec823,sqlx-macros-0.5.7,110890
github.com-1ecc6299db9ec823,systemstat-0.1.10,127295
github.com-1ecc6299db9ec823,colorful-0.2.2,99698
github.com-1ecc6299db9ec823,quick-xml-0.20.0,645935
github.com-1ecc6299db9ec823,selinux-sys-0.6.2,27060
github.com-1ecc6299db9ec823,vsmtp-mail-parser-1.4.0-rc.10,137699
github.com-1ecc6299db9ec823,sec1-0.7.2,64870
github.com-1ecc6299db9ec823,nix-0.22.1,1161830
github.com-1ecc6299db9ec823,snow-0.9.0,2658286
github.com-1ecc6299db9ec823,per_test_directory_macros-0.1.0,2962
github.com-1ecc6299db9ec823,syn-helpers-0.4.3,58801
github.com-1ecc6299db9ec823,terminal_size-0.2.2,29633
github.com-1ecc6299db9ec823,bevy_hierarchy-0.7.0,41018
github.com-1ecc6299db9ec823,dynamic_reload-0.4.0,74455
github.com-1ecc6299db9ec823,http-signature-normalization-actix-0.5.0-beta.14,126857
github.com-1ecc6299db9ec823,http-body-0.4.1,24138
github.com-1ecc6299db9ec823,gix-index-0.13.0,207795
github.com-1ecc6299db9ec823,darling_macro-0.13.1,4156
github.com-1ecc6299db9ec823,serde_json-1.0.66,543072
github.com-1ecc6299db9ec823,minreq-1.4.1,41355
github.com-1ecc6299db9ec823,sct-0.6.1,60974
github.com-1ecc6299db9ec823,openssl-0.10.50,1173941
github.com-1ecc6299db9ec823,bevy_pbr-0.6.0,201163
github.com-1ecc6299db9ec823,security-framework-2.3.1,290512
github.com-1ecc6299db9ec823,pin-project-internal-0.4.30,128419
github.com-1ecc6299db9ec823,serde_yaml-0.7.5,158524
github.com-1ecc6299db9ec823,cid-0.3.2,17269
github.com-1ecc6299db9ec823,plotters-backend-0.3.0,51995
github.com-1ecc6299db9ec823,serde_yaml-0.8.12,179579
github.com-1ecc6299db9ec823,cosmwasm-schema-derive-1.1.9,34956
github.com-1ecc6299db9ec823,docopt-0.6.86,175553
github.com-1ecc6299db9ec823,git-testament-0.2.4,27685
github.com-1ecc6299db9ec823,htmlescape-0.3.1,143378
github.com-1ecc6299db9ec823,is_proc_translated-0.1.1,16533
github.com-1ecc6299db9ec823,futures-macro-0.3.4,33147
github.com-1ecc6299db9ec823,futures-intrusive-0.4.2,520476
github.com-1ecc6299db9ec823,rustix-0.35.13,1581355
github.com-1ecc6299db9ec823,glsl-layout-0.3.2,75515
github.com-1ecc6299db9ec823,darling-0.12.0,67446
github.com-1ecc6299db9ec823,blake3-0.1.5,394136
github.com-1ecc6299db9ec823,async-stripe-0.15.0,3157635
github.com-1ecc6299db9ec823,hbs-common-sys-0.2.1,1034
github.com-1ecc6299db9ec823,base58-0.1.0,7019
github.com-1ecc6299db9ec823,time-0.2.23,342720
github.com-1ecc6299db9ec823,memoffset-0.5.6,27595
github.com-1ecc6299db9ec823,colored-1.9.3,85161
github.com-1ecc6299db9ec823,lrpar-0.13.1,153317
github.com-1ecc6299db9ec823,clap-2.34.0,975823
github.com-1ecc6299db9ec823,chalk-engine-0.55.0,203718
github.com-1ecc6299db9ec823,cosmic-space-0.3.6,800331
github.com-1ecc6299db9ec823,syn-1.0.93,1886902
github.com-1ecc6299db9ec823,futures-core-0.3.5,43430
github.com-1ecc6299db9ec823,prost-derive-0.11.6,99428
github.com-1ecc6299db9ec823,toml_edit-0.15.0,491549
github.com-1ecc6299db9ec823,pcb-llvm-0.2.0,17328
github.com-1ecc6299db9ec823,rusticata-macros-2.1.0,35537
github.com-1ecc6299db9ec823,rustyline-with-hint-fix-10.1.0,548833
github.com-1ecc6299db9ec823,sharded-slab-0.1.1,239224
github.com-1ecc6299db9ec823,literally-0.1.3,20415
github.com-1ecc6299db9ec823,riff-1.0.1,20582
github.com-1ecc6299db9ec823,futures-macro-0.3.23,38691
github.com-1ecc6299db9ec823,criterion-0.3.1,431723
github.com-1ecc6299db9ec823,atty-0.2.14,14567
github.com-1ecc6299db9ec823,vergen-3.1.0,49089
github.com-1ecc6299db9ec823,peeking_take_while-0.1.2,18604
github.com-1ecc6299db9ec823,serde_derive-1.0.156,316173
github.com-1ecc6299db9ec823,geo-0.23.1,1022596
github.com-1ecc6299db9ec823,persy-1.4.3,778219
github.com-1ecc6299db9ec823,futures-lite-1.13.0,214632
github.com-1ecc6299db9ec823,ms_dtyp-0.0.3,44387
github.com-1ecc6299db9ec823,thiserror-1.0.33,66618
github.com-1ecc6299db9ec823,marksman_escape-0.1.2,587235
github.com-1ecc6299db9ec823,serde_derive-1.0.101,289156
github.com-1ecc6299db9ec823,gix-ref-0.29.0,214105
github.com-1ecc6299db9ec823,der-0.7.5,384316
github.com-1ecc6299db9ec823,promptly-0.3.0,35216
github.com-1ecc6299db9ec823,libc-0.2.115,3166629
github.com-1ecc6299db9ec823,ppv-lite86-0.1.2,33514
github.com-1ecc6299db9ec823,gfx-hal-0.6.0,254453
github.com-1ecc6299db9ec823,as-slice-0.1.3,20306
github.com-1ecc6299db9ec823,gpu-alloc-0.3.0,78823
github.com-1ecc6299db9ec823,arc-swap-0.4.8,167950
github.com-1ecc6299db9ec823,libusb1-sys-0.5.0,1458763
github.com-1ecc6299db9ec823,sysinfo-0.26.8,609932
github.com-1ecc6299db9ec823,refinery-macros-0.8.7,6514
github.com-1ecc6299db9ec823,assert_float_eq-1.1.3,38445
github.com-1ecc6299db9ec823,tinyvec-1.1.0,363582
github.com-1ecc6299db9ec823,predicates-1.0.7,1168580
github.com-1ecc6299db9ec823,pulldown-cmark-0.9.3,595681
github.com-1ecc6299db9ec823,aws-sigv4-0.46.0,97885
github.com-1ecc6299db9ec823,fastrand-1.5.0,39175
github.com-1ecc6299db9ec823,futures-channel-0.3.17,131816
github.com-1ecc6299db9ec823,usbd_scsi-0.1.0,172205
github.com-1ecc6299db9ec823,tinyvec-1.4.0,379505
github.com-1ecc6299db9ec823,structsy-0.5.1,513822
github.com-1ecc6299db9ec823,aws-sdk-ssm-0.21.0,9755619
github.com-1ecc6299db9ec823,pin-project-lite-0.1.1,63942
github.com-1ecc6299db9ec823,tokio-rustls-0.13.0,78252
github.com-1ecc6299db9ec823,tinyvec_macros-0.1.0,2912
github.com-1ecc6299db9ec823,extended_matrix_float-1.0.0,6233
github.com-1ecc6299db9ec823,displaydoc-0.2.3,68676
github.com-1ecc6299db9ec823,typed-arena-2.0.2,43549
github.com-1ecc6299db9ec823,cranelift-0.86.1,16294
github.com-1ecc6299db9ec823,modular-bitfield-impl-0.10.0,64389
github.com-1ecc6299db9ec823,schemafy_core-0.5.2,7696
github.com-1ecc6299db9ec823,sea-orm-macros-0.8.0,86930
github.com-1ecc6299db9ec823,core-foundation-sys-0.4.6,61859
github.com-1ecc6299db9ec823,move-symbol-pool-0.3.2,14473
github.com-1ecc6299db9ec823,glutin-0.25.1,300518
github.com-1ecc6299db9ec823,postcard-cobs-0.2.0,41524
github.com-1ecc6299db9ec823,quote-0.6.11,69636
github.com-1ecc6299db9ec823,encoding_rs-0.8.32,5022316
github.com-1ecc6299db9ec823,clap-2.32.0,946148
github.com-1ecc6299db9ec823,term-0.6.1,181220
github.com-1ecc6299db9ec823,enumset-1.0.12,85911
github.com-1ecc6299db9ec823,ctest2-0.4.1,100745
github.com-1ecc6299db9ec823,serde-xml-any-0.0.3,70554
github.com-1ecc6299db9ec823,proc-macro-hack-0.5.11,39025
github.com-1ecc6299db9ec823,remove_dir_all-0.5.1,23418
github.com-1ecc6299db9ec823,weezl-0.1.5,134218
github.com-1ecc6299db9ec823,windows_x86_64_gnullvm-0.42.1,3254874
github.com-1ecc6299db9ec823,rocket-0.5.0-rc.2,1225987
github.com-1ecc6299db9ec823,pin-project-0.4.27,282004
github.com-1ecc6299db9ec823,criterion-cycles-per-byte-0.1.3,18296
github.com-1ecc6299db9ec823,coco-0.1.1,107143
github.com-1ecc6299db9ec823,solana-bloom-1.15.1,22207
github.com-1ecc6299db9ec823,qoqo_calculator-1.1.1,163666
github.com-1ecc6299db9ec823,aes-gcm-0.9.4,381036
github.com-1ecc6299db9ec823,blowfish-0.9.1,39658
github.com-1ecc6299db9ec823,pango-0.14.3,258440
github.com-1ecc6299db9ec823,clap_derive-3.0.0,129105
github.com-1ecc6299db9ec823,content_inspector-0.2.4,27568
github.com-1ecc6299db9ec823,jsona-0.2.0,104104
github.com-1ecc6299db9ec823,gix-quote-0.4.3,32314
github.com-1ecc6299db9ec823,bcs-0.1.3,93194
github.com-1ecc6299db9ec823,statrs-0.14.0,681982
github.com-1ecc6299db9ec823,cw-controllers-0.16.0,32195
github.com-1ecc6299db9ec823,hyper-0.12.36,578470
github.com-1ecc6299db9ec823,argon2-0.4.1,112707
github.com-1ecc6299db9ec823,fraction-0.12.2,482976
github.com-1ecc6299db9ec823,quickcheck-0.7.2,89884
github.com-1ecc6299db9ec823,typetag-0.1.8,135149
github.com-1ecc6299db9ec823,object-0.20.0,916661
github.com-1ecc6299db9ec823,pest_derive-2.2.1,60318
github.com-1ecc6299db9ec823,coremidi-sys-3.1.0,40849
github.com-1ecc6299db9ec823,either-1.6.0,48881
github.com-1ecc6299db9ec823,tarpc-0.29.0,244416
github.com-1ecc6299db9ec823,num-integer-0.1.42,88403
github.com-1ecc6299db9ec823,oid-registry-0.6.0,46996
github.com-1ecc6299db9ec823,historian-3.0.11,23818
github.com-1ecc6299db9ec823,ui-sys-0.1.3,1784250
github.com-1ecc6299db9ec823,cranelift-frontend-0.92.0,166902
github.com-1ecc6299db9ec823,pin-project-lite-0.1.12,77882
github.com-1ecc6299db9ec823,piston2d-gfx_graphics-0.72.0,91826
github.com-1ecc6299db9ec823,stylist-macros-0.9.2,78647
github.com-1ecc6299db9ec823,valico-3.4.0,1394467
github.com-1ecc6299db9ec823,inventory-0.3.3,40329
github.com-1ecc6299db9ec823,wrapping_arithmetic-0.1.0,8774
github.com-1ecc6299db9ec823,serde-1.0.138,502921
github.com-1ecc6299db9ec823,ra_common-0.1.3,16920
github.com-1ecc6299db9ec823,markup5ever-0.10.0,213742
github.com-1ecc6299db9ec823,libp2p-core-0.20.1,460422
github.com-1ecc6299db9ec823,inout-0.1.2,40474
github.com-1ecc6299db9ec823,flatbuffers-23.1.21,103944
github.com-1ecc6299db9ec823,gdk-pixbuf-sys-0.10.0,42914
github.com-1ecc6299db9ec823,miniz_oxide-0.5.1,223551
github.com-1ecc6299db9ec823,merge-0.1.0,70214
github.com-1ecc6299db9ec823,pagecache-0.6.0,260742
github.com-1ecc6299db9ec823,ritelinked-0.3.2,142063
github.com-1ecc6299db9ec823,ethers-contract-1.0.2,589452
github.com-1ecc6299db9ec823,color_quant-1.1.0,21284
github.com-1ecc6299db9ec823,libykpers-sys-0.3.1,14270
github.com-1ecc6299db9ec823,cgmath-0.17.0,367702
github.com-1ecc6299db9ec823,clap-4.0.18,1096299
github.com-1ecc6299db9ec823,ears-0.5.1,165152
github.com-1ecc6299db9ec823,h2-0.2.5,765073
github.com-1ecc6299db9ec823,image-0.22.5,725576
github.com-1ecc6299db9ec823,digest-0.10.1,83013
github.com-1ecc6299db9ec823,js-sys-0.3.46,410849
github.com-1ecc6299db9ec823,psl-types-2.0.11,25329
github.com-1ecc6299db9ec823,apub-core-0.2.0,52434
github.com-1ecc6299db9ec823,thiserror-1.0.22,59077
github.com-1ecc6299db9ec823,num-complex-0.4.3,139539
github.com-1ecc6299db9ec823,autocfg-1.0.1,41521
github.com-1ecc6299db9ec823,amethyst_locale-0.15.3,4896
github.com-1ecc6299db9ec823,tokio-timer-0.2.11,167147
github.com-1ecc6299db9ec823,pipe-trait-0.2.1,11031
github.com-1ecc6299db9ec823,http-muncher-0.3.2,259101
github.com-1ecc6299db9ec823,thin-dst-1.1.0,46297
github.com-1ecc6299db9ec823,float-ord-0.2.0,21145
github.com-1ecc6299db9ec823,trust-dns-proto-0.21.2,1312809
github.com-1ecc6299db9ec823,ordered-multimap-0.4.3,178966
github.com-1ecc6299db9ec823,bitflags-0.4.0,33932
github.com-1ecc6299db9ec823,windows_x86_64_gnullvm-0.42.0,3240134
github.com-1ecc6299db9ec823,cargo-util-0.1.2,72189
github.com-1ecc6299db9ec823,serde_with_macros-1.5.2,72325
github.com-1ecc6299db9ec823,wasmer-2.3.0,529984
github.com-1ecc6299db9ec823,tokio-codec-0.1.2,30428
github.com-1ecc6299db9ec823,pico-args-0.5.0,54991
github.com-1ecc6299db9ec823,migformatting-0.1.1,1680
github.com-1ecc6299db9ec823,lexical-core-0.6.7,2382284
github.com-1ecc6299db9ec823,katex-wasmbind-0.10.0,274096
github.com-1ecc6299db9ec823,blender-armature-0.0.1,51371
github.com-1ecc6299db9ec823,twoway-0.2.1,129719
github.com-1ecc6299db9ec823,sha3-0.10.0,540582
github.com-1ecc6299db9ec823,ringbuf-0.2.8,92733
github.com-1ecc6299db9ec823,pest_meta-2.1.3,175833
github.com-1ecc6299db9ec823,selectme-macros-0.7.1,79130
github.com-1ecc6299db9ec823,secp256k1-sys-0.7.0,5303296
github.com-1ecc6299db9ec823,panic-probe-0.3.0,18841
github.com-1ecc6299db9ec823,ron-0.6.6,208755
github.com-1ecc6299db9ec823,defmt-macros-0.3.3,78405
github.com-1ecc6299db9ec823,winapi-x86_64-pc-windows-gnu-0.4.0,53158182
github.com-1ecc6299db9ec823,aph-0.2.0,30088
github.com-1ecc6299db9ec823,winnow-0.4.6,959730
github.com-1ecc6299db9ec823,syntex_syntax-0.54.0,1272567
github.com-1ecc6299db9ec823,prost-derive-0.11.9,99428
github.com-1ecc6299db9ec823,commoncrypto-sys-0.2.0,16095
github.com-1ecc6299db9ec823,yew-router-macro-0.15.0,42667
github.com-1ecc6299db9ec823,http-range-header-0.3.0,29647
github.com-1ecc6299db9ec823,crossbeam-queue-0.2.3,60131
github.com-1ecc6299db9ec823,slice-deque-0.3.0,271889
github.com-1ecc6299db9ec823,libc-0.2.65,2334946
github.com-1ecc6299db9ec823,minidom-0.14.0,102507
github.com-1ecc6299db9ec823,tokio-native-tls-0.3.0,60313
github.com-1ecc6299db9ec823,glam-0.17.3,1191013
github.com-1ecc6299db9ec823,semver-1.0.6,114819
github.com-1ecc6299db9ec823,cortex-m-rtfm-macros-0.5.1,112048
github.com-1ecc6299db9ec823,bitvec-1.0.0,1006982
github.com-1ecc6299db9ec823,gfx-backend-metal-0.6.5,660301
github.com-1ecc6299db9ec823,object-0.30.1,1467041
github.com-1ecc6299db9ec823,proc-macro-error-attr-0.4.11,18220
github.com-1ecc6299db9ec823,proteus-0.5.0,179567
github.com-1ecc6299db9ec823,crunchy-0.1.6,6678
github.com-1ecc6299db9ec823,once_cell-1.7.2,121632
github.com-1ecc6299db9ec823,rel-0.2.0,14524
github.com-1ecc6299db9ec823,lexical-core-0.7.5,2355166
github.com-1ecc6299db9ec823,windows_x86_64_gnu-0.42.1,10581222
github.com-1ecc6299db9ec823,thread_local-1.1.5,49409
github.com-1ecc6299db9ec823,openssl-sys-0.9.63,285709
github.com-1ecc6299db9ec823,simplelog-0.11.2,85170
github.com-1ecc6299db9ec823,thiserror-impl-1.0.25,55249
github.com-1ecc6299db9ec823,quanta-0.10.0,82241
github.com-1ecc6299db9ec823,vsmtp-common-1.4.0-rc.10,122740
github.com-1ecc6299db9ec823,tonic-0.1.0-alpha.6,302938
github.com-1ecc6299db9ec823,ecdsa-0.16.1,121203
github.com-1ecc6299db9ec823,deltae-0.3.0,2871017
github.com-1ecc6299db9ec823,phf_shared-0.11.1,30454
github.com-1ecc6299db9ec823,trustfall-rustdoc-adapter-22.5.2,5348192
github.com-1ecc6299db9ec823,mockall_derive-0.11.0,227736
github.com-1ecc6299db9ec823,wasm-bindgen-0.2.64,584320
github.com-1ecc6299db9ec823,sg-std-0.12.0,27020
github.com-1ecc6299db9ec823,chalk-ir-0.87.0,288472
github.com-1ecc6299db9ec823,environment-0.1.1,9957
github.com-1ecc6299db9ec823,crash-handler-0.3.3,125183
github.com-1ecc6299db9ec823,bindgen-0.59.2,958852
github.com-1ecc6299db9ec823,serde_path_to_error-0.1.7,101591
github.com-1ecc6299db9ec823,tinyvec-0.3.3,77508
github.com-1ecc6299db9ec823,precomputed-hash-0.1.1,2853
github.com-1ecc6299db9ec823,rustc-rayon-core-0.4.1,264995
github.com-1ecc6299db9ec823,gix-sec-0.6.2,57428
github.com-1ecc6299db9ec823,pistoncore-input-0.19.0,83490
github.com-1ecc6299db9ec823,gloo-utils-0.1.5,15602
github.com-1ecc6299db9ec823,redox_intelflash-0.1.3,28056
github.com-1ecc6299db9ec823,block2-0.2.0-alpha.6,39192
github.com-1ecc6299db9ec823,fastly-shared-0.9.1,19292
github.com-1ecc6299db9ec823,ibc-chain-registry-0.1.0,48243
github.com-1ecc6299db9ec823,socket2-0.4.4,205035
github.com-1ecc6299db9ec823,futures-channel-0.3.19,132274
github.com-1ecc6299db9ec823,structopt-0.3.16,217443
github.com-1ecc6299db9ec823,rusty-fork-0.2.2,64570
github.com-1ecc6299db9ec823,parking_lot_core-0.9.7,139601
github.com-1ecc6299db9ec823,async-lock-2.6.0,99844
github.com-1ecc6299db9ec823,bindgen-0.56.0,923373
github.com-1ecc6299db9ec823,quad-rand-0.2.1,9108
github.com-1ecc6299db9ec823,wasmflow-codec-0.10.0,12343
github.com-1ecc6299db9ec823,gix-0.38.0,883190
github.com-1ecc6299db9ec823,futures-macro-0.3.27,38519
github.com-1ecc6299db9ec823,portable-atomic-0.3.13,549649
github.com-1ecc6299db9ec823,portable-atomic-1.3.2,799707
github.com-1ecc6299db9ec823,bevy-crevice-derive-0.6.0,16165
github.com-1ecc6299db9ec823,gltf-json-0.15.2,118263
github.com-1ecc6299db9ec823,struple-impl-0.1.0,4096
github.com-1ecc6299db9ec823,annotate-snippets-0.9.1,153174
github.com-1ecc6299db9ec823,futures-core-0.3.28,46207
github.com-1ecc6299db9ec823,wezterm-bidi-0.2.2,361283
github.com-1ecc6299db9ec823,mildew-0.1.2,3002
github.com-1ecc6299db9ec823,bytecount-0.6.3,46567
github.com-1ecc6299db9ec823,numext-fixed-hash-core-0.1.6,7403
github.com-1ecc6299db9ec823,bytesize-1.1.0,34012
github.com-1ecc6299db9ec823,oxsdatatypes-0.1.0,174662
github.com-1ecc6299db9ec823,hostname-0.1.5,4811
github.com-1ecc6299db9ec823,io-lifetimes-1.0.4,207652
github.com-1ecc6299db9ec823,derive_builder_core-0.11.2,135502
github.com-1ecc6299db9ec823,ttf-parser-0.15.2,711615
github.com-1ecc6299db9ec823,tracing-opentelemetry-0.17.4,187675
github.com-1ecc6299db9ec823,ab_glyph_rasterizer-0.1.7,34278
github.com-1ecc6299db9ec823,bevy_diagnostic-0.6.0,14396
github.com-1ecc6299db9ec823,toml_datetime-0.5.0,34801
github.com-1ecc6299db9ec823,wasm-parser-0.1.7,39726
github.com-1ecc6299db9ec823,ppv-null-0.1.2,26098
github.com-1ecc6299db9ec823,ci_info-0.10.2,1197933
github.com-1ecc6299db9ec823,jobserver-0.1.21,72720
github.com-1ecc6299db9ec823,sentencepiece-sys-0.10.0,10055292
github.com-1ecc6299db9ec823,zstd-sys-2.0.1+zstd.1.5.2,3387955
github.com-1ecc6299db9ec823,byte-strings-proc_macros-0.2.2,7886
github.com-1ecc6299db9ec823,snapbox-0.4.11,193312
github.com-1ecc6299db9ec823,ron-0.6.4,198516
github.com-1ecc6299db9ec823,gix-object-0.28.0,102536
github.com-1ecc6299db9ec823,strum_macros-0.23.1,87403
github.com-1ecc6299db9ec823,defmt-0.3.2,93568
github.com-1ecc6299db9ec823,openssl-0.10.35,971227
github.com-1ecc6299db9ec823,gtk-sys-0.14.0,1376726
github.com-1ecc6299db9ec823,gpu-alloc-0.4.7,99476
github.com-1ecc6299db9ec823,colored-2.0.0,91075
github.com-1ecc6299db9ec823,fixedbitset-0.4.2,67872
github.com-1ecc6299db9ec823,argparse-0.2.2,95032
github.com-1ecc6299db9ec823,bevy_mod_raycast-0.6.2,456756
github.com-1ecc6299db9ec823,byte-strings-0.2.2,35209
github.com-1ecc6299db9ec823,mem_tools-0.1.0,937956
github.com-1ecc6299db9ec823,deno_core-0.167.0,11067700
github.com-1ecc6299db9ec823,rocksdb-0.19.0,628015
github.com-1ecc6299db9ec823,num-traits-0.2.12,231414
github.com-1ecc6299db9ec823,type-info-derive-0.2.0,56221
github.com-1ecc6299db9ec823,structopt-derive-0.3.4,68017
github.com-1ecc6299db9ec823,extendr-macros-0.3.1,49695
github.com-1ecc6299db9ec823,secret-cosmwasm-std-1.0.0,632711
github.com-1ecc6299db9ec823,skim-0.7.0,380243
github.com-1ecc6299db9ec823,serde-1.0.135,501463
github.com-1ecc6299db9ec823,lock_api-0.1.5,109183
github.com-1ecc6299db9ec823,cw-multi-test-0.16.2,445599
github.com-1ecc6299db9ec823,quote-1.0.10,120640
github.com-1ecc6299db9ec823,safemem-0.3.2,17382
github.com-1ecc6299db9ec823,gloo-dialogs-0.1.1,4653
github.com-1ecc6299db9ec823,dashmap-4.0.2,105438
github.com-1ecc6299db9ec823,oorandom-11.1.0,31893
github.com-1ecc6299db9ec823,polars-core-0.21.1,1678691
github.com-1ecc6299db9ec823,claxon-0.4.2,259276
github.com-1ecc6299db9ec823,cc-1.0.35,179169
github.com-1ecc6299db9ec823,cocoa-0.19.1,296083
github.com-1ecc6299db9ec823,tokio-1.9.0,2490393
github.com-1ecc6299db9ec823,gix-refspec-0.10.1,105495
github.com-1ecc6299db9ec823,futures-task-0.3.12,39561
github.com-1ecc6299db9ec823,sqlx-core-0.4.2,1064795
github.com-1ecc6299db9ec823,futures-task-0.3.14,39566
github.com-1ecc6299db9ec823,datastore_grpc-0.4.0,18233399
github.com-1ecc6299db9ec823,directories-4.0.1,74013
github.com-1ecc6299db9ec823,wgpu-hal-0.15.1,1201034
github.com-1ecc6299db9ec823,discard-1.0.4,14342
github.com-1ecc6299db9ec823,tinytga-0.1.0,102322
github.com-1ecc6299db9ec823,prost-types-0.10.1,126121
github.com-1ecc6299db9ec823,assert2-0.3.6,36145
github.com-1ecc6299db9ec823,syn-inline-mod-0.5.0,35740
github.com-1ecc6299db9ec823,bat-0.22.1,5407476
github.com-1ecc6299db9ec823,minidumper-child-0.1.0,32329
github.com-1ecc6299db9ec823,libp2p-kad-0.21.0,416675
github.com-1ecc6299db9ec823,asn1_der-0.6.3,1102166
github.com-1ecc6299db9ec823,h2-0.2.4,764682
github.com-1ecc6299db9ec823,ena-0.14.2,90713
github.com-1ecc6299db9ec823,prost-build-0.8.0,31248726
github.com-1ecc6299db9ec823,wasmer-compiler-cranelift-3.1.1,300456
github.com-1ecc6299db9ec823,gfx-hal-0.7.0,238750
github.com-1ecc6299db9ec823,nom-4.2.3,644514
github.com-1ecc6299db9ec823,os_str_bytes-2.4.0,52159
github.com-1ecc6299db9ec823,sourcemap-6.2.1,135303
github.com-1ecc6299db9ec823,actix-router-0.5.1,150753
github.com-1ecc6299db9ec823,markup5ever-0.9.0,229731
github.com-1ecc6299db9ec823,gloo-worker-0.2.1,31624
github.com-1ecc6299db9ec823,object-0.25.3,1313095
github.com-1ecc6299db9ec823,rustversion-1.0.0,41602

View File

@ -0,0 +1,148 @@
//! Utility for capturing a global cache last-use database based on the files
//! on a real-world system.
//!
//! This will look in the CARGO_HOME of the current system and record last-use
//! data for all files in the cache. This is intended to provide a real-world
//! example for a benchmark that should be close to what a real set of data
//! should look like.
//!
//! See `benches/global_cache_tracker.rs` for the benchmark that uses this
//! data.
//!
//! The database is kept in git. It usually shouldn't need to be re-generated
//! unless there is a change in the schema or the benchmark.
use cargo::core::global_cache_tracker::{self, DeferredGlobalLastUse, GlobalCacheTracker};
use cargo::util::cache_lock::CacheLockMode;
use cargo::util::interning::InternedString;
use cargo::Config;
use rand::prelude::SliceRandom;
use std::collections::HashMap;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
// Set up config.
let shell = cargo::core::Shell::new();
let homedir = Path::new(env!("CARGO_MANIFEST_DIR")).join("global-cache-tracker");
let cwd = homedir.clone();
let mut config = Config::new(shell, cwd, homedir.clone());
config
.configure(
0,
false,
None,
false,
false,
false,
&None,
&["gc".to_string()],
&[],
)
.unwrap();
let db_path = GlobalCacheTracker::db_path(&config).into_path_unlocked();
if db_path.exists() {
fs::remove_file(&db_path).unwrap();
}
let _lock = config
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
.unwrap();
let mut deferred = DeferredGlobalLastUse::new();
let mut tracker = GlobalCacheTracker::new(&config).unwrap();
let real_home = cargo::util::homedir(&std::env::current_dir().unwrap()).unwrap();
let cache_dir = real_home.join("registry/cache");
for dir_ent in fs::read_dir(cache_dir).unwrap() {
let registry = dir_ent.unwrap();
let encoded_registry_name = InternedString::new(&registry.file_name().to_string_lossy());
for krate in fs::read_dir(registry.path()).unwrap() {
let krate = krate.unwrap();
let meta = krate.metadata().unwrap();
deferred.mark_registry_crate_used_stamp(
global_cache_tracker::RegistryCrate {
encoded_registry_name,
crate_filename: krate.file_name().to_string_lossy().as_ref().into(),
size: meta.len(),
},
Some(&meta.modified().unwrap()),
);
}
}
let mut src_entries = Vec::new();
let cache_dir = real_home.join("registry/src");
for dir_ent in fs::read_dir(cache_dir).unwrap() {
let registry = dir_ent.unwrap();
let encoded_registry_name = InternedString::new(&registry.file_name().to_string_lossy());
for krate in fs::read_dir(registry.path()).unwrap() {
let krate = krate.unwrap();
let meta = krate.metadata().unwrap();
let src = global_cache_tracker::RegistrySrc {
encoded_registry_name,
package_dir: krate.file_name().to_string_lossy().as_ref().into(),
size: Some(cargo_util::du(&krate.path(), &[]).unwrap()),
};
src_entries.push(src.clone());
let timestamp = meta.modified().unwrap();
deferred.mark_registry_src_used_stamp(src, Some(&timestamp));
}
}
let git_co_dir = real_home.join("git/checkouts");
for dir_ent in fs::read_dir(git_co_dir).unwrap() {
let git_source = dir_ent.unwrap();
let encoded_git_name = InternedString::new(&git_source.file_name().to_string_lossy());
for co in fs::read_dir(git_source.path()).unwrap() {
let co = co.unwrap();
let meta = co.metadata().unwrap();
deferred.mark_git_checkout_used_stamp(
global_cache_tracker::GitCheckout {
encoded_git_name,
short_name: co.file_name().to_string_lossy().as_ref().into(),
size: Some(cargo_util::du(&co.path(), &[]).unwrap()),
},
Some(&meta.modified().unwrap()),
);
}
}
deferred.save(&mut tracker).unwrap();
drop(deferred);
drop(tracker);
fs::rename(&db_path, homedir.join("global-cache-sample")).unwrap();
// Clean up the lock file created above.
fs::remove_file(homedir.join(".package-cache")).unwrap();
// Save a random sample of crates that the benchmark should update.
// Pick whichever registry has the most entries. This is to be somewhat
// realistic for the common case that all dependencies come from one
// registry (crates.io).
let mut counts = HashMap::new();
for src in &src_entries {
let c: &mut u32 = counts.entry(src.encoded_registry_name).or_default();
*c += 1;
}
let mut counts: Vec<_> = counts.into_iter().map(|(k, v)| (v, k)).collect();
counts.sort();
let biggest = counts.last().unwrap().1;
src_entries.retain(|src| src.encoded_registry_name == biggest);
let mut rng = &mut rand::thread_rng();
let sample: Vec<_> = src_entries.choose_multiple(&mut rng, 500).collect();
let mut f = File::create(homedir.join("random-sample")).unwrap();
for src in sample {
writeln!(
f,
"{},{},{}",
src.encoded_registry_name,
src.package_dir,
src.size.unwrap()
)
.unwrap();
}
}