Class: OsCtl::Cli::Top::Tui::ModelThread
- Inherits:
-
Object
- Object
- OsCtl::Cli::Top::Tui::ModelThread
- Defined in:
- lib/osctl/cli/top/tui/model_thread.rb
Instance Attribute Summary collapse
- #generation ⇒ Integer readonly
- #last_measurement ⇒ Time? readonly
- #mode ⇒ :realtime, :cumulative
Instance Method Summary collapse
- #containers ⇒ Object
- #get_data ⇒ Object
-
#initialize(model, rate) ⇒ ModelThread
constructor
A new instance of ModelThread.
- #iostat_enabled? ⇒ Boolean
- #measure(mode: nil) ⇒ Object protected
- #start ⇒ Object
- #stop ⇒ Object
- #work ⇒ Object protected
Constructor Details
#initialize(model, rate) ⇒ ModelThread
Returns a new instance of ModelThread.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 14 def initialize(model, rate) @model = model @rate = rate @last_measurement = nil @generation = 0 @mode = model.mode @data = { containers: [] } @queue = OsCtl::Lib::Queue.new @mutex = Mutex.new end |
Instance Attribute Details
#generation ⇒ Integer (readonly)
9 10 11 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 9 def generation @generation end |
#last_measurement ⇒ Time? (readonly)
6 7 8 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 6 def last_measurement @last_measurement end |
#mode ⇒ :realtime, :cumulative
12 13 14 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 12 def mode @mode end |
Instance Method Details
#containers ⇒ Object
49 50 51 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 49 def containers @model.containers end |
#get_data ⇒ Object
34 35 36 37 38 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 34 def get_data @mutex.synchronize do [@data, @last_measurement, @generation] end end |
#iostat_enabled? ⇒ Boolean
45 46 47 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 45 def iostat_enabled? @model.iostat_enabled? end |
#measure(mode: nil) ⇒ Object (protected)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 72 def measure(mode: nil) @model.measure @mutex.synchronize do @last_measurement = Time.now if mode @model.mode = mode @mode = mode end @data = @model.data @generation += 1 end end |
#start ⇒ Object
25 26 27 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 25 def start @thread = Thread.new { work } end |
#stop ⇒ Object
29 30 31 32 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 29 def stop @queue << [:stop] @thread.join end |
#work ⇒ Object (protected)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/osctl/cli/top/tui/model_thread.rb', line 55 def work measure loop do cmd, *args = @queue.pop(timeout: @rate) return if cmd == :stop kwargs = {} if cmd == :mode kwargs[:mode] = args[0] end measure(**kwargs) end end |