@@ -16,42 +16,80 @@ use crate::server::{Request, Response, ResponseHeaders};
16
16
17
17
pub async fn handle_self_profile_processed_download (
18
18
body : self_profile_raw:: Request ,
19
- params : HashMap < String , String > ,
19
+ mut params : HashMap < String , String > ,
20
20
ctxt : & SiteCtxt ,
21
21
) -> http:: Response < hyper:: Body > {
22
- let title = format ! (
23
- "{}: {} {}" ,
24
- & body. commit[ ..std:: cmp:: min( 7 , body. commit. len( ) ) ] ,
25
- body. benchmark,
26
- body. run_name
27
- ) ;
22
+ let diff_against = params. remove ( "base_commit" ) ;
23
+ if params
24
+ . get ( "type" )
25
+ . map_or ( false , |t| t != "codegen-schedule" )
26
+ && diff_against. is_some ( )
27
+ {
28
+ let mut resp = Response :: new ( "Only codegen_schedule supports diffing right now." . into ( ) ) ;
29
+ * resp. status_mut ( ) = StatusCode :: BAD_REQUEST ;
30
+ return resp;
31
+ }
32
+
33
+ let title = if let Some ( diff_against) = diff_against. as_ref ( ) {
34
+ format ! (
35
+ "{} vs {}: {} {}" ,
36
+ & diff_against[ ..std:: cmp:: min( 7 , diff_against. len( ) ) ] ,
37
+ & body. commit[ ..std:: cmp:: min( 7 , body. commit. len( ) ) ] ,
38
+ body. benchmark,
39
+ body. run_name
40
+ )
41
+ } else {
42
+ format ! (
43
+ "{}: {} {}" ,
44
+ & body. commit[ ..std:: cmp:: min( 7 , body. commit. len( ) ) ] ,
45
+ body. benchmark,
46
+ body. run_name
47
+ )
48
+ } ;
28
49
29
50
let start = Instant :: now ( ) ;
30
51
31
- let ( url, is_tarball) = match handle_self_profile_raw ( body, ctxt) . await {
32
- Ok ( v) => ( v. url , v. is_tarball ) ,
52
+ let base_data = if let Some ( diff_against) = diff_against {
53
+ match handle_self_profile_raw (
54
+ self_profile_raw:: Request {
55
+ commit : diff_against,
56
+ benchmark : body. benchmark . clone ( ) ,
57
+ run_name : body. run_name . clone ( ) ,
58
+ cid : None ,
59
+ } ,
60
+ ctxt,
61
+ )
62
+ . await
63
+ {
64
+ Ok ( v) => match get_self_profile_raw_data ( & v. url ) . await {
65
+ Ok ( v) => Some ( v) ,
66
+ Err ( e) => return e,
67
+ } ,
68
+ Err ( e) => {
69
+ let mut resp = Response :: new ( e. into ( ) ) ;
70
+ * resp. status_mut ( ) = StatusCode :: BAD_REQUEST ;
71
+ return resp;
72
+ }
73
+ }
74
+ } else {
75
+ None
76
+ } ;
77
+
78
+ let data = match handle_self_profile_raw ( body, ctxt) . await {
79
+ Ok ( v) => match get_self_profile_raw_data ( & v. url ) . await {
80
+ Ok ( v) => v,
81
+ Err ( e) => return e,
82
+ } ,
33
83
Err ( e) => {
34
84
let mut resp = Response :: new ( e. into ( ) ) ;
35
85
* resp. status_mut ( ) = StatusCode :: BAD_REQUEST ;
36
86
return resp;
37
87
}
38
88
} ;
39
89
40
- if is_tarball {
41
- let mut resp =
42
- Response :: new ( "Processing legacy format self-profile data is not supported" . into ( ) ) ;
43
- * resp. status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR ;
44
- return resp;
45
- }
46
-
47
- let data = match get_self_profile_raw_data ( & url) . await {
48
- Ok ( v) => v,
49
- Err ( e) => return e,
50
- } ;
51
-
52
90
log:: trace!( "got data in {:?}" , start. elapsed( ) ) ;
53
91
54
- let output = match crate :: self_profile:: generate ( & title, data, params) {
92
+ let output = match crate :: self_profile:: generate ( & title, base_data , data, params) {
55
93
Ok ( c) => c,
56
94
Err ( e) => {
57
95
log:: error!( "Failed to generate json {:?}" , e) ;
@@ -63,8 +101,12 @@ pub async fn handle_self_profile_processed_download(
63
101
let mut builder = http:: Response :: builder ( )
64
102
. header_typed ( if output. filename . ends_with ( "json" ) {
65
103
ContentType :: json ( )
66
- } else {
104
+ } else if output . filename . ends_with ( "svg" ) {
67
105
ContentType :: from ( "image/svg+xml" . parse :: < mime:: Mime > ( ) . unwrap ( ) )
106
+ } else if output. filename . ends_with ( "html" ) {
107
+ ContentType :: html ( )
108
+ } else {
109
+ unreachable ! ( )
68
110
} )
69
111
. status ( StatusCode :: OK ) ;
70
112
@@ -257,6 +299,7 @@ fn sort_self_profile(
257
299
async fn get_self_profile_raw_data ( url : & str ) -> Result < Vec < u8 > , Response > {
258
300
log:: trace!( "downloading {}" , url) ;
259
301
302
+ let start = Instant :: now ( ) ;
260
303
let resp = match reqwest:: get ( url) . await {
261
304
Ok ( r) => r,
262
305
Err ( e) => {
@@ -283,6 +326,12 @@ async fn get_self_profile_raw_data(url: &str) -> Result<Vec<u8>, Response> {
283
326
}
284
327
} ;
285
328
329
+ log:: trace!(
330
+ "downloaded {} bytes in {:?}" ,
331
+ compressed. len( ) ,
332
+ start. elapsed( )
333
+ ) ;
334
+
286
335
let mut data = Vec :: new ( ) ;
287
336
288
337
match snap:: read:: FrameDecoder :: new ( compressed. reader ( ) ) . read_to_end ( & mut data) {
@@ -462,7 +511,7 @@ pub async fn handle_self_profile_raw(
462
511
let aids_and_cids = conn
463
512
. list_self_profile (
464
513
ArtifactId :: Commit ( database:: Commit {
465
- sha : body. commit ,
514
+ sha : body. commit . clone ( ) ,
466
515
date : database:: Date :: empty ( ) ,
467
516
} ) ,
468
517
bench_name,
@@ -473,7 +522,7 @@ pub async fn handle_self_profile_raw(
473
522
let ( aid, first_cid) = aids_and_cids
474
523
. first ( )
475
524
. copied ( )
476
- . ok_or_else ( || format ! ( "No results for this commit" ) ) ?;
525
+ . ok_or_else ( || format ! ( "No results for {}" , body . commit) ) ?;
477
526
478
527
let cid = match body. cid {
479
528
Some ( cid) => {
@@ -500,27 +549,15 @@ pub async fn handle_self_profile_raw(
500
549
. map ( |( _, cid) | cid)
501
550
. collect :: < Vec < _ > > ( ) ;
502
551
503
- return match fetch ( & cids, cid, format ! ( "{}.mm_profdata.sz" , url_prefix) , false ) . await {
552
+ return match fetch ( & cids, cid, format ! ( "{}.mm_profdata.sz" , url_prefix) ) . await {
504
553
Ok ( fetched) => Ok ( fetched) ,
505
- Err ( new_error) => {
506
- match fetch ( & cids, cid, format ! ( "{}.tar.sz" , url_prefix) , true ) . await {
507
- Ok ( fetched) => Ok ( fetched) ,
508
- Err ( old_error) => {
509
- // Both files failed to fetch; return the errors for both:
510
- Err ( format ! (
511
- "mm_profdata download failed: {:?}, tarball download failed: {:?}" ,
512
- new_error, old_error
513
- ) )
514
- }
515
- }
516
- }
554
+ Err ( new_error) => Err ( format ! ( "mm_profdata download failed: {:?}" , new_error, ) ) ,
517
555
} ;
518
556
519
557
async fn fetch (
520
558
cids : & [ i32 ] ,
521
559
cid : i32 ,
522
560
url : String ,
523
- is_tarball : bool ,
524
561
) -> ServerResult < self_profile_raw:: Response > {
525
562
let resp = reqwest:: Client :: new ( )
526
563
. head ( & url)
@@ -538,7 +575,7 @@ pub async fn handle_self_profile_raw(
538
575
cids : cids. to_vec ( ) ,
539
576
cid,
540
577
url,
541
- is_tarball,
578
+ is_tarball : false ,
542
579
} )
543
580
}
544
581
}
0 commit comments