module Benelux
Constants
- NOTSUPPORTED
- VERSION
Attributes
known_threads[R]
packed_methods[R]
timeline[R]
timeline_chunk[R]
timeline_updates[R]
tracks[R]
Public Class Methods
add_counter(klass, meth, aliaz=nil, &blk)
click to toggle source
# File lib/benelux.rb, line 154 def Benelux.add_counter klass, meth, aliaz=nil, &blk raise NotSupported, klass unless Benelux.supported? klass Benelux::MethodCounter.new klass, meth, aliaz, &blk end
add_timer(klass, meth, aliaz=nil, &blk)
click to toggle source
# 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)
click to toggle source
Run a benchmark the healthy way: with a warmup run, with multiple repetitions, and standard deviation.
-
n
Number of times to executeblk
(one data sample) -
reps
Number of data samples to collect -
blk
a Ruby block to benchmark
Returns a Benelux::Tms object
# 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)
click to toggle source
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.
# 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?()
click to toggle source
# File lib/benelux.rb, line 166 def Benelux.debug?; @@debug; end
disable_debug()
click to toggle source
# File lib/benelux.rb, line 165 def Benelux.disable_debug; @@debug = false; end
enable_debug()
click to toggle source
# File lib/benelux.rb, line 164 def Benelux.enable_debug; @@debug = true; end
inspect()
click to toggle source
# File lib/benelux.rb, line 124 def Benelux.inspect str = ["Benelux"] str << "tracks:" << Benelux.tracks.inspect str.join $/ end
known_thread?(t=Thread.current)
click to toggle source
# File lib/benelux.rb, line 135 def Benelux.known_thread?(t=Thread.current) Benelux.known_threads.member? t end
ld(*msg)
click to toggle source
# File lib/benelux.rb, line 159 def Benelux.ld(*msg) @@logger.puts "D: " << msg.join("#{$/}D: ") if debug? end
merge_tracks()
click to toggle source
# 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)
click to toggle source
# File lib/benelux.rb, line 139 def Benelux.packed_method(klass, meth) return nil unless defined?(Benelux.packed_methods[klass][meth]) Benelux.packed_methods[klass][meth] end
packed_method?(klass, meth)
click to toggle source
# File lib/benelux.rb, line 144 def Benelux.packed_method? klass, meth !Benelux.packed_method(klass, meth).nil? end
reset()
click to toggle source
# File lib/benelux.rb, line 35 def Benelux.reset @tracks = SelectableHash.new @timeline = Timeline.new @timeline_chunk = Timeline.new # See: update_global_timeline @timeline_updates = 0 @known_threads = [] @processed_dead_threads = [] end
supported?(klass)
click to toggle source
# File lib/benelux.rb, line 130 def Benelux.supported?(klass) !NOTSUPPORTED.member?(klass) end
thread_timeline()
click to toggle source
# File lib/benelux.rb, line 49 def Benelux.thread_timeline Thread.current.timeline end
track(name)
click to toggle source
# File lib/benelux.rb, line 53 def Benelux.track(name) raise UnknownTrack unless track? name @tracks[name] end
track?(name)
click to toggle source
# File lib/benelux.rb, line 58 def Benelux.track?(name) @tracks.has_key? name end
update_global_timeline()
click to toggle source
Only updates data from threads that are dead and rotated timelines.
# 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) } # Threads that have rotated timelines rthreads = Benelux.known_threads.select { |t| !t.rotated_timelines.empty? } dtimelines = dthreads.collect { |t| t.timeline } # Also get all rotated timelines. rthreads.each { |t| # We loop carefully through the rotated timelines # incase something was added while we're working. while !t.rotated_timelines.empty? dtimelines.push t.rotated_timelines.shift end } Benelux.ld [:update_global_timeline, dthreads.size, rthreads.size, dtimelines.size].inspect # Keep track of this update separately @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