Class: Benelux::Timeline
Overview
|------+----+--+----+----|
|
0.02
- Usage examples
Benelux.timeline.each do |mark|
p [mark.track, mark.name, mark.tags[:usecase], mark.tags[:call_id]]
end
Benelux.timeline.ranges(:do_request).each do |range|
puts "Client%s: %s: %s: %f" % [range.track, range.thread_id, range.name, range.duration]
end
regions = Benelux.timeline(track_id).regions(:execute)
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#+(other) ⇒ Object
-
#[](*tags) ⇒ Object
-
#add_count(name, count, tags = {}) ⇒ Object
-
#add_default_tags(tags = Selectable::Tags.new) ⇒ Object
(also: #add_default_tag)
-
#add_mark(name) ⇒ Object
-
#add_message(msg, tags = {}) ⇒ Object
msg is the message to store.
-
#add_range(name, from, to) ⇒ Object
-
#clear ⇒ Object
-
#dump ⇒ Object
-
#duration ⇒ Object
-
#each(*args, &blk) ⇒ Object
-
#initialize(*args) ⇒ Timeline
constructor
A new instance of Timeline.
-
#marks(*names) ⇒ Object
obj.marks(:execute_a, :execute_z, :do_request_a) => [:execute_a, :do_request_a, :do_request_a, :execute_z].
-
#merge!(*timelines) ⇒ Object
-
#regions(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.regions(:do_request) =>.
-
#remove_default_tags(*tags) ⇒ Object
-
#track ⇒ Object
Methods included from Selectable
#filter, #filter!, included, normalize, #rfilter, #tags
Constructor Details
#initialize(*args) ⇒ Timeline
Returns a new instance of Timeline.
Instance Attribute Details
Returns the value of attribute caller.
26
27
28
|
# File 'lib/benelux/timeline.rb', line 26
def caller
@caller
end
|
Returns the value of attribute default_tags.
25
26
27
|
# File 'lib/benelux/timeline.rb', line 25
def default_tags
@default_tags
end
|
#messages(tags = Selectable::Tags.new) ⇒ Object
Returns the value of attribute messages.
24
25
26
|
# File 'lib/benelux/timeline.rb', line 24
def messages
@messages
end
|
#ranges(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.ranges(:do_request) =>
[[:do_request_a, :do_request_z], [:do_request_a, ...]]
96
97
98
|
# File 'lib/benelux/timeline.rb', line 96
def ranges
@ranges
end
|
Returns the value of attribute stats.
23
24
25
|
# File 'lib/benelux/timeline.rb', line 23
def stats
@stats
end
|
Instance Method Details
192
193
194
195
196
197
198
|
# File 'lib/benelux/timeline.rb', line 192
def +(other)
self.push *other
@ranges.push *other.ranges
@messages.push *tl.messages
@stats += other.stats
self
end
|
#[](*tags) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/benelux/timeline.rb', line 77
def [](*tags)
tl = super
tl.ranges = @ranges.select do |region|
region.tags >= tags
end
stats = Benelux::Stats.new
@stats.each do |stat|
next unless stat.tags >= tags
stats += stat
end
tl.messages = messages
tl.stats = stats
tl
end
|
#add_count(name, count, tags = {}) ⇒ Object
157
158
159
160
161
162
|
# File 'lib/benelux/timeline.rb', line 157
def add_count(name, count, tags={})
tags = tags.merge self.default_tags
self.stats.add_group(name)
self.stats.sample(name, count, tags)
count
end
|
36
37
38
|
# File 'lib/benelux/timeline.rb', line 36
def add_default_tags(tags=Selectable::Tags.new)
@default_tags.merge! tags
end
|
#add_mark(name) ⇒ Object
164
165
166
167
168
169
|
# File 'lib/benelux/timeline.rb', line 164
def add_mark(name)
mark = Benelux::Mark.now(name)
mark.add_tags self.default_tags
self << mark
mark
end
|
#add_message(msg, tags = {}) ⇒ Object
msg is the message to store. This can be any type of
object that includes Selectable::Object (so that tags
can be added to the message to retreive it later). If
msg does not include Selectable::Object it will be
converted to a TaggableString object.
147
148
149
150
151
152
153
154
155
|
# File 'lib/benelux/timeline.rb', line 147
def add_message(msg, tags={})
unless msg.kind_of?(Selectable::Object)
msg = TaggableString.new msg.to_s
end
msg.add_tags self.default_tags
msg.add_tags tags
@messages << msg
msg
end
|
#add_range(name, from, to) ⇒ Object
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/benelux/timeline.rb', line 171
def add_range(name, from, to)
range = Benelux::Range.new(name, from, to)
range.add_tags self.default_tags
range.add_tags from.tags
range.add_tags to.tags
self.ranges << range
self.stats.add_group(name)
self.stats.sample(name, range.duration, range.tags)
range
end
|
135
136
137
138
139
140
|
# File 'lib/benelux/timeline.rb', line 135
def clear
@ranges.clear
@stats.clear
@messages.clear
super
end
|
48
49
50
|
# File 'lib/benelux/timeline.rb', line 48
def dump
end
|
52
53
54
55
|
# File 'lib/benelux/timeline.rb', line 52
def duration
return 0 if self.last.nil?
self.last - self.first
end
|
#each(*args, &blk) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/benelux/timeline.rb', line 57
def each(*args, &blk)
if args.empty?
super(&blk)
else
self.marks(*args).each(&blk)
end
end
|
#marks(*names) ⇒ Object
obj.marks(:execute_a, :execute_z, :do_request_a) =>
[:execute_a, :do_request_a, :do_request_a, :execute_z]
69
70
71
72
73
74
75
|
# File 'lib/benelux/timeline.rb', line 69
def marks(*names)
return self if names.empty?
names = names.flatten.collect { |n| n.to_s }
self.select do |mark|
names.member? mark.name.to_s
end
end
|
#merge!(*timelines) ⇒ Object
182
183
184
185
186
187
188
189
190
|
# File 'lib/benelux/timeline.rb', line 182
def merge!(*timelines)
timelines.each do |tl|
self.push *tl
@ranges.push *tl.ranges
@messages.push *tl.messages
@stats += tl.stats
end
self
end
|
#regions(name = nil, tags = Selectable::Tags.new) ⇒ Object
obj.regions(:do_request) =>
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/benelux/timeline.rb', line 109
def regions(name=nil, tags=Selectable::Tags.new)
return self if name.nil?
self.ranges(name, tags).collect do |base_range|
marks = self.sort.select do |mark|
mark >= base_range.from &&
mark <= base_range.to &&
mark.tags >= base_range.tags
end
ranges = self.ranges.select do |range|
range.from >= base_range.from &&
range.to <= base_range.to &&
range.tags >= base_range.tags
end
tl = Benelux::Timeline.new(marks)
tl.ranges = ranges.sort
tl
end
end
|
40
41
42
|
# File 'lib/benelux/timeline.rb', line 40
def remove_default_tags(*tags)
@default_tags.delete_if { |n,v| tags.member?(n) }
end
|
44
45
46
|
# File 'lib/benelux/timeline.rb', line 44
def track
@default_tags[:track]
end
|