# 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
# 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
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
# 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
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
# File lib/benelux.rb, line 165 def Benelux.disable_debug; @@debug = false; end
# File lib/benelux.rb, line 164 def Benelux.enable_debug; @@debug = true; end
# File lib/benelux.rb, line 124 def Benelux.inspect str = ["Benelux"] str << "tracks:" << Benelux.tracks.inspect str.join $/ end
# File lib/benelux.rb, line 135 def Benelux.known_thread?(t=Thread.current) Benelux.known_threads.member? t end
# File lib/benelux.rb, line 159 def Benelux.ld(*msg) @@logger.puts "D: " << msg.join("#{$/}D: ") if debug? end
# 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
# 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
# File lib/benelux.rb, line 144 def Benelux.packed_method? klass, meth !Benelux.packed_method(klass, meth).nil? end
# 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
# File lib/benelux.rb, line 130 def Benelux.supported?(klass) !NOTSUPPORTED.member?(klass) end
# File lib/benelux.rb, line 49 def Benelux.thread_timeline Thread.current.timeline end
# File lib/benelux.rb, line 53 def Benelux.track(name) raise UnknownTrack unless track? name @tracks[name] end
# File lib/benelux.rb, line 58 def Benelux.track?(name) @tracks.has_key? name end
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
Generated with the Darkfish Rdoc Generator 2.