Repository navigation
[Fuzz task steps duration] Add fuzz process execution duration - #5625
brun0-matheus wants to merge 9 commits into
Conversation
eadfba5 to
a3e611f
Compare
33a7eb3 to
02c76c7
Compare
0ace156 to
58390fc
Compare
| steps_time_tracker.measure( | ||
| 'fuzz_process_exec', | ||
| result.time_executed, | ||
| success=True, | ||
| expected_parent_step='fuzz') |
There was a problem hiding this comment.
Two caveats on result.time_executed:
new_process.ProcessResultdefaultstime_executed=None, and other consumers tolerateNone. Since this runs insidewith steps_time_tracker.track('fuzz'):, if an engine ever returnstime_executed=None,datetime.timedelta(seconds=None)raisesTypeError, marks'fuzz'as failed, and aborts the entire fuzzing session (discardingresultand any found crashes). Guardingif result.time_executed is not None:here (in addition to validating insideTimeStatTracker._measure) avoids crashing a completed fuzz round.- Note for AFL:
AflRunner.run_afl_fuzz(afl/launcher.py) retriesafl-fuzzon corpus hangs / CPU-affinity errors and returns only the lastProcessResult, soresult.time_executedunder-reports totalafl-fuzzexecution time on retried rounds (worth documenting or addressing in a follow-up).
There was a problem hiding this comment.
- This does not happen because, even though the default is None, when ProcessResult is returned
time_executedis always set. Added a check with an error log to be safe, though. - 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.
| { | ||
| 'name': 'fuzz_process_exec', | ||
| 'type': 'INTERVAL', | ||
| 'mode': 'NULLABLE', | ||
| }, |
There was a problem hiding this comment.
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_FIELDSand onFUZZ_TASK_STEPS_DURATION.descriptioninmonitoring_metrics.py?
There was a problem hiding this comment.
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.
| 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 | ||
| }) |
There was a problem hiding this comment.
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 raisesTypeError(which insiderun_engine_fuzzerwould abort a completed fuzz round).- Negative values (e.g. bad caller input or a backward NTP clock step in
time.time()) produce a negativetimedeltathat_timedelta_to_duration_stringformats as"P-1DT23H59M59.000000S"and corruptdist.sumin 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.')
returnThere was a problem hiding this comment.
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.
Bug: b/577972745
Builds upon PR #5617
Overview
The
fuzzstep 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 thefuzzmethod (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
TimeStatTrackersupport nested steps (addsexpected_parent_stepparameter and changes error messages).TimeStatTrackersupport manual measurements.fuzz_process_executionstep toJobRun.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