def executing(self):
    """A contextmanager that sets metrics in the context of a (v1) engine execution."""
    self._set_target_root_count_in_runtracker()
    yield
    metrics = self._scheduler.metrics()
    self.run_tracker.pantsd_stats.set_scheduler_metrics(metrics)
    engine_workunits = self._scheduler.engine_workunits(metrics)
    if engine_workunits:
      self.run_tracker.report.bulk_record_workunits(engine_workunits)
    self._set_affected_target_count_in_runtracker()