Skip to content

Commit b393756

Browse files
Record duration of collector benchmarking
1 parent 807246b commit b393756

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

collector/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::io::{stderr, Write};
1313
use std::path::{Path, PathBuf};
1414
use std::process;
1515
use std::process::Command;
16-
use std::str;
16+
use std::{str, time::Instant};
1717
use tokio::runtime::Runtime;
1818

1919
mod background_worker;
@@ -274,6 +274,7 @@ fn bench(
274274
}
275275
let interned_cid = rt.block_on(tx.conn().artifact_id(&cid));
276276

277+
let start = Instant::now();
277278
for (nth_benchmark, benchmark) in benchmarks.iter().enumerate() {
278279
rt.block_on(
279280
tx.conn()
@@ -315,6 +316,11 @@ fn bench(
315316
}
316317
}
317318
}
319+
let end = start.elapsed();
320+
321+
eprintln!("collection took {:?}", end);
322+
323+
rt.block_on(tx.conn().record_duration(interned_cid, end));
318324

319325
// Publish results now that we've finished fully with this commit.
320326
rt.block_on(tx.commit()).unwrap();

database/src/pool.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{ArtifactId, ArtifactIdNumber};
22
use crate::{Cache, CollectionId, Index, Profile, QueryDatum, QueuedCommit};
33
use hashbrown::HashMap;
44
use std::sync::{Arc, Mutex};
5+
use std::time::Duration;
56
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
67

78
pub mod both;
@@ -15,6 +16,10 @@ pub trait Connection: Send + Sync {
1516

1617
async fn load_index(&mut self) -> Index;
1718

19+
/// This records the duration of a collection run, i.e., collecting all of
20+
/// the statistics for a particular artifact.
21+
async fn record_duration(&self, artifact: ArtifactIdNumber, duration: Duration);
22+
1823
async fn collection_id(&self) -> CollectionId;
1924
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber;
2025
async fn record_benchmark(&self, krate: &str, supports_stable: bool);

database/src/pool/both.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ where
186186
self.b.record_benchmark(krate, supports_stable)
187187
);
188188
}
189+
async fn record_duration(
190+
&self,
191+
artifact: crate::ArtifactIdNumber,
192+
duration: std::time::Duration,
193+
) {
194+
join!(
195+
self.a.record_duration(artifact, duration),
196+
self.b.record_duration(artifact, duration)
197+
);
198+
}
189199
}
190200

191201
#[async_trait::async_trait]
@@ -349,4 +359,14 @@ impl<'a> Connection for BothTransaction<'a> {
349359
self.b.conn_ref().record_benchmark(krate, supports_stable)
350360
);
351361
}
362+
async fn record_duration(
363+
&self,
364+
artifact: crate::ArtifactIdNumber,
365+
duration: std::time::Duration,
366+
) {
367+
join!(
368+
self.a.conn_ref().record_duration(artifact, duration),
369+
self.b.conn_ref().record_duration(artifact, duration)
370+
);
371+
}
352372
}

database/src/pool/postgres.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ static MIGRATIONS: &[&str] = &[
152152
r#"
153153
create unique index on pull_request_build (pr) where complete = false;
154154
"#,
155+
r#"
156+
create table artifact_collection_duration(
157+
aid smallint primary key not null references artifact(id) on delete cascade on update cascade,
158+
date_recorded timestamptz not null,
159+
duration integer not null
160+
);
161+
"#,
155162
];
156163

157164
#[async_trait::async_trait]
@@ -222,6 +229,7 @@ pub struct CachedStatements {
222229
select_pstat_series: Statement,
223230
get_error: Statement,
224231
collection_id: Statement,
232+
record_duration: Statement,
225233
}
226234

227235
pub struct PostgresTransaction<'a> {
@@ -336,6 +344,13 @@ impl PostgresConnection {
336344
insert_pstat_series: conn.prepare("insert into pstat_series (crate, profile, cache, statistic) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING RETURNING id").await.unwrap(),
337345
select_pstat_series: conn.prepare("select id from pstat_series where crate = $1 and profile = $2 and cache = $3 and statistic = $4").await.unwrap(),
338346
collection_id: conn.prepare("insert into collection DEFAULT VALUES returning id").await.unwrap(),
347+
record_duration: conn.prepare("
348+
insert into artifact_collection_duration (
349+
aid,
350+
date_recorded,
351+
duration
352+
) VALUES ($1, CURRENT_TIMESTAMP, $2)
353+
").await.unwrap(),
339354
}),
340355
conn,
341356
}
@@ -356,6 +371,17 @@ where
356371
conn: tx,
357372
})
358373
}
374+
375+
async fn record_duration(&self, artifact: ArtifactIdNumber, duration: Duration) {
376+
self.conn()
377+
.execute(
378+
&self.statements().record_duration,
379+
&[&(artifact.0 as i16), &(duration.as_secs() as i32)],
380+
)
381+
.await
382+
.unwrap();
383+
}
384+
359385
async fn load_index(&mut self) -> Index {
360386
Index {
361387
commits: self

database/src/pool/sqlite.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ static MIGRATIONS: &[&str] = &[
133133
requested timestamp without time zone
134134
);
135135
"#,
136+
r#"
137+
create table artifact_collection_duration(
138+
aid integer primary key not null references artifact(id) on delete cascade on update cascade,
139+
date_recorded timestamp without time zone not null,
140+
duration integer not null
141+
);
142+
"#,
136143
];
137144

138145
#[async_trait::async_trait]
@@ -209,6 +216,16 @@ impl Connection for SqliteConnection {
209216
})
210217
}
211218

219+
async fn record_duration(&self, artifact: ArtifactIdNumber, duration: Duration) {
220+
self.raw_ref()
221+
.prepare_cached(
222+
"insert into artifact_collection_duration (aid, date_recorded, duration) VALUES (?, strftime('%s','now'), ?)",
223+
)
224+
.unwrap()
225+
.execute(params![artifact.0, duration.as_secs() as i64])
226+
.unwrap();
227+
}
228+
212229
async fn load_index(&mut self) -> Index {
213230
let commits = self
214231
.raw()
@@ -386,7 +403,7 @@ impl Connection for SqliteConnection {
386403
async fn queue_pr(&self, pr: u32) {
387404
self.raw_ref()
388405
.prepare_cached(
389-
"insert into pull_request_builds (pr, complete, requested) VALUES (?, 0, now)",
406+
"insert into pull_request_builds (pr, complete, requested) VALUES (?, 0, strftime('%s','now'))",
390407
)
391408
.unwrap()
392409
.execute(params![pr])

0 commit comments

Comments
 (0)