1
- use std:: collections:: { HashMap , HashSet } ;
1
+ use std:: collections:: HashSet ;
2
2
use std:: io:: Read ;
3
3
use std:: sync:: Arc ;
4
4
use std:: time:: { Duration , Instant } ;
5
5
6
6
use bytes:: Buf ;
7
7
use headers:: { ContentType , Header } ;
8
8
use hyper:: StatusCode ;
9
- use log:: error;
10
9
11
- use crate :: api:: { self_profile, self_profile_raw, ServerResult } ;
10
+ use crate :: api:: { self_profile, self_profile_processed , self_profile_raw, ServerResult } ;
12
11
use crate :: db:: ArtifactId ;
13
12
use crate :: load:: SiteCtxt ;
14
13
use crate :: selector:: { self , Tag } ;
15
- use crate :: server:: { Request , Response , ResponseHeaders } ;
14
+ use crate :: server:: { Response , ResponseHeaders } ;
16
15
17
16
pub async fn handle_self_profile_processed_download (
18
- body : self_profile_raw:: Request ,
19
- mut params : HashMap < String , String > ,
17
+ body : self_profile_processed:: Request ,
20
18
ctxt : & SiteCtxt ,
21
19
) -> http:: Response < hyper:: Body > {
20
+ log:: info!( "handle_self_profile_processed_download({:?})" , body) ;
21
+ let mut params = body. params . clone ( ) ;
22
22
let diff_against = params. remove ( "base_commit" ) ;
23
- if params
24
- . get ( "type" )
25
- . map_or ( false , |t| t != "codegen-schedule" )
23
+
24
+ if body. processor_type != self_profile_processed:: ProcessorType :: CodegenSchedule
26
25
&& diff_against. is_some ( )
27
26
{
28
- let mut resp = Response :: new ( "Only codegen_schedule supports diffing right now." . into ( ) ) ;
27
+ let mut resp = Response :: new ( "Only codegen-schedule supports diffing right now." . into ( ) ) ;
29
28
* resp. status_mut ( ) = StatusCode :: BAD_REQUEST ;
30
29
return resp;
31
30
}
@@ -75,7 +74,17 @@ pub async fn handle_self_profile_processed_download(
75
74
None
76
75
} ;
77
76
78
- let data = match handle_self_profile_raw ( body, ctxt) . await {
77
+ let data = match handle_self_profile_raw (
78
+ self_profile_raw:: Request {
79
+ commit : body. commit ,
80
+ benchmark : body. benchmark . clone ( ) ,
81
+ run_name : body. run_name . clone ( ) ,
82
+ cid : body. cid ,
83
+ } ,
84
+ ctxt,
85
+ )
86
+ . await
87
+ {
79
88
Ok ( v) => match get_self_profile_raw_data ( & v. url ) . await {
80
89
Ok ( v) => v,
81
90
Err ( e) => return e,
@@ -89,15 +98,16 @@ pub async fn handle_self_profile_processed_download(
89
98
90
99
log:: trace!( "got data in {:?}" , start. elapsed( ) ) ;
91
100
92
- let output = match crate :: self_profile:: generate ( & title, base_data, data, params) {
93
- Ok ( c) => c,
94
- Err ( e) => {
95
- log:: error!( "Failed to generate json {:?}" , e) ;
96
- let mut resp = http:: Response :: new ( format ! ( "{:?}" , e) . into ( ) ) ;
97
- * resp. status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR ;
98
- return resp;
99
- }
100
- } ;
101
+ let output =
102
+ match crate :: self_profile:: generate ( & title, body. processor_type , base_data, data, params) {
103
+ Ok ( c) => c,
104
+ Err ( e) => {
105
+ log:: error!( "Failed to generate json {:?}" , e) ;
106
+ let mut resp = http:: Response :: new ( format ! ( "{:?}" , e) . into ( ) ) ;
107
+ * resp. status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR ;
108
+ return resp;
109
+ }
110
+ } ;
101
111
let mut builder = http:: Response :: builder ( )
102
112
. header_typed ( if output. filename . ends_with ( "json" ) {
103
113
ContentType :: json ( )
@@ -390,9 +400,9 @@ pub async fn handle_self_profile_raw_download(
390
400
body : self_profile_raw:: Request ,
391
401
ctxt : & SiteCtxt ,
392
402
) -> http:: Response < hyper:: Body > {
393
- let res = handle_self_profile_raw ( body , ctxt ) . await ;
394
- let ( url, is_tarball ) = match res {
395
- Ok ( v) => ( v. url , v . is_tarball ) ,
403
+ log :: info! ( "handle_self_profile_raw_download({:?})" , body ) ;
404
+ let url = match handle_self_profile_raw ( body , ctxt ) . await {
405
+ Ok ( v) => v. url ,
396
406
Err ( e) => {
397
407
let mut resp = http:: Response :: new ( e. into ( ) ) ;
398
408
* resp. status_mut ( ) = StatusCode :: BAD_REQUEST ;
@@ -427,75 +437,16 @@ pub async fn handle_self_profile_raw_download(
427
437
. insert ( hyper:: header:: CONTENT_TYPE , header. pop ( ) . unwrap ( ) ) ;
428
438
server_resp. headers_mut ( ) . insert (
429
439
hyper:: header:: CONTENT_DISPOSITION ,
430
- hyper:: header:: HeaderValue :: from_maybe_shared ( format ! (
431
- "attachment; filename=\" {}\" " ,
432
- if is_tarball {
433
- "self-profile.tar"
434
- } else {
435
- "self-profile.mm_profdata"
436
- }
437
- ) )
440
+ hyper:: header:: HeaderValue :: from_maybe_shared (
441
+ "attachment; filename=\" self-profile.mm_profdata\" " ,
442
+ )
438
443
. expect ( "valid header" ) ,
439
444
) ;
440
445
* server_resp. status_mut ( ) = StatusCode :: OK ;
441
446
tokio:: spawn ( tarball ( resp, sender) ) ;
442
447
server_resp
443
448
}
444
449
445
- pub fn get_self_profile_raw (
446
- req : & Request ,
447
- ) -> Result < ( HashMap < String , String > , self_profile_raw:: Request ) , http:: Response < hyper:: Body > > {
448
- // FIXME: how should this look?
449
- let url = match url:: Url :: parse ( & format ! ( "http://example.com{}" , req. uri( ) ) ) {
450
- Ok ( v) => v,
451
- Err ( e) => {
452
- error ! ( "failed to parse url {}: {:?}" , req. uri( ) , e) ;
453
- return Err ( http:: Response :: builder ( )
454
- . header_typed ( ContentType :: text_utf8 ( ) )
455
- . status ( StatusCode :: BAD_REQUEST )
456
- . body ( hyper:: Body :: from ( format ! (
457
- "failed to parse url {}: {:?}" ,
458
- req. uri( ) ,
459
- e
460
- ) ) )
461
- . unwrap ( ) ) ;
462
- }
463
- } ;
464
- let mut parts = url
465
- . query_pairs ( )
466
- . into_owned ( )
467
- . collect :: < HashMap < String , String > > ( ) ;
468
- macro_rules! key_or_error {
469
- ( $ident: ident) => {
470
- if let Some ( v) = parts. remove( stringify!( $ident) ) {
471
- v
472
- } else {
473
- error!(
474
- "failed to deserialize request {}: missing {} in query string" ,
475
- req. uri( ) ,
476
- stringify!( $ident)
477
- ) ;
478
- return Err ( http:: Response :: builder( )
479
- . header_typed( ContentType :: text_utf8( ) )
480
- . status( StatusCode :: BAD_REQUEST )
481
- . body( hyper:: Body :: from( format!(
482
- "failed to deserialize request {}: missing {} in query string" ,
483
- req. uri( ) ,
484
- stringify!( $ident)
485
- ) ) )
486
- . unwrap( ) ) ;
487
- }
488
- } ;
489
- }
490
- let request = self_profile_raw:: Request {
491
- commit : key_or_error ! ( commit) ,
492
- benchmark : key_or_error ! ( benchmark) ,
493
- run_name : key_or_error ! ( run_name) ,
494
- cid : None ,
495
- } ;
496
- return Ok ( ( parts, request) ) ;
497
- }
498
-
499
450
async fn tarball ( resp : reqwest:: Response , mut sender : hyper:: body:: Sender ) {
500
451
// Ideally, we would stream the response though the snappy decoding, but
501
452
// snappy doesn't support that AFAICT -- we'd need it to implement AsyncRead
@@ -615,7 +566,6 @@ pub async fn handle_self_profile_raw(
615
566
cids : cids. to_vec ( ) ,
616
567
cid,
617
568
url,
618
- is_tarball : false ,
619
569
} )
620
570
}
621
571
}
0 commit comments