@@ -412,24 +412,25 @@ def __init__(self, fuzzer_name, job_type, time_module=time):
412412 self .time = time_module
413413 self .start_time = None
414414 self .timeout = None
415+ self .duration = 0
415416
416417 def __enter__ (self ):
417418 self .start_time = self .time .time ()
418419 self .timeout = False
419420 return self
420421
421422 def __exit__ (self , exc_type , value , traceback ):
422- duration = self .time .time () - self .start_time
423+ self . duration = self .time .time () - self .start_time
423424 monitoring_metrics .FUZZER_TOTAL_FUZZ_TIME .increment_by (
424- int (duration ), {
425+ int (self . duration ), {
425426 'fuzzer' : self .fuzzer_name ,
426427 'timeout' : self .timeout ,
427428 'platform' : environment .platform (),
428429 'is_batch' : environment .is_uworker (),
429430 'runtime' : environment .get_runtime ().value ,
430431 })
431432 monitoring_metrics .JOB_TOTAL_FUZZ_TIME .increment_by (
432- int (duration ), {
433+ int (self . duration ), {
433434 'job' : self .job_type ,
434435 'timeout' : self .timeout ,
435436 'platform' : environment .platform (),
@@ -1643,6 +1644,8 @@ def do_engine_fuzzing(self, engine_impl):
16431644 self .testcase_directory )
16441645 # Timeouts are only accounted for in libfuzzer, this can be None
16451646 tracker .timeout = bool (result .timed_out )
1647+ self .fuzz_task_output .total_fuzzing_time_seconds += int (
1648+ tracker .duration )
16461649 except FuzzTargetNotFoundError :
16471650 # Ocassionally fuzz targets are deleted. This is pretty rare. Since
16481651 # ClusterFuzz did nothing wrong, don't bubble up an exception, consider
@@ -1834,6 +1837,7 @@ def do_blackbox_fuzzing(self, fuzzer, fuzzer_directory, job_type):
18341837 with _TrackFuzzTime (self .fully_qualified_fuzzer_name ,
18351838 job_type ) as tracker :
18361839 tracker .timeout = utils .wait_until_timeout (threads , thread_timeout )
1840+ self .fuzz_task_output .total_fuzzing_time_seconds += int (tracker .duration )
18371841
18381842 # Allow for some time to finish processing before terminating the
18391843 # processes.
@@ -2054,7 +2058,9 @@ def postprocess(self, uworker_output):
20542058 fuzz_task_output = uworker_output .fuzz_task_output
20552059 postprocess_store_fuzzer_run_results (uworker_output )
20562060 logs .info ('postprocess: fuzz_task_output.fully_qualified_fuzzer_name '
2057- f'{ fuzz_task_output .fully_qualified_fuzzer_name } ' )
2061+ f'{ fuzz_task_output .fully_qualified_fuzzer_name } . '
2062+ 'Total fuzzing time seconds: '
2063+ f'{ fuzz_task_output .total_fuzzing_time_seconds } ' )
20582064 uworker_input = uworker_output .uworker_input
20592065 postprocess_process_crashes (uworker_input , uworker_output )
20602066 postprocess_sample_testcases (uworker_input , uworker_output )
@@ -2072,6 +2078,9 @@ def postprocess(self, uworker_output):
20722078
20732079 _upload_testcase_run_jsons (
20742080 uworker_output .fuzz_task_output .testcase_run_jsons )
2081+ # TODO(dylanj): Upload total fuzzing time to big query
2082+ logs .info (
2083+ f"Total fuzzing time { fuzz_task_output .total_fuzzing_time_seconds } " )
20752084 testcase_manager .update_build_metadata (
20762085 uworker_input .job_type , uworker_output .fuzz_task_output .build_data )
20772086
0 commit comments