Class: Sys::Top
- Inherits:
-
Object
- Object
- Sys::Top
- Defined in:
- lib/sys/top.rb
Overview
The Top class serves as a toplevel name for the ‘top’ method.
Constant Summary collapse
- VERSION =
The version of the sys-top library
'1.0.3'
Class Method Summary collapse
-
.top(num = 10, field = 'pctcpu') ⇒ Object
Returns an array of Struct::ProcTableStruct elements containing up to
num
elements, sorted byfield
.
Class Method Details
.top(num = 10, field = 'pctcpu') ⇒ Object
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.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sys/top.rb', line 18 def self.top(num=10, field='pctcpu') field = field.to_s if field.is_a?(Symbol) # Sort by pid on Windows by default if File::ALT_SEPARATOR && field == 'pctcpu' field = 'pid' end Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1] end |