7
7
// option. This file may not be copied, modified, or distributed
8
8
// except according to those terms.
9
9
10
- use std:: collections:: { HashMap , HashSet } ;
11
- use std:: env;
10
+ use std:: collections:: HashSet ;
12
11
use std:: fs;
13
- use std:: io:: Read ;
14
12
use std:: ops:: RangeInclusive ;
15
- use std:: path:: { Path , PathBuf } ;
13
+ use std:: path:: Path ;
16
14
17
15
use anyhow:: Context ;
18
16
use chrono:: { Duration , Utc } ;
19
17
use parking_lot:: Mutex ;
20
18
use serde:: { Deserialize , Serialize } ;
21
19
22
- use crate :: git;
23
20
use crate :: util;
24
21
use collector:: { Bound , Date } ;
25
22
26
23
use crate :: api:: github;
27
- use crate :: db:: ArtifactData ;
28
24
use collector;
29
25
pub use collector:: { BenchmarkName , Commit , Patch , Sha , StatId , Stats } ;
30
- use log:: { error, info, warn} ;
31
26
32
27
#[ derive( Debug , PartialEq , Eq , Clone , Serialize , Deserialize ) ]
33
28
pub enum MissingReason {
@@ -128,8 +123,6 @@ pub struct Config {
128
123
pub struct InputData {
129
124
pub commits : Vec < Commit > ,
130
125
131
- pub artifact_data : Vec < ArtifactData > ,
132
-
133
126
pub persistent : Mutex < Persistent > ,
134
127
135
128
pub config : Config ,
@@ -157,76 +150,7 @@ impl InputData {
157
150
}
158
151
159
152
/// 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 > {
230
154
let config = if let Ok ( s) = fs:: read_to_string ( "site-config.toml" ) {
231
155
toml:: from_str ( & s) ?
232
156
} else {
@@ -236,46 +160,14 @@ impl InputData {
236
160
}
237
161
} ;
238
162
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 ) ;
247
164
let index = crate :: db:: Index :: load ( & db) ;
248
165
let mut commits = index. commits ( ) ;
249
166
commits. sort ( ) ;
250
167
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
-
275
168
let persistent = Persistent :: load ( ) ;
276
169
Ok ( InputData {
277
170
commits,
278
- artifact_data,
279
171
persistent : Mutex :: new ( persistent) ,
280
172
config,
281
173
index,
0 commit comments