parameters: (self)
return_statement: return proc_stats
docstring: Calculate process CPU/VM stats (CPU stats are relative to last call).
docstring_summary: Calculate process CPU/VM stats (CPU stats are relative to last call).
docstring_tokens: Calculate process CPU / VM stats ( CPU stats are relative to last call ) .
function: def GetStats(self):
      """Calculate process CPU/VM stats (CPU stats are relative to last call)."""
      # Process must retain its own copy of _last_sys_stats because CPU times
      # are calculated relatively to the last GetStats() call (for the process).
      cur_sys_stats = self.device.UpdateAndGetSystemStats()
      old_sys_stats = self._last_sys_stats or cur_sys_stats
      cur_proc_stats = cur_sys_stats['processes'].get(str(self.pid))
      old_proc_stats = old_sys_stats['processes'].get(str(self.pid))
  
      # The process might have gone in the meanwhile.
      if (not cur_proc_stats or not old_proc_stats):
        return None
  
      run_time = (((cur_sys_stats['time']['ticks'] -
                  cur_proc_stats['start_time']) / cur_sys_stats['time']['rate']))
      ticks = max(1, cur_sys_stats['time']['ticks'] -
                  old_sys_stats['time']['ticks'])
      cpu_usage = (100 *
                   ((cur_proc_stats['user_time'] + cur_proc_stats['sys_time']) -
                   (old_proc_stats['user_time'] + old_proc_stats['sys_time'])) /
                   ticks) / len(cur_sys_stats['cpu'])
      proc_stats = backends.ProcessStats(
          threads=cur_proc_stats['n_threads'],
          run_time=run_time,
          cpu_usage=cpu_usage,
          vm_rss=cur_proc_stats['vm_rss'],
          page_faults=cur_proc_stats['maj_faults'] + cur_proc_stats['min_faults'])
      self._last_sys_stats = cur_sys_stats
      return proc_stats
function_tokens: def GetStats ( self ) : # Process must retain its own copy of _last_sys_stats because CPU times # are calculated relatively to the last GetStats() call (for the process). cur_sys_stats = self . device . UpdateAndGetSystemStats ( ) old_sys_stats = self . _last_sys_stats or cur_sys_stats cur_proc_stats = cur_sys_stats [ 'processes' ] . get ( str ( self . pid ) ) old_proc_stats = old_sys_stats [ 'processes' ] . get ( str ( self . pid ) ) # The process might have gone in the meanwhile. if ( not cur_proc_stats or not old_proc_stats ) : return None run_time = ( ( ( cur_sys_stats [ 'time' ] [ 'ticks' ] - cur_proc_stats [ 'start_time' ] ) / cur_sys_stats [ 'time' ] [ 'rate' ] ) ) ticks = max ( 1 , cur_sys_stats [ 'time' ] [ 'ticks' ] - old_sys_stats [ 'time' ] [ 'ticks' ] ) cpu_usage = ( 100 * ( ( cur_proc_stats [ 'user_time' ] + cur_proc_stats [ 'sys_time' ] ) - ( old_proc_stats [ 'user_time' ] + old_proc_stats [ 'sys_time' ] ) ) / ticks ) / len ( cur_sys_stats [ 'cpu' ] ) proc_stats = backends . ProcessStats ( threads = cur_proc_stats [ 'n_threads' ] , run_time = run_time , cpu_usage = cpu_usage , vm_rss = cur_proc_stats [ 'vm_rss' ] , page_faults = cur_proc_stats [ 'maj_faults' ] + cur_proc_stats [ 'min_faults' ] ) self . _last_sys_stats = cur_sys_stats return proc_stats