From 6eb6da1d34a2cbb6e388059c8cf38720e0f25bac Mon Sep 17 00:00:00 2001 From: Vitor Guidi Date: Tue, 29 Oct 2024 12:16:50 -0300 Subject: [PATCH] Adding fuzzing session duration metric (#4336) ### Motivation We currently lack metrics for fuzzing session duration. This PR adds that as a histogram metric, with granularity by fuzzer, job and platform. Part of #4271 --- .../_internal/bot/tasks/utasks/fuzz_task.py | 9 +++++++++ .../_internal/metrics/monitoring_metrics.py | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py b/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py index db89002e3b..3a98cc2610 100644 --- a/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py +++ b/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py @@ -1718,6 +1718,7 @@ def do_blackbox_fuzzing(self, fuzzer, fuzzer_directory, job_type): def run(self): """Run the fuzzing session.""" + start_time = time.time() # Update LSAN local blacklist with global blacklist. global_blacklisted_functions = ( self.uworker_input.fuzz_task_input.global_blacklisted_functions) @@ -1871,6 +1872,14 @@ def run(self): self.fuzz_task_output.fuzzer_revision = self.fuzzer.revision self.fuzz_task_output.crash_groups.extend(crash_groups) + fuzzing_session_duration = time.time() - start_time + monitoring_metrics.FUZZING_SESSION_DURATION.add( + fuzzing_session_duration, { + 'fuzzer': self.fuzzer_name, + 'job': self.job_type, + 'platform': environment.platform() + }) + return uworker_msg_pb2.Output(fuzz_task_output=self.fuzz_task_output) # pylint: disable=no-member def postprocess(self, uworker_output): diff --git a/src/clusterfuzz/_internal/metrics/monitoring_metrics.py b/src/clusterfuzz/_internal/metrics/monitoring_metrics.py index bac5b81401..36b99e1676 100644 --- a/src/clusterfuzz/_internal/metrics/monitoring_metrics.py +++ b/src/clusterfuzz/_internal/metrics/monitoring_metrics.py @@ -91,6 +91,19 @@ ], ) +# This metric tracks fuzzer setup and data bundle update, +# fuzzing time and the time to upload results to datastore +FUZZING_SESSION_DURATION = monitor.CumulativeDistributionMetric( + 'task/fuzz/session/duration', + bucketer=monitor.FixedWidthBucketer(width=0.05, num_finite_buckets=20), + description=('Total duration of fuzzing session.'), + field_spec=[ + monitor.StringField('fuzzer'), + monitor.StringField('job'), + monitor.StringField('platform'), + ], +) + JOB_TOTAL_FUZZ_TIME = monitor.CounterMetric( 'task/fuzz/job/total_time', description=('The total fuzz time in seconds '