@@ -12,6 +12,7 @@ use std::env;
12
12
use std:: fmt;
13
13
use std:: fs:: { self , File } ;
14
14
use std:: hash;
15
+ use std:: io:: Read ;
15
16
use std:: path:: { Path , PathBuf } ;
16
17
use std:: process:: { self , Command , Stdio } ;
17
18
use std:: str;
@@ -642,42 +643,58 @@ impl Upload {
642
643
// Files are placed at
643
644
// * self-profile/<artifact id>/<krate>/<profile>/<cache>
644
645
// /self-profile-<collection-id>.{extension}
645
- let tarball = snap:: write:: FrameEncoder :: new ( Vec :: new ( ) ) ;
646
- let mut builder = tar:: Builder :: new ( tarball) ;
647
- builder. mode ( tar:: HeaderMode :: Deterministic ) ;
648
-
649
- let append_file =
650
- |builder : & mut tar:: Builder < _ > , file : & Path , name : & str | -> anyhow:: Result < ( ) > {
651
- if file. exists ( ) {
652
- // Silently ignore missing files, the new self-profile
653
- // experiment with one file has a different structure.
654
- builder. append_path_with_name ( file, name) ?;
655
- }
656
- Ok ( ( ) )
657
- } ;
658
- append_file (
659
- & mut builder,
660
- & files. string_index ,
661
- "self-profile.string_index" ,
662
- )
663
- . expect ( "append string index" ) ;
664
- append_file ( & mut builder, & files. string_data , "self-profile.string_data" )
665
- . expect ( "append string data" ) ;
666
- append_file ( & mut builder, & files. events , "self-profile.events" ) . expect ( "append events" ) ;
667
-
668
646
let upload = tempfile:: NamedTempFile :: new ( )
669
647
. context ( "create temporary file" )
670
648
. unwrap ( ) ;
671
- builder. finish ( ) . expect ( "complete tarball" ) ;
672
- std:: fs:: write (
673
- upload. path ( ) ,
674
- builder
675
- . into_inner ( )
676
- . expect ( "get" )
677
- . into_inner ( )
678
- . expect ( "snap success" ) ,
679
- )
680
- . expect ( "wrote tarball" ) ;
649
+ let filename = match files {
650
+ SelfProfileFiles :: Seven {
651
+ string_index,
652
+ string_data,
653
+ events,
654
+ } => {
655
+ let tarball = snap:: write:: FrameEncoder :: new ( Vec :: new ( ) ) ;
656
+ let mut builder = tar:: Builder :: new ( tarball) ;
657
+ builder. mode ( tar:: HeaderMode :: Deterministic ) ;
658
+
659
+ let append_file = |builder : & mut tar:: Builder < _ > ,
660
+ file : & Path ,
661
+ name : & str |
662
+ -> anyhow:: Result < ( ) > {
663
+ if file. exists ( ) {
664
+ // Silently ignore missing files, the new self-profile
665
+ // experiment with one file has a different structure.
666
+ builder. append_path_with_name ( file, name) ?;
667
+ }
668
+ Ok ( ( ) )
669
+ } ;
670
+
671
+ append_file ( & mut builder, & string_index, "self-profile.string_index" )
672
+ . expect ( "append string index" ) ;
673
+ append_file ( & mut builder, & string_data, "self-profile.string_data" )
674
+ . expect ( "append string data" ) ;
675
+ append_file ( & mut builder, & events, "self-profile.events" ) . expect ( "append events" ) ;
676
+ builder. finish ( ) . expect ( "complete tarball" ) ;
677
+ std:: fs:: write (
678
+ upload. path ( ) ,
679
+ builder
680
+ . into_inner ( )
681
+ . expect ( "get" )
682
+ . into_inner ( )
683
+ . expect ( "snap success" ) ,
684
+ )
685
+ . expect ( "wrote tarball" ) ;
686
+ format ! ( "self-profile-{}.tar.sz" , collection)
687
+ }
688
+ SelfProfileFiles :: Eight { file } => {
689
+ let data = std:: fs:: read ( & file) . expect ( "read profile data" ) ;
690
+ let mut data = snap:: read:: FrameEncoder :: new ( & data[ ..] ) ;
691
+ let mut compressed = Vec :: new ( ) ;
692
+ data. read_to_end ( & mut compressed) . expect ( "compressed" ) ;
693
+ std:: fs:: write ( upload. path ( ) , & compressed) . expect ( "write compressed profile data" ) ;
694
+
695
+ format ! ( "self-profile-{}.mm_profdata.sz" , collection)
696
+ }
697
+ } ;
681
698
682
699
let child = Command :: new ( "aws" )
683
700
. arg ( "s3" )
@@ -686,10 +703,7 @@ impl Upload {
686
703
. arg ( upload. path ( ) )
687
704
. arg ( & format ! (
688
705
"s3://rustc-perf/{}" ,
689
- & prefix
690
- . join( format!( "self-profile-{}.tar.sz" , collection) )
691
- . to_str( )
692
- . unwrap( )
706
+ & prefix. join( & filename) . to_str( ) . unwrap( )
693
707
) )
694
708
. spawn ( )
695
709
. expect ( "spawn aws" ) ;
@@ -1283,10 +1297,15 @@ enum DeserializeStatError {
1283
1297
ParseError ( String , #[ source] :: std:: num:: ParseFloatError ) ,
1284
1298
}
1285
1299
1286
- struct SelfProfileFiles {
1287
- string_data : PathBuf ,
1288
- string_index : PathBuf ,
1289
- events : PathBuf ,
1300
+ enum SelfProfileFiles {
1301
+ Seven {
1302
+ string_data : PathBuf ,
1303
+ string_index : PathBuf ,
1304
+ events : PathBuf ,
1305
+ } ,
1306
+ Eight {
1307
+ file : PathBuf ,
1308
+ } ,
1290
1309
}
1291
1310
1292
1311
fn process_perf_stat_output (
@@ -1298,6 +1317,7 @@ fn process_perf_stat_output(
1298
1317
let mut profile: Option < SelfProfile > = None ;
1299
1318
let mut dir: Option < PathBuf > = None ;
1300
1319
let mut prefix: Option < String > = None ;
1320
+ let mut file: Option < PathBuf > = None ;
1301
1321
for line in stdout. lines ( ) {
1302
1322
if line. starts_with ( "!self-profile-output:" ) {
1303
1323
profile = Some ( serde_json:: from_str ( & line[ "!self-profile-output:" . len ( ) ..] ) . unwrap ( ) ) ;
@@ -1311,6 +1331,10 @@ fn process_perf_stat_output(
1311
1331
prefix = Some ( String :: from ( & line[ "!self-profile-prefix:" . len ( ) ..] ) ) ;
1312
1332
continue ;
1313
1333
}
1334
+ if line. starts_with ( "!self-profile-file:" ) {
1335
+ file = Some ( PathBuf :: from ( & line[ "!self-profile-file:" . len ( ) ..] ) ) ;
1336
+ continue ;
1337
+ }
1314
1338
1315
1339
// github.com/torvalds/linux/blob/bc78d646e708/tools/perf/Documentation/perf-stat.txt#L281
1316
1340
macro_rules! get {
@@ -1347,29 +1371,32 @@ fn process_perf_stat_output(
1347
1371
}
1348
1372
1349
1373
let files = if let ( Some ( prefix) , Some ( dir) ) = ( prefix, dir) {
1350
- let mut files = SelfProfileFiles {
1351
- string_index : PathBuf :: new ( ) ,
1352
- string_data : PathBuf :: new ( ) ,
1353
- events : PathBuf :: new ( ) ,
1354
- } ;
1355
- // Rename the data files. There should be exactly three.
1374
+ let mut string_index = PathBuf :: new ( ) ;
1375
+ let mut string_data = PathBuf :: new ( ) ;
1376
+ let mut events = PathBuf :: new ( ) ;
1356
1377
for entry in fs:: read_dir ( & dir) . unwrap ( ) {
1357
1378
let filename = entry. unwrap ( ) . file_name ( ) ;
1358
1379
let filename_str = filename. to_str ( ) . unwrap ( ) ;
1359
1380
let path = dir. join ( filename_str) ;
1360
1381
if filename_str. ends_with ( ".events" ) {
1361
1382
assert ! ( filename_str. contains( & prefix) , "{:?}" , path) ;
1362
- files . events = path;
1383
+ events = path;
1363
1384
} else if filename_str. ends_with ( ".string_data" ) {
1364
1385
assert ! ( filename_str. contains( & prefix) , "{:?}" , path) ;
1365
- files . string_data = path;
1386
+ string_data = path;
1366
1387
} else if filename_str. ends_with ( ".string_index" ) {
1367
1388
assert ! ( filename_str. contains( & prefix) , "{:?}" , path) ;
1368
- files . string_index = path;
1389
+ string_index = path;
1369
1390
}
1370
1391
}
1371
1392
1372
- Some ( files)
1393
+ Some ( SelfProfileFiles :: Seven {
1394
+ string_index,
1395
+ string_data,
1396
+ events,
1397
+ } )
1398
+ } else if let Some ( file) = file {
1399
+ Some ( SelfProfileFiles :: Eight { file } )
1373
1400
} else {
1374
1401
None
1375
1402
} ;
0 commit comments