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
+ let mut params = body. params . clone ( ) ;
22
21
let diff_against = params. remove ( "base_commit" ) ;
23
- if params
24
- . get ( "type" )
25
- . map_or ( false , |t| t != "codegen-schedule" )
22
+
23
+ if body. processor_type != self_profile_processed:: ProcessorType :: CodegenSchedule
26
24
&& diff_against. is_some ( )
27
25
{
28
- let mut resp = Response :: new ( "Only codegen_schedule supports diffing right now." . into ( ) ) ;
26
+ let mut resp = Response :: new ( "Only codegen-schedule supports diffing right now." . into ( ) ) ;
29
27
* resp. status_mut ( ) = StatusCode :: BAD_REQUEST ;
30
28
return resp;
31
29
}
@@ -75,7 +73,17 @@ pub async fn handle_self_profile_processed_download(
75
73
None
76
74
} ;
77
75
78
- let data = match handle_self_profile_raw ( body, ctxt) . await {
76
+ let data = match handle_self_profile_raw (
77
+ self_profile_raw:: Request {
78
+ commit : body. commit ,
79
+ benchmark : body. benchmark . clone ( ) ,
80
+ run_name : body. run_name . clone ( ) ,
81
+ cid : body. cid ,
82
+ } ,
83
+ ctxt,
84
+ )
85
+ . await
86
+ {
79
87
Ok ( v) => match get_self_profile_raw_data ( & v. url ) . await {
80
88
Ok ( v) => v,
81
89
Err ( e) => return e,
@@ -89,15 +97,16 @@ pub async fn handle_self_profile_processed_download(
89
97
90
98
log:: trace!( "got data in {:?}" , start. elapsed( ) ) ;
91
99
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
- } ;
100
+ let output =
101
+ match crate :: self_profile:: generate ( & title, body. processor_type , base_data, data, params) {
102
+ Ok ( c) => c,
103
+ Err ( e) => {
104
+ log:: error!( "Failed to generate json {:?}" , e) ;
105
+ let mut resp = http:: Response :: new ( format ! ( "{:?}" , e) . into ( ) ) ;
106
+ * resp. status_mut ( ) = StatusCode :: INTERNAL_SERVER_ERROR ;
107
+ return resp;
108
+ }
109
+ } ;
101
110
let mut builder = http:: Response :: builder ( )
102
111
. header_typed ( if output. filename . ends_with ( "json" ) {
103
112
ContentType :: json ( )
@@ -436,60 +445,6 @@ pub async fn handle_self_profile_raw_download(
436
445
server_resp
437
446
}
438
447
439
- pub fn get_self_profile_raw (
440
- req : & Request ,
441
- ) -> Result < ( HashMap < String , String > , self_profile_raw:: Request ) , http:: Response < hyper:: Body > > {
442
- // FIXME: how should this look?
443
- let url = match url:: Url :: parse ( & format ! ( "http://example.com{}" , req. uri( ) ) ) {
444
- Ok ( v) => v,
445
- Err ( e) => {
446
- error ! ( "failed to parse url {}: {:?}" , req. uri( ) , e) ;
447
- return Err ( http:: Response :: builder ( )
448
- . header_typed ( ContentType :: text_utf8 ( ) )
449
- . status ( StatusCode :: BAD_REQUEST )
450
- . body ( hyper:: Body :: from ( format ! (
451
- "failed to parse url {}: {:?}" ,
452
- req. uri( ) ,
453
- e
454
- ) ) )
455
- . unwrap ( ) ) ;
456
- }
457
- } ;
458
- let mut parts = url
459
- . query_pairs ( )
460
- . into_owned ( )
461
- . collect :: < HashMap < String , String > > ( ) ;
462
- macro_rules! key_or_error {
463
- ( $ident: ident) => {
464
- if let Some ( v) = parts. remove( stringify!( $ident) ) {
465
- v
466
- } else {
467
- error!(
468
- "failed to deserialize request {}: missing {} in query string" ,
469
- req. uri( ) ,
470
- stringify!( $ident)
471
- ) ;
472
- return Err ( http:: Response :: builder( )
473
- . header_typed( ContentType :: text_utf8( ) )
474
- . status( StatusCode :: BAD_REQUEST )
475
- . body( hyper:: Body :: from( format!(
476
- "failed to deserialize request {}: missing {} in query string" ,
477
- req. uri( ) ,
478
- stringify!( $ident)
479
- ) ) )
480
- . unwrap( ) ) ;
481
- }
482
- } ;
483
- }
484
- let request = self_profile_raw:: Request {
485
- commit : key_or_error ! ( commit) ,
486
- benchmark : key_or_error ! ( benchmark) ,
487
- run_name : key_or_error ! ( run_name) ,
488
- cid : None ,
489
- } ;
490
- return Ok ( ( parts, request) ) ;
491
- }
492
-
493
448
async fn tarball ( resp : reqwest:: Response , mut sender : hyper:: body:: Sender ) {
494
449
// Ideally, we would stream the response though the snappy decoding, but
495
450
// snappy doesn't support that AFAICT -- we'd need it to implement AsyncRead
0 commit comments