Class: PerfMonger::Command::ServerCommand::Recorder
- Inherits:
-
Object
- Object
- PerfMonger::Command::ServerCommand::Recorder
- Defined in:
- lib/perfmonger/command/server.rb
Instance Method Summary collapse
- #get_current_record ⇒ Object
-
#initialize(record_cmd) ⇒ Recorder
constructor
A new instance of Recorder.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(record_cmd) ⇒ Recorder
Returns a new instance of Recorder.
147 148 149 150 151 152 153 154 155 |
# File 'lib/perfmonger/command/server.rb', line 147 def initialize(record_cmd) @current_record = nil @mutex = Mutex.new @cond = ConditionVariable.new @thread = nil @record_cmd = record_cmd @working = false end |
Instance Method Details
#get_current_record ⇒ Object
195 196 197 198 199 200 201 202 203 204 |
# File 'lib/perfmonger/command/server.rb', line 195 def get_current_record @mutex.synchronize do if @working @cond.wait(@mutex) current_perf_data = @current_perf_data else raise EOFError end end end |
#start ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/perfmonger/command/server.rb', line 157 def start @mutex.synchronize do if @thread.nil? @thread = true @working = true else return end end @thread = Thread.start do begin IO.popen(@record_cmd, "r") do |io| io.each_line do |line| @mutex.synchronize do @current_perf_data = line.strip @cond.broadcast end end end rescue Exception => err puts("ERROR: Exception in record_thread(#{@record_thread}) in perfmonger-server") puts("#{err.class.to_s}: #{err.}") puts(err.backtrace) end end self end |
#stop ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/perfmonger/command/server.rb', line 187 def stop @mutex.synchronize do @working = false @thread.terminate @cond.broadcast end end |