Class: PSI::Trigger
- Inherits:
-
Object
- Object
- PSI::Trigger
- Defined in:
- lib/psi/trigger.rb
Overview
A kernel PSI trigger tied to an open pressure file descriptor.
Constant Summary collapse
- KINDS =
Triggerable pressure categories.
%i[some full].freeze
Instance Attribute Summary collapse
-
#cgroup ⇒ Object
readonly
Returns the value of attribute cgroup.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#stall ⇒ Object
readonly
Returns the value of attribute stall.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Class Method Summary collapse
-
.open ⇒ Trigger, Object
Opens a trigger and closes it after the optional block.
Instance Method Summary collapse
-
#close ⇒ nil
Closes the descriptor and unregisters the kernel trigger.
- #closed? ⇒ Boolean
-
#initialize(resource, kind: :some, stall:, window:, cgroup: nil) ⇒ Trigger
constructor
A new instance of Trigger.
- #to_io ⇒ Object
- #wait(timeout: nil) ⇒ Object
Constructor Details
#initialize(resource, kind: :some, stall:, window:, cgroup: nil) ⇒ Trigger
Returns a new instance of Trigger.
26 27 28 29 30 31 32 33 34 |
# File 'lib/psi/trigger.rb', line 26 def initialize(resource, kind: :some, stall:, window:, cgroup: nil) @resource = resource.respond_to?(:to_sym) ? resource.to_sym : resource @kind = kind.respond_to?(:to_sym) ? kind.to_sym : kind @stall = Float(stall) @window = Float(window) @cgroup = cgroup validate! register end |
Instance Attribute Details
#cgroup ⇒ Object (readonly)
Returns the value of attribute cgroup.
11 12 13 |
# File 'lib/psi/trigger.rb', line 11 def cgroup @cgroup end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
11 12 13 |
# File 'lib/psi/trigger.rb', line 11 def kind @kind end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
11 12 13 |
# File 'lib/psi/trigger.rb', line 11 def resource @resource end |
#stall ⇒ Object (readonly)
Returns the value of attribute stall.
11 12 13 |
# File 'lib/psi/trigger.rb', line 11 def stall @stall end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
11 12 13 |
# File 'lib/psi/trigger.rb', line 11 def window @window end |
Class Method Details
.open ⇒ Trigger, Object
Opens a trigger and closes it after the optional block.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/psi/trigger.rb', line 15 def self.open(...) trigger = new(...) return trigger unless block_given? begin yield trigger ensure trigger.close end end |
Instance Method Details
#close ⇒ nil
Closes the descriptor and unregisters the kernel trigger.
44 45 46 47 |
# File 'lib/psi/trigger.rb', line 44 def close @io&.close unless closed? nil end |
#closed? ⇒ Boolean
49 50 51 |
# File 'lib/psi/trigger.rb', line 49 def closed? !@io || @io.closed? end |
#to_io ⇒ Object
53 54 55 56 57 |
# File 'lib/psi/trigger.rb', line 53 def to_io raise Error, "trigger is closed" if closed? @io end |
#wait(timeout: nil) ⇒ Object
36 37 38 39 40 |
# File 'lib/psi/trigger.rb', line 36 def wait(timeout: nil) raise Error, "trigger is closed" if closed? !!@io.wait(IO::PRIORITY, timeout) end |