Ejemplo n.º 1
0
    def Progress(self):
        """Indicate progress of the client action.

    This function should be called periodically during client actions that do
    not finish instantly. It will notify the nanny that the action is not stuck
    and avoid the timeout and it will also check if the action has reached its
    cpu limit.

    Raises:
      CPUExceededError: CPU limit exceeded.
    """
        now = time.time()
        if now - self.last_progress_time <= 2:
            return

        self.last_progress_time = now

        # Prevent the machine from sleeping while the action is running.
        client_utils.KeepAlive()

        self.grr_worker.Heartbeat()

        user_start = self.cpu_start.user
        system_start = self.cpu_start.system
        cpu_times = self.proc.cpu_times()
        user_end = cpu_times.user
        system_end = cpu_times.system

        used_cpu = user_end - user_start + system_end - system_start

        if used_cpu > self.cpu_limit:
            self.grr_worker.SendClientAlert("Cpu limit exceeded.")
            raise CPUExceededError("Action exceeded cpu limit.")
Ejemplo n.º 2
0
    def Progress(self):
        """Indicate progress of the client action.

    This function should be called periodically during client actions that do
    not finish instantly. It will notify the nanny that the action is not stuck
    and avoid the timeout and it will also check if the action has reached its
    cpu limit.

    Raises:
      CPUExceededError: CPU limit exceeded.
      RuntimeExceededError: Runtime limit exceeded.
    """
        now = rdfvalue.RDFDatetime.Now()
        time_since_last_progress = now - ActionPlugin.last_progress_time

        if time_since_last_progress <= self._PROGRESS_THROTTLE_INTERVAL:
            return

        if self.runtime_limit and now - self.start_time > self.runtime_limit:
            raise RuntimeExceededError(
                "{} exceeded runtime limit of {}.".format(
                    compatibility.GetName(type(self)), self.runtime_limit))

        ActionPlugin.last_progress_time = now

        # Prevent the machine from sleeping while the action is running.
        client_utils.KeepAlive()

        self.grr_worker.Heartbeat()

        used_cpu = self.cpu_times.total_cpu_used

        if used_cpu > self.cpu_limit:
            raise CPUExceededError("Action exceeded cpu limit.")