Skip to content

Commit

Permalink
Merge pull request #83 from BallAerospace/improve-startup-speed
Browse files Browse the repository at this point in the history
re #82 Improve COSMOS startup speed
  • Loading branch information
ryanmelt committed Mar 13, 2015
2 parents fc3772d + 348ce70 commit 8403d38
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 45 deletions.
1 change: 0 additions & 1 deletion lib/cosmos/gui/choosers/telemetry_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def initialize(
@item_changed_callback = nil
@select_button_callback = nil
@support_latest = support_latest
update()
end

# Update items
Expand Down
14 changes: 10 additions & 4 deletions lib/cosmos/gui/dialogs/progress_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def initialize(parent, title, width = 500, height = 300, show_overall = true, sh

@thread = nil
@cancel_callback = nil
@overall_progress = 0
@step_progress = 0
end

def self.canceled?
Expand Down Expand Up @@ -199,17 +201,21 @@ def complete
end

def set_step_progress (value)
unless @complete
progress_int = (value * 100).to_i
if !@complete and @step_progress != progress_int
@step_progress = progress_int
Qt.execute_in_main_thread(false) do
@step_bar.setValue(value * 100.0) if @step_bar
@step_bar.setValue(progress_int) if @step_bar
end
end
end

def set_overall_progress (value)
unless @complete
progress_int = (value * 100).to_i
if !@complete and @overall_progress != progress_int
@overall_progress = progress_int
Qt.execute_in_main_thread(false) do
@overall_bar.setValue(value * 100.0) if @overall_bar
@overall_bar.setValue(progress_int) if @overall_bar
end
end
end
Expand Down
42 changes: 32 additions & 10 deletions lib/cosmos/gui/dialogs/splash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ def initialize(parent)
layout.addWidget(@message_box)
@progress_bar = Qt::ProgressBar.new
layout.addWidget(@progress_bar)

setLayout(layout)

@progress = 0
@complete = false
end

def message=(message)
Qt.execute_in_main_thread(true) do
@message_box.setText(message)
unless @complete
Qt.execute_in_main_thread(false) do
@message_box.setText(message)
end
end
end

def progress=(progress)
Qt.execute_in_main_thread(true) do
@progress_bar.setValue(progress * 100)
progress_int = (progress * 100).to_i
if !@complete and @progress != progress_int
@progress = progress_int
Qt.execute_in_main_thread(false) do
@progress_bar.setValue(progress_int)
end
end
end

Expand Down Expand Up @@ -82,7 +90,6 @@ def self.execute(parent, wait_for_complete = false, &block)
# Qt.execute_in_main_thread(true) do
# < Update the GUI >
# end
complete = false
Thread.new do
error = nil
begin
Expand All @@ -91,6 +98,8 @@ def self.execute(parent, wait_for_complete = false, &block)
error = e
end

@complete = true

# If the block threw an error show it before allowing the application to crash
if error
Qt.execute_in_main_thread(true) do
Expand All @@ -101,12 +110,25 @@ def self.execute(parent, wait_for_complete = false, &block)
Qt.execute_in_main_thread(true) do
# Once the block has completed we hide and dispose the dialog to allow the main application to take over
dialog.hide
dialog.dispose unless wait_for_complete

unless wait_for_complete
# Need to make sure all Qt.execute_in_main_thread() have completed before disposing or
# we will segfault
Qt::RubyThreadFix.queue.pop.call until Qt::RubyThreadFix.queue.empty?

dialog.dispose
end
end
complete = true
end
dialog.exec if wait_for_complete
dialog.dispose if wait_for_complete
if wait_for_complete
dialog.exec

# Need to make sure all Qt.execute_in_main_thread() have completed before disposing or
# we will segfault
Qt::RubyThreadFix.queue.pop.call until Qt::RubyThreadFix.queue.empty?

dialog.dispose
end
end
end

Expand Down
5 changes: 3 additions & 2 deletions lib/cosmos/packets/limits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def get(target_name, packet_name, item_name, limits_set = nil)
# @return [Array<limits_set, persistence, enabled, red_low, yellow_low, red_high, yellow_high, green_low (optional), green_high (optional)] Limits information
def set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, red_high, green_low = nil, green_high = nil, limits_set = :CUSTOM, persistence = nil, enabled = true)
packet = get_packet(target_name, packet_name)
limits = packet.get_item(item_name).limits
item = packet.get_item(item_name)
limits = item.limits
if limits_set
limits_set = limits_set.to_s.upcase.intern
else
Expand Down Expand Up @@ -231,7 +232,7 @@ def set(target_name, packet_name, item_name, red_low, yellow_low, yellow_high, r
end
limits.enabled = enabled
limits.persistence_setting = Integer(persistence) if persistence
packet.update_limits_items_cache
packet.update_limits_items_cache(item)
@config.limits_sets << limits_set
@config.limits_sets.uniq!
return [limits_set, limits.persistence_setting, limits.enabled, limits_for_set[0], limits_for_set[1], limits_for_set[2], limits_for_set[3], limits_for_set[4], limits_for_set[5]]
Expand Down
21 changes: 12 additions & 9 deletions lib/cosmos/packets/packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def define_item(name, bit_offset, bit_size, data_type, array_size = nil, endiann
def define(item)
item = super(item)
update_id_items(item)
update_limits_items_cache()
update_limits_items_cache(item)
item
end

Expand Down Expand Up @@ -532,16 +532,19 @@ def disable_limits(name)
end
end

# Force the packet to update its knowledge of items with limits. This is an
# optimization so we don't have to iterate through all the items when
# Add an item to the limits items cache if necessary.
# You MUST call this after adding limits to an item
#This is an optimization so we don't have to iterate through all the items when
# checking for limits.
def update_limits_items_cache
# Collect only the items who have limits values or states and then
# compact the array to remove all the nil values
@limits_items = @sorted_items.collect do |item|
item if item.limits.values || item.state_colors
def update_limits_items_cache(item)
if item.limits.values || item.state_colors
@limits_items ||= []
@limits_items_hash ||= {}
unless @limits_items_hash[item]
@limits_items << item
@limits_items_hash[item] = true
end
end
@limits_items.compact!
end

# Return an array of arrays indicating all items in the packet that are out of limits
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/parsers/limits_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_limits(packet, item, warnings)
item.limits.persistence_setting = get_persistence()
item.limits.persistence_count = 0

packet.update_limits_items_cache
packet.update_limits_items_cache(item)
limits_set
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/packets/parsers/state_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def parse_additional_parameters(packet, cmd_or_tlm, item)
get_hazardous(item)
else
get_state_colors(item)
packet.update_limits_items_cache
packet.update_limits_items_cache(item)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/cosmos/tools/tlm_extractor/tlm_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def initialize(options)
@tlm_extractor_config = TlmExtractorConfig.new(options.config_file)
@tlm_extractor_processor = TlmExtractorProcessor.new
Qt.execute_in_main_thread(true) do
@telemetry_chooser.update
sync_config_to_gui()
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def initialize(parent, orientation = Qt::Horizontal)

# Chooser for packet and y item
@telemetry_chooser = TelemetryChooser.new(self, orientation, true, false, true, true)
@telemetry_chooser.update
@overall_frame.addWidget(@telemetry_chooser)
@telemetry_chooser.target_changed_callback = method(:packet_changed_callback)
@telemetry_chooser.packet_changed_callback = method(:packet_changed_callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def set_data_object(data_object)

# Telemetry Chooser for housekeeping item
@telemetry_chooser = TelemetryChooser.new(self, Qt::Vertical, true, false, true)
@telemetry_chooser.update
@telemetry_chooser.set_item(data_object.target_name, data_object.packet_name, data_object.item_name)
@telemetry_chooser.target_changed_callback = method(:target_packet_changed_callback)
@telemetry_chooser.packet_changed_callback = method(:target_packet_changed_callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def set_data_object(data_object)

# Telemetry Chooser for x item
@telemetry_chooser = TelemetryChooser.new(self, Qt::Vertical, true, false)
@telemetry_chooser.update
@telemetry_chooser.set_item(data_object.target_name, data_object.packet_name, data_object.y_item_name)
@telemetry_chooser.target_changed_callback = method(:target_packet_changed_callback)
@telemetry_chooser.packet_changed_callback = method(:target_packet_changed_callback)
Expand Down
50 changes: 33 additions & 17 deletions spec/packets/packet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,15 @@ module Cosmos
i = p.get_item("TEST1")
i.states = {"TRUE"=>1,"FALSE"=>0}
i.state_colors = {"TRUE"=>:GREEN,"FALSE"=>:RED}
p.update_limits_items_cache(i)
p.write("TEST1",0)
p.enable_limits("TEST1")
p.append_item("test2", 16, :UINT)
i = p.get_item("TEST2")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.write("TEST2",3)
p.enable_limits("TEST2")
p.update_limits_items_cache
p.update_limits_items_cache(i)
p.check_limits

vals = p.read_all_with_limits_states
Expand Down Expand Up @@ -813,14 +814,17 @@ module Cosmos
it "calls the limits_change_callback for all non STALE items" do
p = Packet.new("tgt","pkt")
p.append_item("test1", 8, :UINT)
p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST1")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.append_item("test2", 16, :UINT)
p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST2")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.write("TEST1",3)
p.write("TEST2",3)
p.enable_limits("TEST1")
p.enable_limits("TEST2")
p.update_limits_items_cache

callback = double("callback", :call => true)
p.limits_change_callback = callback
Expand All @@ -845,11 +849,11 @@ module Cosmos

test1 = p.get_item("TEST1")
test1.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache
p.update_limits_items_cache(test1)
expect(p.limits_items).to eql [test1]
test2 = p.get_item("TEST2")
test2.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache
p.update_limits_items_cache(test2)
expect(p.limits_items).to eql [test1, test2]
end
end
Expand All @@ -858,14 +862,17 @@ module Cosmos
it "returns an array indicating all items out of limits" do
p = Packet.new("tgt","pkt")
p.append_item("test1", 8, :UINT)
p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST1")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.enable_limits("TEST1")
p.write("TEST1",3)
p.append_item("test2", 16, :UINT)
p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST2")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.write("TEST2",3)
p.enable_limits("TEST2")
p.update_limits_items_cache
p.check_limits
expect(p.out_of_limits).to eql []

Expand All @@ -882,12 +889,15 @@ module Cosmos
it "sets all limits states to the given state" do
p = Packet.new("tgt","pkt")
p.append_item("test1", 8, :UINT)
p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST1")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.enable_limits("TEST1")
p.append_item("test2", 16, :UINT)
p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST2")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.enable_limits("TEST2")
p.update_limits_items_cache
expect(p.out_of_limits).to eql []

PacketItemLimits::OUT_OF_LIMITS_STATES.each do |state|
Expand Down Expand Up @@ -927,6 +937,7 @@ module Cosmos
expect(test1.limits.enabled).to be_falsey
test1.states = {"TRUE"=>1,"FALSE"=>0}
test1.state_colors = {"TRUE"=>:GREEN,"FALSE"=>:RED}
@p.update_limits_items_cache(test1)
@p.write("TEST1", 0)
@p.enable_limits("TEST1")
test2 = @p.get_item("TEST2")
Expand All @@ -935,7 +946,7 @@ module Cosmos
test2.state_colors = {"TRUE"=>:RED,"FALSE"=>:GREEN}
@p.write("TEST2", 0)
@p.enable_limits("TEST2")
@p.update_limits_items_cache
@p.update_limits_items_cache(test2)

# Mock the callback so we can see if it is called properly
callback = double("callback", :call => true)
Expand Down Expand Up @@ -963,18 +974,20 @@ module Cosmos
@test1 = @p.get_item("TEST1")
expect(@test1.limits.enabled).to be_falsey
@test1.limits.values = {:DEFAULT=>[1,2,4,5]} # red yellow
@p.update_limits_items_cache(@test1)
@p.enable_limits("TEST1")

@test2 = @p.get_item("TEST2")
expect(@test2.limits.enabled).to be_falsey
@test2.limits.values = {:DEFAULT=>[1,2,6,7,3,5]} # red yellow and blue
@p.update_limits_items_cache(@test2)
@p.enable_limits("TEST2")

@test3 = @p.get_item("TEST3")
expect(@test3.limits.enabled).to be_falsey
@test3.limits.values = {:DEFAULT=>[1,1.5,2.5,3]} # red yellow
@p.update_limits_items_cache(@test3)
@p.enable_limits("TEST3")
@p.update_limits_items_cache

# Mock the callback so we can see if it is called properly
@callback = double("callback", :call => true)
Expand Down Expand Up @@ -1224,12 +1237,15 @@ module Cosmos
it "sets all limits states to stale" do
p = Packet.new("tgt","pkt")
p.append_item("test1", 8, :UINT)
p.get_item("TEST1").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST1")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.enable_limits("TEST1")
p.append_item("test2", 16, :UINT)
p.get_item("TEST2").limits.values = {:DEFAULT=>[1,2,4,5]}
i = p.get_item("TEST2")
i.limits.values = {:DEFAULT=>[1,2,4,5]}
p.update_limits_items_cache(i)
p.enable_limits("TEST2")
p.update_limits_items_cache
expect(p.out_of_limits).to eql []

expect(p.stale).to be_truthy
Expand Down

0 comments on commit 8403d38

Please sign in to comment.