Module: Benelux
- Defined in:
- lib/benelux.rb,
lib/benelux/mark.rb,
lib/benelux/range.rb,
lib/benelux/stats.rb,
lib/benelux/track.rb,
lib/benelux/packer.rb,
lib/benelux/timeline.rb
Defined Under Namespace
Classes: AlreadyTimed, BadRecursion, BeneluxError, Mark, MethodCounter, MethodPacker, MethodTimer, NotSupported, Range, Stats, Timeline, Tms, Track, UnknownTrack
Constant Summary
collapse
- VERSION =
"0.5.17"
- NOTSUPPORTED =
[Class, Object, Kernel]
- @@mutex =
Mutex.new
- @@debug =
false
- @@logger =
STDERR
Class Attribute Summary collapse
Class Method Summary
collapse
-
.add_counter(klass, meth, aliaz = nil, &blk) ⇒ Object
-
.add_thread_tag(*args) ⇒ Object
-
.add_thread_tags(args = Selectable::Tags.new) ⇒ Object
Thread tags become the default for any new Mark or Range.
-
.add_timer(klass, meth, aliaz = nil, &blk) ⇒ Object
-
.bm(n = 1, reps = 5, &blk) ⇒ Object
Run a benchmark the healthy way: with a warmup run, with multiple repetitions, and standard deviation.
-
.current_track(name = nil, group = nil) ⇒ Object
If name
is specified, this will associate the current thread with that Track name
(the Track will be created if necessary).
-
.debug? ⇒ Boolean
-
.disable_debug ⇒ Object
-
.enable_debug ⇒ Object
-
.inspect ⇒ Object
-
.known_thread?(t = Thread.current) ⇒ Boolean
-
.ld(*msg) ⇒ Object
-
.packed_method(klass, meth) ⇒ Object
-
.packed_method?(klass, meth) ⇒ Boolean
-
.remove_thread_tag(*args) ⇒ Object
-
.remove_thread_tags(*args) ⇒ Object
-
.reset ⇒ Object
-
.supported?(klass) ⇒ Boolean
-
.thread_timeline ⇒ Object
-
.track(name) ⇒ Object
-
.track?(name) ⇒ Boolean
-
.update_global_timeline ⇒ Object
Only updates data from threads that are dead and rotated timelines.
Class Attribute Details
.known_threads ⇒ Object
Returns the value of attribute known_threads.
32
33
34
|
# File 'lib/benelux.rb', line 32
def known_threads
@known_threads
end
|
.packed_methods ⇒ Object
Returns the value of attribute packed_methods.
27
28
29
|
# File 'lib/benelux.rb', line 27
def packed_methods
@packed_methods
end
|
Returns the value of attribute timeline.
29
30
31
|
# File 'lib/benelux.rb', line 29
def timeline
@timeline
end
|
.timeline_chunk ⇒ Object
Returns the value of attribute timeline_chunk.
30
31
32
|
# File 'lib/benelux.rb', line 30
def timeline_chunk
@timeline_chunk
end
|
.timeline_updates ⇒ Object
Returns the value of attribute timeline_updates.
31
32
33
|
# File 'lib/benelux.rb', line 31
def timeline_updates
@timeline_updates
end
|
Returns the value of attribute tracks.
28
29
30
|
# File 'lib/benelux.rb', line 28
def tracks
@tracks
end
|
Class Method Details
.add_counter(klass, meth, aliaz = nil, &blk) ⇒ Object
.add_thread_tag(*args) ⇒ Object
122
|
# File 'lib/benelux.rb', line 122
def Benelux.add_thread_tag(*args) add_thread_tags *args end
|
Thread tags become the default for any new Mark or Range.
119
120
121
|
# File 'lib/benelux.rb', line 119
def Benelux.add_thread_tags(args=Selectable::Tags.new)
Benelux.thread_timeline.add_default_tags args
end
|
.add_timer(klass, meth, aliaz = nil, &blk) ⇒ Object
154
155
156
157
158
|
# File 'lib/benelux.rb', line 154
def Benelux.add_timer klass, meth, aliaz=nil, &blk
raise NotSupported, klass unless Benelux.supported? klass
raise AlreadyTimed, klass if Benelux.packed_method? klass, meth
Benelux::MethodTimer.new klass, meth, aliaz, &blk
end
|
.bm(n = 1, reps = 5, &blk) ⇒ Object
Run a benchmark the healthy way: with a warmup run, with multiple repetitions, and standard deviation.
-
n
Number of times to execute blk
(one data sample)
-
reps
Number of data samples to collect
-
blk
a Ruby block to benchmark
Returns a Benelux::Tms object
232
233
234
235
236
237
238
239
240
|
# File 'lib/benelux.rb', line 232
def Benelux.bm(n=1, reps=5, &blk)
require 'benchmark'
n.times &blk
tms = Benelux::Tms.new
reps.times do |rep|
tms.sample Benchmark.measure() {n.times &blk}
end
tms
end
|
.current_track(name = nil, group = nil) ⇒ Object
If name
is specified, this will associate the current thread with that Track name
(the Track will be created if necessary).
If track
is nil, it returns the Track object for the Track associated to the current thread.
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/benelux.rb', line 69
def Benelux.current_track(name=nil,group=nil)
if name.nil?
name = Thread.current.track_name
else
Thread.current.track_name = name
@@mutex.synchronize do
Thread.current.timeline ||= Benelux::Timeline.new
Thread.current.rotated_timelines ||= []
@tracks[name] ||= Track.new(name, group)
@tracks[name].add_thread Thread.current
@known_threads << Thread.current
end
end
Benelux.track(name)
end
|
.debug? ⇒ Boolean
172
|
# File 'lib/benelux.rb', line 172
def Benelux.debug?; @@debug; end
|
.disable_debug ⇒ Object
171
|
# File 'lib/benelux.rb', line 171
def Benelux.disable_debug; @@debug = false; end
|
.enable_debug ⇒ Object
170
|
# File 'lib/benelux.rb', line 170
def Benelux.enable_debug; @@debug = true; end
|
130
131
132
133
134
|
# File 'lib/benelux.rb', line 130
def Benelux.inspect
str = ["Benelux"]
str << "tracks:" << Benelux.tracks.inspect
str.join $/
end
|
.known_thread?(t = Thread.current) ⇒ Boolean
165
166
167
|
# File 'lib/benelux.rb', line 165
def Benelux.ld(*msg)
@@logger.puts "D: " << msg.join("#{$/}D: ") if debug?
end
|
.packed_method(klass, meth) ⇒ Object
.packed_method?(klass, meth) ⇒ Boolean
.remove_thread_tag(*args) ⇒ Object
127
|
# File 'lib/benelux.rb', line 127
def Benelux.remove_thread_tag(*args) remove_thread_tags *args end
|
35
36
37
38
39
40
41
42
|
# File 'lib/benelux.rb', line 35
def Benelux.reset
@tracks = SelectableHash.new
@timeline = Timeline.new
@timeline_chunk = Timeline.new @timeline_updates = 0
@known_threads = []
@processed_dead_threads = []
end
|
.supported?(klass) ⇒ Boolean
136
137
138
|
# File 'lib/benelux.rb', line 136
def Benelux.supported?(klass)
!NOTSUPPORTED.member?(klass)
end
|
.thread_timeline ⇒ Object
49
50
51
|
# File 'lib/benelux.rb', line 49
def Benelux.thread_timeline
Thread.current.timeline
end
|
.track(name) ⇒ Object
53
54
55
56
|
# File 'lib/benelux.rb', line 53
def Benelux.track(name)
raise UnknownTrack unless track? name
@tracks[name]
end
|
.track?(name) ⇒ Boolean
58
59
60
|
# File 'lib/benelux.rb', line 58
def Benelux.track?(name)
@tracks.has_key? name
end
|
.update_global_timeline ⇒ Object
Only updates data from threads that are dead and rotated timelines.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/benelux.rb', line 88
def Benelux.update_global_timeline
@@mutex.synchronize do
dthreads = Benelux.known_threads.select { |t|
!t.timeline.nil? && (t.nil? || !t.status) &&
!@processed_dead_threads.member?(t)
}
rthreads = Benelux.known_threads.select { |t|
!t.rotated_timelines.empty?
}
dtimelines = dthreads.collect { |t| t.timeline }
rthreads.each { |t|
while !t.rotated_timelines.empty?
dtimelines.push t.rotated_timelines.shift
end
}
Benelux.ld [:update_global_timeline, dthreads.size, rthreads.size, dtimelines.size].inspect
@timeline_chunk = Benelux::Timeline.new
@timeline_chunk.merge! *dtimelines
@processed_dead_threads.push *dthreads
tl = Benelux.timeline.merge! Benelux.timeline_chunk
@timeline_updates += 1
tl
end
end
|