Skip to content

Commit c4897ba

Browse files
committed
Extract async runtime creation into a separate function
1 parent 65c438f commit c4897ba

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

collector/src/bin/collector.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,6 @@ fn main_result() -> anyhow::Result<i32> {
645645
runtime: &runtime_benchmark_dir,
646646
};
647647

648-
let mut builder = tokio::runtime::Builder::new_multi_thread();
649-
// We want to minimize noise from the runtime
650-
builder
651-
.worker_threads(1)
652-
.max_blocking_threads(1)
653-
.enable_time()
654-
.enable_io();
655-
let mut rt = builder.build().expect("built runtime");
656-
657648
// XXX: This doesn't necessarily work for all archs
658649
let target_triple = format!("{}-unknown-linux-gnu", std::env::consts::ARCH);
659650

@@ -765,6 +756,7 @@ fn main_result() -> anyhow::Result<i32> {
765756
CargoIsolationMode::Isolated
766757
};
767758

759+
let mut rt = build_async_runtime();
768760
let mut conn = rt.block_on(pool.connection());
769761
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
770762
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
@@ -916,6 +908,7 @@ fn main_result() -> anyhow::Result<i32> {
916908
benchmarks.retain(|b| local.category.0.contains(&b.category()));
917909

918910
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
911+
let mut rt = build_async_runtime();
919912
let mut conn = rt.block_on(pool.connection());
920913
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
921914

@@ -965,6 +958,7 @@ fn main_result() -> anyhow::Result<i32> {
965958
};
966959

967960
let pool = database::Pool::open(&db.db);
961+
let mut rt = build_async_runtime();
968962

969963
let res = match next {
970964
NextArtifact::Release(tag) => {
@@ -1047,6 +1041,7 @@ fn main_result() -> anyhow::Result<i32> {
10471041
Commands::BenchPublished { toolchain, db } => {
10481042
log_db(&db);
10491043
let pool = database::Pool::open(&db.db);
1044+
let mut rt = build_async_runtime();
10501045
let conn = rt.block_on(pool.connection());
10511046
let toolchain = create_toolchain_from_published_version(&toolchain, &target_triple)?;
10521047
bench_published_artifact(conn, &mut rt, toolchain, &benchmark_dirs)?;
@@ -1204,6 +1199,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
12041199
}
12051200
Commands::PurgeArtifact { name, db } => {
12061201
let pool = Pool::open(&db.db);
1202+
let rt = build_async_runtime();
12071203
let conn = rt.block_on(pool.connection());
12081204
rt.block_on(conn.purge_artifact(&ArtifactId::Tag(name.clone())));
12091205

@@ -1213,6 +1209,17 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
12131209
}
12141210
}
12151211

1212+
fn build_async_runtime() -> Runtime {
1213+
let mut builder = tokio::runtime::Builder::new_multi_thread();
1214+
// We want to minimize noise from the runtime
1215+
builder
1216+
.worker_threads(1)
1217+
.max_blocking_threads(1)
1218+
.enable_time()
1219+
.enable_io();
1220+
builder.build().expect("built runtime")
1221+
}
1222+
12161223
fn print_binary_stats(
12171224
name_header: &str,
12181225
items: HashMap<String, u64>,

0 commit comments

Comments
 (0)