@@ -3,6 +3,7 @@ use std::io::Read;
3
3
use std:: sync:: Arc ;
4
4
use std:: time:: { Duration , Instant } ;
5
5
6
+ use analyzeme:: ProfilingData ;
6
7
use bytes:: Buf ;
7
8
use database:: ArtifactIdNumber ;
8
9
use headers:: { ContentType , Header } ;
@@ -144,7 +145,7 @@ pub async fn handle_self_profile_processed_download(
144
145
fn get_self_profile_data (
145
146
cpu_clock : Option < f64 > ,
146
147
self_profile : Option < crate :: selector:: SelfProfileData > ,
147
- raw_data : Vec < u8 > ,
148
+ profiling_data : & ProfilingData ,
148
149
) -> ServerResult < self_profile:: SelfProfile > {
149
150
let profile = self_profile
150
151
. as_ref ( )
@@ -181,7 +182,7 @@ fn get_self_profile_data(
181
182
. map ( |qd| qd. incremental_load_time )
182
183
. sum ( ) ,
183
184
} ;
184
- let artifact_sizes = raw_mmprof_data_to_artifact_sizes ( raw_data ) . ok ( ) ;
185
+ let artifact_sizes = raw_mmprof_data_to_artifact_sizes ( profiling_data ) . ok ( ) ;
185
186
let profile = self_profile:: SelfProfile {
186
187
query_data : profile
187
188
. query_data
@@ -244,11 +245,11 @@ fn add_uninvoked_base_profile_queries(
244
245
fn get_self_profile_delta (
245
246
profile : & self_profile:: SelfProfile ,
246
247
base_profile : & Option < self_profile:: SelfProfile > ,
247
- raw_data : Vec < u8 > ,
248
- base_raw_data : Option < Vec < u8 > > ,
248
+ profiling_data : & ProfilingData ,
249
+ base_profiling_data : Option < & ProfilingData > ,
249
250
) -> Option < self_profile:: SelfProfileDelta > {
250
251
let base_profile = base_profile. as_ref ( ) ?;
251
- let base_raw_data = base_raw_data ?;
252
+ let base_raw_data = base_profiling_data ?;
252
253
253
254
let totals = self_profile:: QueryDataDelta {
254
255
self_time : profile. totals . self_time as i64 - base_profile. totals . self_time as i64 ,
@@ -288,13 +289,13 @@ fn get_self_profile_delta(
288
289
}
289
290
}
290
291
291
- let first = raw_mmprof_data_to_artifact_sizes ( raw_data ) . unwrap_or_else ( |_| Vec :: new ( ) ) ;
292
+ let first = raw_mmprof_data_to_artifact_sizes ( profiling_data ) . unwrap_or_else ( |_| Vec :: new ( ) ) ;
292
293
let base = raw_mmprof_data_to_artifact_sizes ( base_raw_data) . unwrap_or_else ( |_| Vec :: new ( ) ) ;
293
294
let artifact_sizes = first
294
295
. into_iter ( )
295
296
. zip ( base. into_iter ( ) )
296
297
. map ( |( a1, a2) | ArtifactSizeDelta {
297
- bytes : a1. bytes - a2. bytes ,
298
+ bytes : a1. bytes as i64 - a2. bytes as i64 ,
298
299
} )
299
300
. collect ( ) ;
300
301
@@ -687,7 +688,7 @@ pub async fn handle_self_profile(
687
688
. await ?;
688
689
assert_eq ! ( cpu_responses. len( ) , 1 , "all selectors are exact" ) ;
689
690
let mut cpu_response = cpu_responses. remove ( 0 ) . series ;
690
- let mut raw_self_profile_data = Vec :: new ( ) ;
691
+ let mut self_profile_data = Vec :: new ( ) ;
691
692
let conn = ctxt. conn ( ) . await ;
692
693
for commit in commits. iter ( ) {
693
694
let aids_and_cids = conn
@@ -696,34 +697,37 @@ pub async fn handle_self_profile(
696
697
if let Some ( ( aid, cid) ) = aids_and_cids. first ( ) {
697
698
match fetch_raw_self_profile_data ( * aid, bench_name, profile, & body. run_name , * cid) . await
698
699
{
699
- Ok ( d) => raw_self_profile_data. push ( d) ,
700
+ Ok ( d) => self_profile_data. push (
701
+ extract_profiling_data ( d)
702
+ . map_err ( |e| format ! ( "error extracting self profiling data: {}" , e) ) ?,
703
+ ) ,
700
704
Err ( _) => return Err ( format ! ( "could not fetch raw profile data" ) ) ,
701
705
} ;
702
706
}
703
707
}
704
- let raw_data = raw_self_profile_data . remove ( 0 ) ;
708
+ let profiling_data = self_profile_data . get ( 0 ) . unwrap ( ) ;
705
709
let mut profile = get_self_profile_data (
706
710
cpu_response. next ( ) . unwrap ( ) . 1 ,
707
711
sp_response. next ( ) . unwrap ( ) . 1 ,
708
- raw_data . clone ( ) ,
712
+ profiling_data ,
709
713
)
710
714
. map_err ( |e| format ! ( "{}: {}" , body. commit, e) ) ?;
711
715
let ( base_profile, base_raw_data) = if body. base_commit . is_some ( ) {
712
- let base_raw_data = raw_self_profile_data . remove ( 0 ) ;
716
+ let base_profiling_data = self_profile_data . get ( 1 ) . unwrap ( ) ;
713
717
let profile = get_self_profile_data (
714
718
cpu_response. next ( ) . unwrap ( ) . 1 ,
715
719
sp_response. next ( ) . unwrap ( ) . 1 ,
716
- base_raw_data . clone ( ) ,
720
+ base_profiling_data ,
717
721
)
718
722
. map_err ( |e| format ! ( "{}: {}" , body. base_commit. as_ref( ) . unwrap( ) , e) ) ?;
719
- ( Some ( profile) , Some ( base_raw_data ) )
723
+ ( Some ( profile) , Some ( base_profiling_data ) )
720
724
} else {
721
725
( None , None )
722
726
} ;
723
727
724
728
add_uninvoked_base_profile_queries ( & mut profile, & base_profile) ;
725
729
let mut base_profile_delta =
726
- get_self_profile_delta ( & profile, & base_profile, raw_data , base_raw_data) ;
730
+ get_self_profile_delta ( & profile, & base_profile, profiling_data , base_raw_data) ;
727
731
sort_self_profile ( & mut profile, & mut base_profile_delta, sort_idx) ;
728
732
729
733
Ok ( self_profile:: Response {
@@ -733,11 +737,8 @@ pub async fn handle_self_profile(
733
737
}
734
738
735
739
fn raw_mmprof_data_to_artifact_sizes (
736
- data : Vec < u8 > ,
740
+ profiling_data : & ProfilingData ,
737
741
) -> anyhow:: Result < Vec < self_profile:: ArtifactSize > > {
738
- let profiling_data = analyzeme:: ProfilingData :: from_paged_buffer ( data, None )
739
- . map_err ( |_| anyhow:: Error :: msg ( "could not parse profiling data" ) ) ?;
740
-
741
742
let mut artifact_sizes: BTreeMap < _ , u64 > = Default :: default ( ) ;
742
743
743
744
for event in profiling_data. iter_full ( ) {
@@ -760,3 +761,8 @@ fn raw_mmprof_data_to_artifact_sizes(
760
761
} )
761
762
. collect ( ) )
762
763
}
764
+
765
+ fn extract_profiling_data ( data : Vec < u8 > ) -> Result < analyzeme:: ProfilingData , anyhow:: Error > {
766
+ analyzeme:: ProfilingData :: from_paged_buffer ( data, None )
767
+ . map_err ( |_| anyhow:: Error :: msg ( "could not parse profiling data" ) )
768
+ }
0 commit comments