@@ -192,21 +192,49 @@ impl SelfProfileStorage for S3SelfProfileStorage {
192192 let upload = tempfile:: NamedTempFile :: new ( ) . context ( "cannot create temporary file" ) ?;
193193 match files {
194194 SelfProfileFiles :: Eight { file } => {
195+ let start = Instant :: now ( ) ;
195196 let data = tokio:: fs:: read ( file)
196197 . await
197198 . context ( "cannot read self-profile data" ) ?;
198- let mut data = snap:: read:: FrameEncoder :: new ( & data[ ..] ) ;
199- let mut compressed = Vec :: new ( ) ;
200- data. read_to_end ( & mut compressed)
201- . context ( "cannot compress self-profile data" ) ?;
199+ log:: trace!(
200+ "Read self-profile duration: {}, size: {}" ,
201+ start. elapsed( ) . as_secs_f64( ) ,
202+ data. len( )
203+ ) ;
204+ let start = Instant :: now ( ) ;
205+
206+ // This is synchronous and blocks the event loop, so we should do it on a
207+ // worker thread
208+ let compressed = tokio:: task:: spawn_blocking ( move || {
209+ let mut data = snap:: read:: FrameEncoder :: new ( & data[ ..] ) ;
210+ let mut compressed = Vec :: new ( ) ;
211+
212+ data. read_to_end ( & mut compressed)
213+ . context ( "cannot compress self-profile data" ) ?;
214+ anyhow:: Ok ( compressed)
215+ } )
216+ . await ??;
217+
218+ log:: trace!(
219+ "Compress self-profile duration: {}, size: {}" ,
220+ start. elapsed( ) . as_secs_f64( ) ,
221+ compressed. len( )
222+ ) ;
223+ let start = Instant :: now ( ) ;
202224 tokio:: fs:: write ( upload. path ( ) , & compressed)
203225 . await
204226 . context ( "cannot write compressed self-profile data" ) ?;
227+ log:: trace!(
228+ "Write self-profile duration: {}" ,
229+ start. elapsed( ) . as_secs_f64( )
230+ ) ;
231+ compressed
205232 }
206233 } ;
207234
208235 log:: info!( "Uploading self-profile to {}" , file_path. display( ) ) ;
209236
237+ let start = Instant :: now ( ) ;
210238 let output = tokio:: process:: Command :: new ( "aws" )
211239 . arg ( "s3" )
212240 . arg ( "cp" )
@@ -232,6 +260,10 @@ impl SelfProfileStorage for S3SelfProfileStorage {
232260 String :: from_utf8_lossy( & output. stderr)
233261 ) ) ;
234262 }
263+ log:: trace!(
264+ "Upload self-profile duration: {}" ,
265+ start. elapsed( ) . as_secs_f64( )
266+ ) ;
235267 Ok ( ( ) )
236268 } )
237269 }
0 commit comments