Skip to content

[Fuzz task steps duration] Add fuzz process execution duration - #5625

Open
brun0-matheus wants to merge 9 commits into
bruno.nested-step-checkfrom
bruno.add-fuzz-process-time
Open

brun0-matheus wants to merge 9 commits into
bruno.nested-step-checkfrom
bruno.add-fuzz-process-time

Conversation

@brun0-matheus

@brun0-matheus brun0-matheus commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Bug: b/577972745

Builds upon PR #5617

Overview

The fuzz step added in PR #5580 tracks more time than only the target program process execution. For blackbox, it also includes the time to spawn/manage the processes, and for engine it includes any other action defined in the fuzz method (it depends on the engine).

This PR measures the wall-clock time of the fuzzer process. For blackbox, it's the time CF waits for the processes to finish. For engine, it's the time return in FuzzResult.time_executed, which is the wall-clock time of the engine process.

Changes

  • Make TimeStatTracker support nested steps (adds expected_parent_step parameter and changes error messages).
  • Make TimeStatTracker support manual measurements.
  • Add fuzz_process_execution step to JobRun.steps_duration.

Tests

Unittests added and all pass. Tested on dev environment: https://screenshot-v2.corp.google.com/0bon3ieq2iet0 and https://screenshot.corp.google.com/53r2joq4gpgc0

@brun0-matheus brun0-matheus self-assigned this Nov 19, 2026
@brun0-matheus
brun0-matheus requested a review from a team as a code owner November 19, 2026 17:51
@brun0-matheus
brun0-matheus force-pushed the bruno.add-fuzz-process-time branch from eadfba5 to a3e611f Compare November 23, 2026 16:34
@brun0-matheus
brun0-matheus requested a review from decoNR November 23, 2026 17:44
@brun0-matheus
brun0-matheus force-pushed the bruno.add-fuzz-process-time branch 3 times, most recently from 33a7eb3 to 02c76c7 Compare November 24, 2026 16:30
@brun0-matheus
brun0-matheus force-pushed the bruno.add-fuzz-process-time branch from 0ace156 to 58390fc Compare November 24, 2026 17:39
Comment on lines +1496 to +1500
steps_time_tracker.measure(
'fuzz_process_exec',
result.time_executed,
success=True,
expected_parent_step='fuzz')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two caveats on result.time_executed:

  1. new_process.ProcessResult defaults time_executed=None, and other consumers tolerate None. Since this runs inside with steps_time_tracker.track('fuzz'):, if an engine ever returns time_executed=None, datetime.timedelta(seconds=None) raises TypeError, marks 'fuzz' as failed, and aborts the entire fuzzing session (discarding result and any found crashes). Guarding if result.time_executed is not None: here (in addition to validating inside TimeStatTracker._measure) avoids crashing a completed fuzz round.
  2. Note for AFL: AflRunner.run_afl_fuzz (afl/launcher.py) retries afl-fuzz on corpus hangs / CPU-affinity errors and returns only the last ProcessResult, so result.time_executed under-reports total afl-fuzz execution time on retried rounds (worth documenting or addressing in a follow-up).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This does not happen because, even though the default is None, when ProcessResult is returned time_executed is always set. Added a check with an error log to be safe, though.
  2. My original idea was to name this metric "fuzz_effective_time", so in this case it makes sense to drop the others runs in AFL, because only the last one is actually useful (the other ones are wasted). Tell me if you think it's better to rename to fuzz_efective_time (I don't like it because the name is not very clear) or to just add a comment about this.

Comment on lines +89 to +93
{
'name': 'fuzz_process_exec',
'type': 'INTERVAL',
'mode': 'NULLABLE',
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior PRs (#5580, #5617) maintained a disjoint, non-overlapping step invariant across steps_duration. fuzz_process_exec is the first sub-step (nested inside fuzz), yet it's exposed as a flat sibling column here and a flat step label value in monitoring_metrics.FUZZ_TASK_STEPS_DURATION with no comment or metric description noting the overlap.

Any BigQuery query or Cloud Monitoring dashboard that sums across steps_duration.* or aggregates FUZZ_TASK_STEPS_DURATION across step will silently double-count ~80–95% of an engine fuzz run. Since BigQuery column names and Cloud Monitoring label values are sticky once deployed, could we either:

  • Decide if sub-steps should be structurally distinguished (e.g., naming convention / nested record), and
  • At minimum, document the parent/child overlap prominently on _STEPS_DURATION_FIELDS and on FUZZ_TASK_STEPS_DURATION.description in monitoring_metrics.py?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea is to make sure nested steps are prefixed with the parent step (like fuzz_process_exec_time and fuzz). Nested steps can be handled later when the query is made.

Added a comment explaining this.

Comment on lines +687 to +700
def _measure(self, name: str, duration_secs: float, success: bool):
"""Records a duration measurement for |name| in stats and metric."""
duration = datetime.timedelta(seconds=duration_secs)
if name in self.stats:
self.stats[name] += duration
else:
self.stats[name] = duration
if self.metric:
self.metric.insert(
duration_secs,
labels={
**self.common_labels, 'step': name,
'success': success
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeStatTracker otherwise follows a "log an error and continue, never crash the caller" contract, but _measure passes duration_secs directly to datetime.timedelta(seconds=duration_secs) without validation:

  • None / non-numeric raises TypeError (which inside run_engine_fuzzer would abort a completed fuzz round).
  • Negative values (e.g. bad caller input or a backward NTP clock step in time.time()) produce a negative timedelta that _timedelta_to_duration_string formats as "P-1DT23H59M59.000000S" and corrupt dist.sum in Cloud Monitoring.

Suggest validating duration_secs here (logging an error and returning early if invalid):

if (not isinstance(duration_secs, (int, float)) or
    isinstance(duration_secs, bool) or
    not math.isfinite(duration_secs) or duration_secs < 0):
  logs.error(
      f'Invalid duration {duration_secs!r} for step "{name}"; skipping.')
  return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with checking the type of duration_secs. The name of the variable and the type annotation clearly indicates it must be a float. I agree with checking for negative values, and I decided to clamp to 0 (in order to still measure something and not break any caller code that uses the measure step) and log an error.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants