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.6.1"
- 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_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, timeline = 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
-
.merge_tracks ⇒ Object
-
.packed_method(klass, meth) ⇒ Object
-
.packed_method?(klass, meth) ⇒ Boolean
-
.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_timer(klass, meth, aliaz = nil, &blk) ⇒ Object
148
149
150
151
152
|
# File 'lib/benelux.rb', line 148
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
226
227
228
229
230
231
232
233
234
|
# File 'lib/benelux.rb', line 226
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, timeline = 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
|
# File 'lib/benelux.rb', line 69
def Benelux.current_track(name=nil,timeline=nil)
if name.nil?
name = Thread.current.track_name
else
Thread.current.track_name = name
@@mutex.synchronize do
@tracks[name] ||= Track.new(name, timeline || Thread.current.timeline || Benelux::Timeline.new)
@tracks[name].add_thread Thread.current
@known_threads << Thread.current
end
end
Benelux.track(name)
end
|
.debug? ⇒ Boolean
166
|
# File 'lib/benelux.rb', line 166
def Benelux.debug?; @@debug; end
|
.disable_debug ⇒ Object
165
|
# File 'lib/benelux.rb', line 165
def Benelux.disable_debug; @@debug = false; end
|
.enable_debug ⇒ Object
164
|
# File 'lib/benelux.rb', line 164
def Benelux.enable_debug; @@debug = true; end
|
124
125
126
127
128
|
# File 'lib/benelux.rb', line 124
def Benelux.inspect
str = ["Benelux"]
str << "tracks:" << Benelux.tracks.inspect
str.join $/
end
|
.known_thread?(t = Thread.current) ⇒ Boolean
159
160
161
|
# File 'lib/benelux.rb', line 159
def Benelux.ld(*msg)
@@logger.puts "D: " << msg.join("#{$/}D: ") if debug?
end
|
.merge_tracks ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/benelux.rb', line 84
def Benelux.merge_tracks
tl = Benelux::Timeline.new
tracks.each_pair do |trackid,track|
tl.merge! track.timeline
end
tl
end
|
.packed_method(klass, meth) ⇒ Object
.packed_method?(klass, meth) ⇒ Boolean
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
130
131
132
|
# File 'lib/benelux.rb', line 130
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.
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/benelux.rb', line 94
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
|