@@ -511,6 +511,47 @@ static void s_s3_meta_request_destroy(void *user_data) {
511511 aws_cached_signing_config_destroy (meta_request -> cached_signing_config );
512512 aws_string_destroy (meta_request -> s3express_session_host );
513513 aws_mutex_clean_up (& meta_request -> synced_data .lock );
514+ char filename [256 ];
515+ meta_request -> count ++ ;
516+ snprintf (filename , sizeof (filename ), "/tmp/s3_read_metrics_%d.csv" , meta_request -> count );
517+ FILE * metrics_file = fopen (filename , "w" );
518+ /* write every read metric to a file */
519+ size_t metric_length = aws_array_list_length (& meta_request -> read_metrics_list );
520+ /* write every read metric to a file */
521+ if (metrics_file ) {
522+ // Write CSV header
523+ fprintf (metrics_file , "index,offset,size,start_timestamp,end_timestamp,duration_ns,throughput_mbps\n" );
524+ // Write all metrics
525+ for (size_t j = 0 ; j < metric_length ; j ++ ) {
526+ struct s3_data_read_metrics m ;
527+ aws_array_list_get_at (& meta_request -> read_metrics_list , & m , j );
528+
529+ uint64_t duration = m .end_timestamp - m .start_timestamp ;
530+ double throughput_mbps = duration > 0 ? (double )(m .size * 8 ) / (duration / 1000.0 ) / 1000000.0 : 0.0 ;
531+
532+ fprintf (
533+ metrics_file ,
534+ "%zu,%llu,%llu,%llu,%llu,%llu,%.2f\n" ,
535+ j ,
536+ (unsigned long long )m .offset ,
537+ (unsigned long long )m .size ,
538+ (unsigned long long )m .start_timestamp ,
539+ (unsigned long long )m .end_timestamp ,
540+ (unsigned long long )duration ,
541+ throughput_mbps );
542+ }
543+ fclose (metrics_file );
544+
545+ AWS_LOGF_INFO (
546+ AWS_LS_S3_META_REQUEST ,
547+ "id=%p Wrote %zu read metrics to %s" ,
548+ (void * )meta_request ,
549+ metric_length ,
550+ filename );
551+ } else {
552+ AWS_LOGF_ERROR (AWS_LS_S3_META_REQUEST , "id=%p Failed to open metrics file %s" , (void * )meta_request , filename );
553+ }
554+ aws_array_list_clean_up (& meta_request -> read_metrics_list );
514555 /* endpoint should have already been released and set NULL by the meta request finish call.
515556 * But call release() again, just in case we're tearing down a half-initialized meta request */
516557 aws_s3_endpoint_release (meta_request -> endpoint );
0 commit comments