Skip to content

Commit 1545886

Browse files
Stop loading artifact data
1 parent 9df9e53 commit 1545886

File tree

3 files changed

+48
-131
lines changed

3 files changed

+48
-131
lines changed

site/src/db.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ impl Index {
748748
.map(|slice| T::from_bytes(&slice))
749749
}
750750

751+
pub fn artifacts(&self) -> impl Iterator<Item = &'_ str> + '_ {
752+
self.artifacts.map.keys().map(|s| &**s)
753+
}
754+
751755
pub fn commits(&self) -> Vec<Commit> {
752756
self.commits.map.keys().copied().collect()
753757
}

site/src/load.rs

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,22 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
use std::collections::{HashMap, HashSet};
11-
use std::env;
10+
use std::collections::HashSet;
1211
use std::fs;
13-
use std::io::Read;
1412
use std::ops::RangeInclusive;
15-
use std::path::{Path, PathBuf};
13+
use std::path::Path;
1614

1715
use anyhow::Context;
1816
use chrono::{Duration, Utc};
1917
use parking_lot::Mutex;
2018
use serde::{Deserialize, Serialize};
2119

22-
use crate::git;
2320
use crate::util;
2421
use collector::{Bound, Date};
2522

2623
use crate::api::github;
27-
use crate::db::ArtifactData;
2824
use collector;
2925
pub use collector::{BenchmarkName, Commit, Patch, Sha, StatId, Stats};
30-
use log::{error, info, warn};
3126

3227
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
3328
pub enum MissingReason {
@@ -128,8 +123,6 @@ pub struct Config {
128123
pub struct InputData {
129124
pub commits: Vec<Commit>,
130125

131-
pub artifact_data: Vec<ArtifactData>,
132-
133126
pub persistent: Mutex<Persistent>,
134127

135128
pub config: Config,
@@ -157,76 +150,7 @@ impl InputData {
157150
}
158151

159152
/// Initialize `InputData from the file system.
160-
pub fn from_fs(repo_loc: &str) -> anyhow::Result<InputData> {
161-
let repo_loc = PathBuf::from(repo_loc);
162-
let mut artifact_data = HashMap::new();
163-
164-
if !repo_loc.exists() {
165-
// If the repository doesn't yet exist, simplify clone it to the given location.
166-
info!(
167-
"cloning repository into {}, since it doesn't exist before",
168-
repo_loc.display()
169-
);
170-
git::execute_command(
171-
&env::current_dir()?,
172-
&[
173-
"clone",
174-
"https://github.com/rust-lang/rustc-timing.git",
175-
repo_loc.to_str().unwrap(),
176-
],
177-
)?;
178-
}
179-
180-
eprintln!("Loading files from directory...");
181-
182-
// Read all files from repo_loc/processed
183-
let latest_section_start = std::time::Instant::now();
184-
let mut file_contents = Vec::new();
185-
for entry in fs::read_dir(repo_loc.join("times"))? {
186-
let entry = entry?;
187-
if entry.file_type()?.is_dir() {
188-
continue;
189-
}
190-
let filename = entry.file_name();
191-
let filename = filename.to_str().unwrap();
192-
if filename.starts_with("artifact-") {
193-
let mut file = fs::File::open(entry.path())
194-
.with_context(|| format!("Failed to open {}", entry.path().display()))?;
195-
file_contents.truncate(0);
196-
if filename.ends_with(".sz") {
197-
let mut szip_reader =
198-
snap::read::FrameDecoder::new(std::io::BufReader::new(file));
199-
szip_reader
200-
.read_to_end(&mut file_contents)
201-
.with_context(|| format!("Failed to read {}", entry.path().display()))?;
202-
} else {
203-
file.read_to_end(&mut file_contents)
204-
.with_context(|| format!("Failed to read {}", entry.path().display()))?;
205-
};
206-
let file_contents = std::str::from_utf8(&file_contents).unwrap();
207-
208-
let contents: ArtifactData = match serde_json::from_str(&file_contents) {
209-
Ok(j) => j,
210-
Err(err) => {
211-
error!("Failed to parse JSON for {}: {:?}", filename, err);
212-
continue;
213-
}
214-
};
215-
if contents.benchmarks.is_empty() {
216-
warn!("empty benchmarks hash for {}", filename);
217-
continue;
218-
}
219-
220-
artifact_data.insert(contents.id.clone(), contents);
221-
}
222-
}
223-
std::mem::drop(file_contents);
224-
225-
eprintln!(
226-
"Done loading files from disk in {:?}",
227-
latest_section_start.elapsed()
228-
);
229-
153+
pub fn from_fs(db: &str) -> anyhow::Result<InputData> {
230154
let config = if let Ok(s) = fs::read_to_string("site-config.toml") {
231155
toml::from_str(&s)?
232156
} else {
@@ -236,46 +160,14 @@ impl InputData {
236160
}
237161
};
238162

239-
InputData::new(artifact_data, config)
240-
}
241-
242-
pub fn new(
243-
mut artifact_data: HashMap<String, ArtifactData>,
244-
config: Config,
245-
) -> anyhow::Result<InputData> {
246-
let db = crate::db::open("data", false);
163+
let db = crate::db::open(db, false);
247164
let index = crate::db::Index::load(&db);
248165
let mut commits = index.commits();
249166
commits.sort();
250167

251-
let mut versions = artifact_data.keys().cloned().collect::<Vec<_>>();
252-
versions.sort_by(|a, b| {
253-
match (
254-
a.parse::<semver::Version>().ok(),
255-
b.parse::<semver::Version>().ok(),
256-
) {
257-
(Some(a), Some(b)) => a.cmp(&b),
258-
(_, _) => {
259-
if a == "beta" {
260-
std::cmp::Ordering::Greater
261-
} else if b == "beta" {
262-
std::cmp::Ordering::Less
263-
} else {
264-
panic!("unexpected version")
265-
}
266-
}
267-
}
268-
});
269-
270-
let artifact_data = versions
271-
.into_iter()
272-
.map(|v| artifact_data.remove(&v).unwrap())
273-
.collect::<Vec<_>>();
274-
275168
let persistent = Persistent::load();
276169
Ok(InputData {
277170
commits,
278-
artifact_data,
279171
persistent: Mutex::new(persistent),
280172
config,
281173
index,

site/src/server.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,68 @@ pub fn handle_info(data: &InputData) -> info::Response {
6565
}
6666

6767
pub fn handle_dashboard(data: &InputData) -> dashboard::Response {
68-
if data.artifact_data.is_empty() {
68+
if data.index.artifacts().next().is_none() {
6969
return dashboard::Response::default();
7070
}
7171

72-
let benchmark_names = data
73-
.artifact_data
74-
.iter()
75-
.find(|ad| ad.id == "beta")
76-
.unwrap()
77-
.benchmarks
78-
.iter()
79-
.filter(|(_, v)| v.is_ok())
80-
.map(|(k, _)| *k)
81-
.collect::<Vec<_>>();
72+
let mut versions = data.index.artifacts().collect::<Vec<_>>();
73+
versions.sort_by(|a, b| {
74+
match (
75+
a.parse::<semver::Version>().ok(),
76+
b.parse::<semver::Version>().ok(),
77+
) {
78+
(Some(a), Some(b)) => a.cmp(&b),
79+
(_, _) => {
80+
if *a == "beta" {
81+
std::cmp::Ordering::Greater
82+
} else if *b == "beta" {
83+
std::cmp::Ordering::Less
84+
} else {
85+
panic!("unexpected version")
86+
}
87+
}
88+
}
89+
});
8290

8391
let cids = Arc::new(
84-
data.artifact_data
85-
.iter()
86-
.map(|ad| db::CollectionId::Artifact(ad.id.clone()))
92+
versions
93+
.into_iter()
94+
.map(|v| db::CollectionId::Artifact(v.to_string()))
8795
.chain(std::iter::once(data.commits.last().unwrap().clone().into()))
8896
.collect::<Vec<_>>(),
8997
);
9098

9199
let query = selector::Query::new()
92-
.set(Tag::Crate, selector::Selector::Subset(benchmark_names))
100+
// FIXME: don't hardcode the stabilized benchmarks
101+
// This list was found via:
102+
// `rg supports.stable collector/benchmarks/ -tjson -c --sort path`
103+
.set(
104+
Tag::Crate,
105+
selector::Selector::Subset(vec![
106+
"encoding",
107+
"futures",
108+
"html5ever",
109+
"inflate",
110+
"piston-image",
111+
"regex",
112+
"style-servo",
113+
"syn",
114+
"tokio-webpush-simple",
115+
]),
116+
)
93117
.set(
94118
Tag::ProcessStatistic,
95119
selector::Selector::One(StatId::WallTime.as_str()),
96120
);
97121

98122
let summary_patches = data.summary_patches();
99123
let by_profile = db::ByProfile::new::<String, _>(|profile| {
100-
let query = query
101-
.clone()
102-
.set(Tag::Profile, selector::Selector::One(profile));
103-
104124
let mut cases = dashboard::Cases::default();
105125
for patch in summary_patches.iter() {
106126
let responses = data.query::<Option<f64>>(
107127
query
108128
.clone()
129+
.set(Tag::Profile, selector::Selector::One(profile))
109130
.set(Tag::Cache, selector::Selector::One(patch)),
110131
cids.clone(),
111132
)?;

0 commit comments

Comments
 (0)