def DeleteOldClientStats(self, yield_after_count,
                           retention_time
                          ):
    """Deletes ClientStats older than a given timestamp."""
    deleted_count = 0
    yielded = False

    for stats_dict in itervalues(self.client_stats):
      for timestamp in list(stats_dict.keys()):
        if timestamp < retention_time:
          del stats_dict[timestamp]
          deleted_count += 1

          if deleted_count >= yield_after_count:
            yield deleted_count
            yielded = True
            deleted_count = 0

    if deleted_count > 0 or not yielded:
      yield deleted_count
Deletes ClientStats older than a given timestamp.