Class: Cosmos::TabbedPlotsLogfileThread
- Defined in:
- lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb
Overview
Thread used to gather telemetry from log file(s) and process it using a TabbedPlotsDefinition
Constant Summary collapse
- PROGRESS_UPDATE_PACKET_COUNT =
Number of packets between updating the progress bar
100
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Array of exceptions that occurred processing the log file.
Instance Method Summary collapse
-
#done? ⇒ Boolean
Indicates if processing is complete.
-
#graceful_kill ⇒ Object
def kill.
-
#initialize(log_files, packet_log_reader, tabbed_plots_config, progress_dialog = nil, time_start = nil, time_end = nil) ⇒ TabbedPlotsLogfileThread
constructor
Create a new TabbedPlotsLogfileThread.
-
#kill(progress_dialog = nil) ⇒ Object
Kills the log file processing thread.
Constructor Details
#initialize(log_files, packet_log_reader, tabbed_plots_config, progress_dialog = nil, time_start = nil, time_end = nil) ⇒ TabbedPlotsLogfileThread
Create a new TabbedPlotsLogfileThread
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb', line 25 def initialize(log_files, packet_log_reader, tabbed_plots_config, progress_dialog = nil, time_start = nil, time_end = nil) super() @packet_log_reader = packet_log_reader @tabbed_plots_config = tabbed_plots_config @errors = [] @done = false @cancel = false if progress_dialog progress_dialog.cancel_callback = method(:kill) progress_dialog. end @thread = Thread.new do begin log_file_count = 1 log_files.each do |log_file| break if @cancel begin file_size = File.size(log_file).to_f break if @cancel progress_dialog.append_text("Procesing File #{log_file_count}/#{log_files.length}: #{log_file}\n") if progress_dialog break if @cancel progress_dialog.set_step_progress(0) if progress_dialog break if @cancel packet_count = 0 if progress_dialog Cosmos.check_log_configuration(@packet_log_reader, log_file) end @packet_log_reader.each(log_file, true, time_start, time_end) do |packet| break if @cancel if progress_dialog and packet_count % PROGRESS_UPDATE_PACKET_COUNT == 0 progress_dialog.set_step_progress(@packet_log_reader.bytes_read / file_size) end break if @cancel @tabbed_plots_config.process_packet(packet) packet_count += 1 end break if @cancel progress_dialog.set_step_progress(1.0) if progress_dialog and not @cancel break if @cancel progress_dialog.set_overall_progress(log_file_count.to_f / log_files.length.to_f) if progress_dialog and not @cancel break if @cancel rescue Exception => error @errors << error break if @cancel progress_dialog.append_text("Error processing #{log_file}:\n#{error.class} : #{error.}\n#{error.backtrace.join("\n")}\n", 2) if progress_dialog # If a progress dialog is shown we can't just bail on this error or # it will close and the user will have no idea what happened # Thus we'll spin here waiting for them to close the dialog break if @cancel if progress_dialog sleep(0.1) until progress_dialog.complete? end break # Bail out because something bad happened end log_file_count += 1 end ensure if !@cancel progress_dialog.complete if progress_dialog sleep(0.1) # Give the user a chance to see something if we process really fast end @done = true end end end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Array of exceptions that occurred processing the log file
22 23 24 |
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb', line 22 def errors @errors end |
Instance Method Details
#done? ⇒ Boolean
Indicates if processing is complete
94 95 96 |
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb', line 94 def done? @done end |
#graceful_kill ⇒ Object
def kill
108 109 110 |
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb', line 108 def graceful_kill # Just to remove warnings end |
#kill(progress_dialog = nil) ⇒ Object
Kills the log file processing thread
99 100 101 102 103 104 105 106 |
# File 'lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb', line 99 def kill(progress_dialog = nil) @cancel = true Cosmos.kill_thread(self, @thread) progress_dialog.complete if progress_dialog @thread = nil @done = true return true, false end |