Skip to content

Commit 96a9692

Browse files
committed
Add artifact_size DB table to store artifact component sizes
1 parent 229bc65 commit 96a9692

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

database/schema.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ id name date type
6161
1 LOCAL_TEST release
6262
```
6363

64+
### artifact size
65+
66+
Records the size of individual components (like `librustc_driver.so` or `libLLVM.so`) of a single
67+
artifact.
68+
69+
This description includes:
70+
* component: normalized name of the component (hashes are removed)
71+
* size: size of the component in bytes
72+
73+
```
74+
sqlite> select * from artifact_size limit 1;
75+
aid component size
76+
---------- ---------- ----------
77+
1 libLLVM.so 177892352
78+
```
79+
6480
### collection
6581

6682
A "collection" of benchmarks tied only differing by the statistic collected.

database/src/pool.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ pub trait Connection: Send + Sync {
8686
krate: &str,
8787
value: Duration,
8888
);
89+
90+
/// Records the size of an artifact component (like `librustc_driver.so` or `libLLVM.so`) in
91+
/// bytes.
92+
async fn record_artifact_size(&self, artifact: ArtifactIdNumber, component: &str, size: u64);
93+
8994
/// Returns vector of bootstrap build times for the given artifacts. The kth
9095
/// element is the minimum build time for the kth artifact in `aids`, across
9196
/// all collections for the artifact, or none if there is no bootstrap data

database/src/pool/postgres.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use chrono::{DateTime, TimeZone, Utc};
88
use hashbrown::HashMap;
99
use native_tls::{Certificate, TlsConnector};
1010
use postgres_native_tls::MakeTlsConnector;
11-
use std::convert::TryFrom;
11+
use std::convert::{TryFrom, TryInto};
1212
use std::str::FromStr;
1313
use std::sync::Arc;
1414
use std::time::Duration;
@@ -246,6 +246,14 @@ static MIGRATIONS: &[&str] = &[
246246
drop table error_series;
247247
alter table error_new rename to error;
248248
"#,
249+
r#"
250+
create table artifact_size(
251+
aid integer references artifact(id) on delete cascade on update cascade,
252+
component text not null,
253+
size integer not null,
254+
UNIQUE(aid, component)
255+
);
256+
"#,
249257
];
250258

251259
#[async_trait::async_trait]
@@ -328,6 +336,7 @@ pub struct CachedStatements {
328336
select_runtime_pstat_series: Statement,
329337
insert_runtime_pstat: Statement,
330338
get_runtime_pstat: Statement,
339+
record_artifact_size: Statement,
331340
}
332341

333342
pub struct PostgresTransaction<'a> {
@@ -513,7 +522,14 @@ impl PostgresConnection {
513522
order by sids.idx
514523
")
515524
.await
516-
.unwrap()
525+
.unwrap(),
526+
record_artifact_size: conn.prepare("
527+
insert into artifact_size (aid, component, size)
528+
values ($1, $2, $3)
529+
on conflict (aid, component)
530+
do update
531+
set size = excluded.size
532+
").await.unwrap(),
517533
}),
518534
conn,
519535
}
@@ -903,6 +919,17 @@ where
903919
.unwrap();
904920
}
905921

922+
async fn record_artifact_size(&self, artifact: ArtifactIdNumber, component: &str, size: u64) {
923+
let size: i32 = size.try_into().expect("Too large artifact");
924+
self.conn()
925+
.execute(
926+
&self.statements().record_artifact_size,
927+
&[&(artifact.0 as i32), &component, &size],
928+
)
929+
.await
930+
.unwrap();
931+
}
932+
906933
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber {
907934
let (name, date, ty) = match artifact {
908935
ArtifactId::Commit(commit) => (

database/src/pool/sqlite.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,16 @@ static MIGRATIONS: &[Migration] = &[
357357
alter table error_new rename to error;
358358
"#,
359359
),
360+
Migration::new(
361+
r#"
362+
create table artifact_size(
363+
aid integer references artifact(id) on delete cascade on update cascade,
364+
component text not null,
365+
size integer not null,
366+
UNIQUE(aid, component)
367+
);
368+
"#,
369+
),
360370
];
361371

362372
#[async_trait::async_trait]
@@ -791,6 +801,16 @@ impl Connection for SqliteConnection {
791801
.unwrap();
792802
}
793803

804+
async fn record_artifact_size(&self, artifact: ArtifactIdNumber, component: &str, size: u64) {
805+
self.raw_ref()
806+
.execute(
807+
"insert or replace into artifact_size (aid, component, size)\
808+
values (?, ?, ?)",
809+
params![&artifact.0, &component, &size],
810+
)
811+
.unwrap();
812+
}
813+
794814
async fn get_bootstrap(&self, aids: &[ArtifactIdNumber]) -> Vec<Option<Duration>> {
795815
aids.iter()
796816
.map(|aid| {

0 commit comments

Comments
 (0)