Class: Syskit::NetworkGeneration::PortDynamics
- Defined in:
- lib/syskit/network_generation/dataflow_dynamics.rb
Overview
A representation of the actual dynamics of a port
At the last stages, the Engine object will try to create and update PortDynamics for each known ports.
The PortDynamics objects maintain a list of so-called 'triggers'. One trigger represents a single periodic event on a port (i.e. reception on an input port and emission on an output port). It states that the port will receive/send Trigger#sample_count samples at a period of Trigger#period. If period is zero, it means that it will happend “every once in a while”.
A sample is virtual: it is not an actual data sample on the connection. The translation between both is given by PortDynamics#sample_size.
Defined Under Namespace
Classes: Trigger
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the port we are computing dynamics for.
-
#sample_size ⇒ Object
readonly
The number of data samples per trigger, if the port's model value needs to be overriden.
-
#triggers ⇒ Object
readonly
The set of registered triggers for this port, as a list of Trigger objects, where
period
is in seconds and sample_count is the count of samples sent atperiod
intervals.
Instance Method Summary collapse
- #add_trigger(name, period, sample_count) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name, sample_size = 1) ⇒ PortDynamics
constructor
A new instance of PortDynamics.
- #merge(other_dynamics) ⇒ Object
- #minimal_period ⇒ Object
- #pretty_print(pp) ⇒ Object
- #queue_size(duration) ⇒ Object
- #sample_count(duration) ⇒ Object
- #sampled_at(duration) ⇒ Object
Constructor Details
#initialize(name, sample_size = 1) ⇒ PortDynamics
Returns a new instance of PortDynamics
78 79 80 81 82 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 78 def initialize(name, sample_size = 1) @name = name @sample_size = sample_size.to_int @triggers = Set.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the port we are computing dynamics for. This is used for debugging purposes only
46 47 48 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 46 def name @name end |
#sample_size ⇒ Object (readonly)
The number of data samples per trigger, if the port's model value needs to be overriden
49 50 51 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 49 def sample_size @sample_size end |
#triggers ⇒ Object (readonly)
The set of registered triggers for this port, as a list of Trigger objects,
where period
is in seconds and sample_count is the count of
samples sent at period
intervals
53 54 55 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 53 def triggers @triggers end |
Instance Method Details
#add_trigger(name, period, sample_count) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 86 def add_trigger(name, period, sample_count) if sample_count != 0 DataFlowDynamics.debug { " [#{self.name}]: adding trigger from #{name} - #{period} #{sample_count}" } triggers << Trigger.new(name, period, sample_count) end end |
#empty? ⇒ Boolean
84 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 84 def empty?; triggers.empty? end |
#merge(other_dynamics) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 93 def merge(other_dynamics) DataFlowDynamics.debug do DataFlowDynamics.debug "adding triggers from #{other_dynamics.name} to #{name}" DataFlowDynamics.log_nest(4) do DataFlowDynamics.log_pp(:debug, other_dynamics) end break end triggers.merge(other_dynamics.triggers) true end |
#minimal_period ⇒ Object
105 106 107 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 105 def minimal_period triggers.map(&:period).min end |
#pretty_print(pp) ⇒ Object
130 131 132 133 134 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 130 def pretty_print(pp) pp.seplist(triggers) do |tr| pp.text "(#{tr.name}): #{tr.period} #{tr.sample_count}" end end |
#queue_size(duration) ⇒ Object
126 127 128 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 126 def queue_size(duration) (1 + sample_count(duration)) * sample_size end |
#sample_count(duration) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 116 def sample_count(duration) triggers.map do |trigger| if trigger.period == 0 trigger.sample_count else (duration/trigger.period).floor * trigger.sample_count end end.inject(&:+) end |
#sampled_at(duration) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/syskit/network_generation/dataflow_dynamics.rb', line 109 def sampled_at(duration) result = PortDynamics.new(name, sample_size) names = triggers.map(&:name) result.add_trigger("#{name}.resample(#{names.join(",")},#{duration})", duration, queue_size(duration)) result end |