Class: Roby::DRoby::Timepoints::CTF
- Defined in:
- lib/roby/droby/timepoints_ctf.rb
Constant Summary collapse
- ID_TIMEPOINT =
1- ID_GROUP_START =
2- ID_GROUP_END =
3
Instance Attribute Summary collapse
-
#clock_base ⇒ Object
readonly
Returns the value of attribute clock_base.
-
#name_to_addr_mapping ⇒ Object
readonly
Returns the value of attribute name_to_addr_mapping.
-
#packet_contents ⇒ Object
readonly
Returns the value of attribute packet_contents.
-
#packet_timestamp_begin ⇒ Object
readonly
Returns the value of attribute packet_timestamp_begin.
-
#packet_timestamp_end ⇒ Object
readonly
Returns the value of attribute packet_timestamp_end.
-
#thread_ids ⇒ Object
readonly
Returns the value of attribute thread_ids.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #add(time, thread_id, thread_name, name) ⇒ Object
- #addr_from_name(name) ⇒ Object
- #generate_metadata ⇒ Object
- #group_end(time, thread_id, thread_name, name) ⇒ Object
- #group_start(time, thread_id, thread_name, name) ⇒ Object
-
#initialize(clock_base: 0) ⇒ CTF
constructor
A new instance of CTF.
- #make_timestamp(time) ⇒ Object
- #marshal_event(time, event_id, thread_id, thread_name, name) ⇒ Object
- #marshal_packet ⇒ Object
- #metadata_template_path ⇒ Object
- #save(path) ⇒ Object
- #thread_id_of(thread_id) ⇒ Object
- #update_packet(time, marshalled_event) ⇒ Object
Constructor Details
#initialize(clock_base: 0) ⇒ CTF
Returns a new instance of CTF.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 17 def initialize(clock_base: 0) @uuid = SecureRandom.random_bytes(16).unpack("C*") @clock_base = clock_base = nil = nil @packet_contents = String.new @name_to_addr_mapping = Hash.new @thread_ids = Hash.new end |
Instance Attribute Details
#clock_base ⇒ Object (readonly)
Returns the value of attribute clock_base.
8 9 10 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 8 def clock_base @clock_base end |
#name_to_addr_mapping ⇒ Object (readonly)
Returns the value of attribute name_to_addr_mapping.
9 10 11 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 9 def name_to_addr_mapping @name_to_addr_mapping end |
#packet_contents ⇒ Object (readonly)
Returns the value of attribute packet_contents.
13 14 15 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 13 def packet_contents @packet_contents end |
#packet_timestamp_begin ⇒ Object (readonly)
Returns the value of attribute packet_timestamp_begin.
11 12 13 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 11 def end |
#packet_timestamp_end ⇒ Object (readonly)
Returns the value of attribute packet_timestamp_end.
12 13 14 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 12 def end |
#thread_ids ⇒ Object (readonly)
Returns the value of attribute thread_ids.
15 16 17 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 15 def thread_ids @thread_ids end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 7 def uuid @uuid end |
Class Method Details
.generate_metadata(path, _uuid, _clock_base) ⇒ Object
68 69 70 71 72 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 68 def self.(path, _uuid, _clock_base) _uuid_s = _uuid.map { |v| "%02x" % v }.join _uuid_s = "#{_uuid_s[0, 8]}-#{_uuid_s[8, 4]}-#{_uuid_s[12, 4]}-#{_uuid_s[16, 4]}-#{_uuid_s[20, 12]}" ERB.new(path.read).result(binding) end |
Instance Method Details
#add(time, thread_id, thread_name, name) ⇒ Object
64 65 66 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 64 def add(time, thread_id, thread_name, name) update_packet(time, marshal_event(time, ID_TIMEPOINT, thread_id_of(thread_id), thread_name, name)) end |
#addr_from_name(name) ⇒ Object
33 34 35 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 33 def addr_from_name(name) name_to_addr_mapping[name] ||= name_to_addr_mapping.size end |
#generate_metadata ⇒ Object
78 79 80 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 78 def self.class.(, uuid, clock_base) end |
#group_end(time, thread_id, thread_name, name) ⇒ Object
60 61 62 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 60 def group_end(time, thread_id, thread_name, name) update_packet(time, marshal_event(time, ID_GROUP_END, thread_id_of(thread_id), thread_name, name)) end |
#group_start(time, thread_id, thread_name, name) ⇒ Object
55 56 57 58 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 55 def group_start(time, thread_id, thread_name, name) marshalled = marshal_event(time, ID_GROUP_START, thread_id_of(thread_id), thread_name, name) update_packet(time, marshalled + [addr_from_name(name)].pack("L<")) end |
#make_timestamp(time) ⇒ Object
29 30 31 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 29 def (time) (time.tv_sec - clock_base) * 1_000_000 + time.tv_usec end |
#marshal_event(time, event_id, thread_id, thread_name, name) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 82 def marshal_event(time, event_id, thread_id, thread_name, name) = (time) event_header = [0xFFFF, event_id, (time)].pack("S<L<Q<") thread_name ||= '' event_context = [thread_id, thread_name.size, thread_name, name.size, name].pack("L<S<A#{thread_name.size}S<A#{name.size}") event_header + event_context end |
#marshal_packet ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 90 def marshal_packet header = [ 0xC1FC1FC1, # Magic *uuid, 0 # Stream ID ].pack("L<C16L<") contents = packet_contents context = [ (), (), 0].pack("Q<Q<L<") = nil = nil @packet_contents = String.new header + context + contents end |
#metadata_template_path ⇒ Object
74 75 76 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 74 def Pathname.new(__FILE__).dirname + "timepoints_ctf.metadata.erb" end |
#save(path) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 108 def save(path) (path + "metadata").open('w') do |io| io.write end (path + "channel0_0").open('w') do |io| io.write marshal_packet end path.sub_ext('.ctf.names').open('w') do |io| name_to_addr_mapping.each do |name, id| io.puts("%016x T %s" % [id, name.gsub(/[^\w]/, '_')]) end end end |
#thread_id_of(thread_id) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 47 def thread_id_of(thread_id) if id = thread_ids[thread_id] id else thread_ids[thread_id] = thread_ids.size end end |
#update_packet(time, marshalled_event) ⇒ Object
41 42 43 44 45 |
# File 'lib/roby/droby/timepoints_ctf.rb', line 41 def update_packet(time, marshalled_event) ||= time = time packet_contents << marshalled_event end |