parameters: (interval=None, percpu=False)
docstring: Return a float representing the current system-wide CPU
      utilization as a percentage.
  
      When interval is > 0.0 compares system CPU times elapsed before
      and after the interval (blocking).
  
      When interval is 0.0 or None compares system CPU times elapsed
      since last call or module import, returning immediately (non
      blocking). That means the first time this is called it will
      return a meaningless 0.0 value which you should ignore.
      In this case is recommended for accuracy that this function be
      called with at least 0.1 seconds between calls.
  
      When percpu is True returns a list of floats representing the
      utilization as a percentage for each CPU.
      First element of the list refers to first CPU, second element
      to second CPU and so on.
      The order of the list is consistent across calls.
  
      Examples:
  
        >>> # blocking, system-wide
        >>> psutil.cpu_percent(interval=1)
        2.0
        >>>
        >>> # blocking, per-cpu
        >>> psutil.cpu_percent(interval=1, percpu=True)
        [2.0, 1.0]
        >>>
        >>> # non-blocking (percentage since last call)
        >>> psutil.cpu_percent(interval=None)
        2.9
        >>>
docstring_summary: Return a float representing the current system-wide CPU
      utilization as a percentage.
docstring_tokens: Return a float representing the current system - wide CPU utilization as a percentage .
function: def cpu_percent(interval=None, percpu=False):
      """Return a float representing the current system-wide CPU
      utilization as a percentage.
  
      When interval is > 0.0 compares system CPU times elapsed before
      and after the interval (blocking).
  
      When interval is 0.0 or None compares system CPU times elapsed
      since last call or module import, returning immediately (non
      blocking). That means the first time this is called it will
      return a meaningless 0.0 value which you should ignore.
      In this case is recommended for accuracy that this function be
      called with at least 0.1 seconds between calls.
  
      When percpu is True returns a list of floats representing the
      utilization as a percentage for each CPU.
      First element of the list refers to first CPU, second element
      to second CPU and so on.
      The order of the list is consistent across calls.
  
      Examples:
  
        >>> # blocking, system-wide
        >>> psutil.cpu_percent(interval=1)
        2.0
        >>>
        >>> # blocking, per-cpu
        >>> psutil.cpu_percent(interval=1, percpu=True)
        [2.0, 1.0]
        >>>
        >>> # non-blocking (percentage since last call)
        >>> psutil.cpu_percent(interval=None)
        2.9
        >>>
      """
      global _last_cpu_times
      global _last_per_cpu_times
      blocking = interval is not None and interval > 0.0
  
      def calculate(t1, t2):
          t1_all = sum(t1)
          t1_busy = t1_all - t1.idle
  
          t2_all = sum(t2)
          t2_busy = t2_all - t2.idle
  
          # this usually indicates a float precision issue
          if t2_busy <= t1_busy:
              return 0.0
  
          busy_delta = t2_busy - t1_busy
          all_delta = t2_all - t1_all
          busy_perc = (busy_delta / all_delta) * 100
          return round(busy_perc, 1)
  
      # system-wide usage
      if not percpu:
          if blocking:
              t1 = cpu_times()
              time.sleep(interval)
          else:
              t1 = _last_cpu_times
          _last_cpu_times = cpu_times()
          return calculate(t1, _last_cpu_times)
      # per-cpu usage
      else:
          ret = []
          if blocking:
              tot1 = cpu_times(percpu=True)
              time.sleep(interval)
          else:
              tot1 = _last_per_cpu_times
          _last_per_cpu_times = cpu_times(percpu=True)
          for t1, t2 in zip(tot1, _last_per_cpu_times):
              ret.append(calculate(t1, t2))
          return ret
function_tokens: def cpu_percent ( interval = None , percpu = False ) : global _last_cpu_times global _last_per_cpu_times blocking = interval is not None and interval > 0.0 def calculate ( t1 , t2 ) : t1_all = sum ( t1 ) t1_busy = t1_all - t1 . idle t2_all = sum ( t2 ) t2_busy = t2_all - t2 . idle # this usually indicates a float precision issue if t2_busy <= t1_busy : return 0.0 busy_delta = t2_busy - t1_busy all_delta = t2_all - t1_all busy_perc = ( busy_delta / all_delta ) * 100 return round ( busy_perc , 1 ) # system-wide usage if not percpu : if blocking : t1 = cpu_times ( ) time . sleep ( interval ) else : t1 = _last_cpu_times _last_cpu_times = cpu_times ( ) return calculate ( t1 , _last_cpu_times ) # per-cpu usage else : ret = [ ] if blocking : tot1 = cpu_times ( percpu = True ) time . sleep ( interval ) else : tot1 = _last_per_cpu_times _last_per_cpu_times = cpu_times ( percpu = True ) for t1 , t2 in zip ( tot1 , _last_per_cpu_times ) : ret . append ( calculate ( t1 , t2 ) ) return ret