Skip to content

Commit 0f2f247

Browse files
Record timings for smaller steps than whole run timing
This should also provide the baseline for progress reporting on the UI (and eventually -- estimates of completion time!). It should also mean that we can more easily alert on things like "step taking 2x longer than it should".
1 parent 47bea3f commit 0f2f247

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

collector/src/main.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,15 @@ fn bench(
194194
iterations: usize,
195195
self_profile: bool,
196196
) -> BenchmarkErrors {
197-
let status_conn = rt.block_on(pool.connection());
198197
let mut conn = rt.block_on(pool.connection());
198+
let status_conn;
199+
let status_conn: Option<&dyn database::Connection> =
200+
if conn.separate_transaction_for_collector() {
201+
status_conn = rt.block_on(pool.connection());
202+
Some(&*status_conn)
203+
} else {
204+
None
205+
};
199206
let mut errors = BenchmarkErrors::new();
200207
eprintln!("Benchmarking {} for triple {}", cid, compiler.triple);
201208

@@ -229,9 +236,17 @@ fn bench(
229236
.iter()
230237
.map(|b| b.name.to_string())
231238
.collect::<Vec<_>>();
232-
rt.block_on(status_conn.collector_start(interned_cid, &steps));
239+
rt.block_on(
240+
status_conn
241+
.unwrap_or_else(|| &*tx.conn())
242+
.collector_start(interned_cid, &steps),
243+
);
233244
for (nth_benchmark, benchmark) in benchmarks.iter().enumerate() {
234-
rt.block_on(status_conn.collector_start_step(interned_cid, &benchmark.name.to_string()));
245+
rt.block_on(
246+
status_conn
247+
.unwrap_or_else(|| &*tx.conn())
248+
.collector_start_step(interned_cid, &benchmark.name.to_string()),
249+
);
235250
rt.block_on(
236251
tx.conn()
237252
.record_benchmark(benchmark.name.0.as_str(), benchmark.supports_stable()),
@@ -262,7 +277,11 @@ fn bench(
262277
&format!("{:?}", s),
263278
));
264279
};
265-
rt.block_on(status_conn.collector_end_step(interned_cid, &benchmark.name.to_string()));
280+
rt.block_on(
281+
status_conn
282+
.unwrap_or_else(|| &*tx.conn())
283+
.collector_end_step(interned_cid, &benchmark.name.to_string()),
284+
);
266285
}
267286
let end = start.elapsed();
268287

database/src/pool.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ pub trait Connection: Send + Sync {
6767
async fn collector_start(&self, aid: ArtifactIdNumber, steps: &[String]);
6868
async fn collector_start_step(&self, aid: ArtifactIdNumber, step: &str);
6969
async fn collector_end_step(&self, aid: ArtifactIdNumber, step: &str);
70+
71+
// This returns `true` if the collector commands can be placed in a separate
72+
// transaction.
73+
//
74+
// Currently, the sqlite backend does not support "regular" usage where they
75+
// are used for genuine progress reporting. sqlite does not support
76+
// concurrent writers -- it will return an error (or wait, if a busy timeout
77+
// is configured).
78+
//
79+
// For now we don't care much as sqlite is not used in production and in
80+
// local usage you can just look at the logs.
81+
fn separate_transaction_for_collector(&self) -> bool;
7082
}
7183

7284
#[async_trait::async_trait]

database/src/pool/postgres.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ where
802802
async fn collector_start_step(&self, aid: ArtifactIdNumber, step: &str) {
803803
self.conn()
804804
.execute(
805-
"update collector_progress set start = CURRENT_TIMESTAMP \
805+
"update collector_progress set start = statement_timestamp() \
806806
where aid = $1 and step = $2 and start is null and end is null;",
807807
&[&(aid.0 as i16), &step],
808808
)
@@ -812,11 +812,14 @@ where
812812
async fn collector_end_step(&self, aid: ArtifactIdNumber, step: &str) {
813813
self.conn()
814814
.execute(
815-
"update collector_progress set end = CURRENT_TIMESTAMP \
815+
"update collector_progress set end = statement_timestamp() \
816816
where aid = $1 and step = $2 and start is not null and end is null;",
817817
&[&(aid.0 as i16), &step],
818818
)
819819
.await
820820
.unwrap();
821821
}
822+
fn separate_transaction_for_collector(&self) -> bool {
823+
true
824+
}
822825
}

database/src/pool/sqlite.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ static MIGRATIONS: &[&str] = &[
144144
create table collector_progress(
145145
aid integer not null references artifact(id) on delete cascade on update cascade,
146146
step text not null,
147-
start timestamp without time zone,
148-
end timestamp without time zone
147+
start integer,
148+
end integer
149149
);
150150
"#,
151151
];
@@ -653,7 +653,7 @@ impl Connection for SqliteConnection {
653653
async fn collector_start_step(&self, aid: ArtifactIdNumber, step: &str) {
654654
self.raw_ref()
655655
.execute(
656-
"update collector_progress set start = now \
656+
"update collector_progress set start = strftime('%s','now') \
657657
where aid = ? and step = ? and start is null;",
658658
params![&aid.0, &step],
659659
)
@@ -662,10 +662,13 @@ impl Connection for SqliteConnection {
662662
async fn collector_end_step(&self, aid: ArtifactIdNumber, step: &str) {
663663
self.raw_ref()
664664
.execute(
665-
"update collector_progress set end = now \
665+
"update collector_progress set end = strftime('%s','now') \
666666
where aid = ? and step = ? and start is not null and end is null;",
667667
params![&aid.0, &step],
668668
)
669669
.unwrap();
670670
}
671+
fn separate_transaction_for_collector(&self) -> bool {
672+
false
673+
}
671674
}

0 commit comments

Comments
 (0)