Skip to content

Commit 2132441

Browse files
authored
Merge pull request #895 from rylev/add-docs1
Add some basic docs
2 parents c648f39 + a038e11 commit 2132441

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

collector/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,33 @@ pub use self_profile::{QueryData, SelfProfile};
1616
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Deserialize)]
1717
pub struct DeltaTime(#[serde(with = "round_float")] pub f64);
1818

19+
/// The bound of a range changes in codebase
20+
///
21+
/// This can either be the upper or lower bound
1922
#[derive(Debug, Clone, PartialEq, Eq)]
2023
pub enum Bound {
21-
// sha, unverified
24+
/// An unverified git commit (in sha form)
2225
Commit(String),
26+
/// A date in time
2327
Date(NaiveDate),
28+
/// No bound
2429
None,
2530
}
2631

2732
impl Bound {
33+
/// Tests whether self bounds the commit to the left
2834
pub fn left_match(&self, commit: &Commit) -> bool {
29-
let last_month = chrono::Utc::now().date().naive_utc() - chrono::Duration::days(30);
3035
match self {
3136
Bound::Commit(sha) => commit.sha == **sha,
3237
Bound::Date(date) => commit.date.0.naive_utc().date() >= *date,
33-
Bound::None => last_month <= commit.date.0.naive_utc().date(),
38+
Bound::None => {
39+
let last_month = chrono::Utc::now().date().naive_utc() - chrono::Duration::days(30);
40+
last_month <= commit.date.0.naive_utc().date()
41+
}
3442
}
3543
}
3644

45+
/// Tests whether self bounds the commit to the right
3746
pub fn right_match(&self, commit: &Commit) -> bool {
3847
match self {
3948
Bound::Commit(sha) => commit.sha == **sha,

database/src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,18 @@ impl Ord for Commit {
189189
}
190190
}
191191

192+
/// The compilation profile (i.e., how the crate was built)
192193
#[derive(
193194
Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
194195
)]
195196
pub enum Profile {
197+
/// A checked build (i.e., no codegen)
196198
Check,
199+
/// A debug build (i.e., low optimizations)
197200
Debug,
201+
/// A doc build
198202
Doc,
203+
/// An optimized "release" build
199204
Opt,
200205
}
201206

@@ -227,15 +232,23 @@ impl fmt::Display for Profile {
227232
}
228233
}
229234

235+
/// The incremental cache state
236+
///
237+
/// These are usually reported to users in a "flipped" way. For example,
238+
/// `Cache::Empty` means we're doing a "full" build. We present this to users as "full".
230239
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
231240
#[serde(tag = "variant", content = "name")]
232241
pub enum Cache {
242+
/// Empty cache (i.e., full build)
233243
#[serde(rename = "full")]
234244
Empty,
245+
/// Empty cache but still incremental (i.e., a full incremental build)
235246
#[serde(rename = "incr-full")]
236247
IncrementalEmpty,
248+
/// Cache is fully up-to-date (i.e., nothing has changed)
237249
#[serde(rename = "incr-unchanged")]
238250
IncrementalFresh,
251+
/// Cache is mostly up-to-date but something has been changed
239252
#[serde(rename = "incr-patched")]
240253
IncrementalPatch(PatchName),
241254
}
@@ -378,9 +391,12 @@ pub enum Label {
378391
Query(QueryLabel),
379392
}
380393

394+
/// An identifier for a built version of the compiler
381395
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
382396
pub enum ArtifactId {
397+
/// A built version of the compiler at an exact commit
383398
Commit(Commit),
399+
/// A symbolic tag for a built compiler like "1.51.0"
384400
Artifact(String),
385401
}
386402

@@ -434,16 +450,26 @@ pub struct LabelId(pub u8, pub u32);
434450
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
435451
pub struct ArtifactIdNumber(pub u32);
436452

453+
/// Id lookups for various things
454+
///
455+
/// This is a quick way to find what the database id for something
437456
#[derive(Debug, Clone, PartialEq, Eq, Default)]
438457
pub struct Index {
458+
/// Id look for a commit
439459
commits: Indexed<Commit>,
460+
/// Id lookup of the errors for a crate
440461
artifacts: Indexed<Box<str>>,
441-
462+
/// Id lookup of the errors for a crate
442463
errors: Indexed<Crate>,
464+
/// Id lookup of a given process stastic profile
443465
pstats: Indexed<(Crate, Profile, Cache, ProcessStatistic)>,
466+
/// Id lookup of a given process query label
444467
queries: Indexed<(Crate, Profile, Cache, QueryLabel)>,
445468
}
446469

470+
/// An index lookup
471+
///
472+
/// Given a `T` find what its database id is
447473
#[derive(Debug, Clone, Serialize, Deserialize)]
448474
struct Indexed<T> {
449475
#[serde(with = "index_serde")]

site/src/comparison.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,17 @@ pub async fn compare_given_commits(
237237
Some(b) => b,
238238
None => return Ok(None),
239239
};
240-
let cids = Arc::new(vec![a.clone().into(), b.clone().into()]);
240+
let cids = Arc::new(vec![a.clone(), b.clone()]);
241241

242+
// get all crates, cache, and profile combinations for the given stat
242243
let query = selector::Query::new()
243244
.set::<String>(Tag::Crate, selector::Selector::All)
244245
.set::<String>(Tag::Cache, selector::Selector::All)
245246
.set::<String>(Tag::Profile, selector::Selector::All)
246247
.set(Tag::ProcessStatistic, selector::Selector::One(stat.clone()));
247248

249+
// `responses` contains a series iterators. The first element in the iterator is the data
250+
// for `a` and the second is the data for `b`
248251
let mut responses = data.query::<Option<f64>>(query, cids).await?;
249252

250253
let conn = data.conn().await;
@@ -257,18 +260,30 @@ pub async fn compare_given_commits(
257260
}))
258261
}
259262

260-
/// Data associated with a specific date
263+
/// Data associated with a specific artifact
261264
#[derive(Debug, Clone, Serialize)]
262265
pub struct DateData {
266+
/// The artifact in question
267+
pub commit: String,
268+
/// The date of the artifact if known
263269
pub date: Option<Date>,
270+
/// The pr of the artifact if known
264271
pub pr: Option<u32>,
265-
pub commit: String,
272+
/// Benchmark data in the form "$crate-$profile" -> Vec<("$cache", nanoseconds)>
273+
///
274+
/// * $profile refers to the flavor of compilation like debug, doc, opt(timized), etc.
275+
/// * $cache refers to how much of the compilation must be done and how much is cached
276+
/// (e.g., "incr-unchanged" == compiling with full incremental cache and no code having changed)
266277
pub data: HashMap<String, Vec<(String, f64)>>,
267-
// crate -> nanoseconds
278+
/// Bootstrap data in the form "$crate" -> nanoseconds
268279
pub bootstrap: HashMap<String, u64>,
269280
}
270281

271282
impl DateData {
283+
/// For the given `ArtifactId`, consume the first datapoint in each of the given `SeriesResponse`
284+
///
285+
/// It is assumed that the provided ArtifactId is the same as artifact id returned as the next data
286+
/// point from all of the series `SeriesResponse`s. If this is not true, this function will panic.
272287
async fn consume_one<'a, T>(
273288
conn: &dyn database::Connection,
274289
commit: ArtifactId,

site/src/load.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,32 @@ impl TryCommit {
6464
}
6565
}
6666

67+
/// Keys for accessing various services
68+
///
69+
/// At the moment only used for accessing GitHub
6770
#[derive(Debug, Default, Deserialize)]
6871
pub struct Keys {
72+
/// GitHub API token from the `GITHUB_API_TOKEN` env variable
6973
pub github: Option<String>,
74+
/// GitHub webhook secret from the `GITHUB_WEBHOOK_SECRET` env variable
7075
pub secret: Option<String>,
7176
}
7277

78+
/// Site configuration
7379
#[derive(Debug, Deserialize)]
7480
pub struct Config {
7581
pub keys: Keys,
7682
}
7783

84+
/// Site context object that contains global data
7885
pub struct InputData {
86+
/// Site configuration
7987
pub config: Config,
80-
88+
/// Cached site landing page
8189
pub landing_page: ArcSwap<Option<Arc<crate::api::graph::Response>>>,
82-
90+
/// Index of various common queries
8391
pub index: ArcSwap<crate::db::Index>,
92+
/// Database connection pool
8493
pub pool: Pool,
8594
}
8695

site/src/selector.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,26 @@ use std::fmt;
3333
use std::ops::RangeInclusive;
3434
use std::sync::Arc;
3535

36-
pub fn data_for(data: &Index, is_left: bool, query: Bound) -> Option<ArtifactId> {
36+
/// Finds the most appropriate `ArtifactId` for a given bound.
37+
///
38+
/// Searches the commits in the index either from the left or the right.
39+
/// If not found in those commits, searches through the artifacts in the index.
40+
pub fn data_for(data: &Index, is_left: bool, bound: Bound) -> Option<ArtifactId> {
3741
let commits = data.commits();
3842
let commit = if is_left {
3943
commits
4044
.iter()
41-
.find(|commit| query.left_match(commit))
45+
.find(|commit| bound.left_match(commit))
4246
.cloned()
4347
} else {
4448
commits
4549
.iter()
46-
.rfind(|commit| query.left_match(commit))
50+
.rfind(|commit| bound.left_match(commit))
4751
.cloned()
4852
};
4953
commit.map(|c| ArtifactId::Commit(c)).or_else(|| {
5054
data.artifacts()
51-
.find(|aid| match &query {
55+
.find(|aid| match &bound {
5256
Bound::Commit(c) => *c == **aid,
5357
Bound::Date(_) => false,
5458
Bound::None => false,

0 commit comments

Comments
 (0)