In Files

Parent

Methods

Class/Module Index [+]

Quicksearch

Sys::Top

The Top class serves as a toplevel name for the 'top' method.

Constants

VERSION

The version of the sys-top library

Public Class Methods

top(num=10, field='pctcpu') click to toggle source

Returns an array of Struct::ProcTableStruct elements containing up to num elements, sorted by field. The default number of elements is 10, while the default field is 'pctcpu'.

Exception: the default sort field is 'pid' on Linux and Windows.

# File lib/sys/top.rb, line 19
def self.top(num=10, field='pctcpu')
   field = field.to_s if field.is_a?(Symbol)
   
   windows = /mswin|win32|dos|cygwin|mingw/

   # Sort by pid on Windows by default
   if Config::CONFIG['host_os'].match(windows) && field == 'pctcpu'
      field = 'pid'
   end
   
   # Linux does not have a pctcpu field yet
   if Config::CONFIG['host_os'].match('linux') && field == 'pctcpu'
      field = 'pid'
   end
      
   Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.