Skip to content

Commit bdd9c2b

Browse files
committed
Add total_fuzzing_time_seconds to FuzzTaskOutput
1 parent c1e2270 commit bdd9c2b

19 files changed

+82
-50
lines changed

src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/clusterfuzz/_internal/build_management/build_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,8 @@ def _emit_build_age_metric(gcs_path):
12071207
# the gcs api returns string, and the local filesystem implementation
12081208
# returns a datetime.datetime object normalized for UTC.
12091209
last_update_time = datetime.datetime.fromisoformat(last_update_time)
1210+
if last_update_time.tzinfo is None:
1211+
last_update_time = last_update_time.replace(tzinfo=datetime.timezone.utc)
12101212
now = datetime.datetime.now(datetime.timezone.utc)
12111213
elapsed_time = now - last_update_time
12121214
elapsed_time_in_hours = elapsed_time.total_seconds() / 3600

src/clusterfuzz/_internal/protos/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ python -m grpc_tools.protoc \
2525
$SCRIPT_DIR/*.proto
2626

2727
read -r -d '' COPYRIGHT_HEADER <<EOF
28-
# Copyright 2023 Google LLC
28+
# Copyright 2026 Google LLC
2929
#
3030
# Licensed under the Apache License, Version 2.0 (the "License");
3131
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/heartbeat_pb2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/heartbeat_pb2.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/heartbeat_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/process_state_pb2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/process_state_pb2.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/process_state_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

src/clusterfuzz/_internal/protos/swarming_pb2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)