Module Benelux

  1. lib/benelux/mark.rb
  2. lib/benelux/packer.rb
  3. lib/benelux/range.rb
  4. lib/benelux/stats.rb
  5. lib/benelux/timeline.rb
  6. lib/benelux/track.rb
  7. lib/benelux.rb
  8. show all

Constants

VERSION = "0.6.1"
NOTSUPPORTED = [Class, Object, Kernel]

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)
[show source]
     # File lib/benelux.rb, line 154
154:   def Benelux.add_counter klass, meth, aliaz=nil, &blk
155:     raise NotSupported, klass unless Benelux.supported? klass
156:     Benelux::MethodCounter.new klass, meth, aliaz, &blk
157:   end
add_timer (klass, meth, aliaz=nil, &blk)
[show source]
     # File lib/benelux.rb, line 148
148:   def Benelux.add_timer klass, meth, aliaz=nil, &blk
149:     raise NotSupported, klass unless Benelux.supported? klass
150:     raise AlreadyTimed, klass if Benelux.packed_method? klass, meth
151:     Benelux::MethodTimer.new klass, meth, aliaz, &blk
152:   end
bm (n=1, reps=5, &blk)

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

[show source]
     # File lib/benelux.rb, line 226
226:   def Benelux.bm(n=1, reps=5, &blk) 
227:     require 'benchmark'
228:     n.times &blk
229:     tms = Benelux::Tms.new
230:     reps.times do |rep|
231:       tms.sample Benchmark.measure() {n.times &blk}
232:     end
233:     tms
234:   end
current_track (name=nil,timeline=nil)

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.

[show source]
    # File lib/benelux.rb, line 69
69:   def Benelux.current_track(name=nil,timeline=nil)
70:     if name.nil?
71:       name = Thread.current.track_name
72:     else
73:       Thread.current.track_name = name
74:       @@mutex.synchronize do
75:         @tracks[name] ||= Track.new(name, timeline || Thread.current.timeline || Benelux::Timeline.new)
76:         @tracks[name].add_thread Thread.current
77:         @known_threads << Thread.current
78:       end
79:     end
80:     Benelux.track(name)
81:   end
debug? ()
[show source]
     # File lib/benelux.rb, line 166
166:   def Benelux.debug?; @@debug; end
disable_debug ()
[show source]
     # File lib/benelux.rb, line 165
165:   def Benelux.disable_debug; @@debug = false; end
enable_debug ()
[show source]
     # File lib/benelux.rb, line 164
164:   def Benelux.enable_debug; @@debug = true; end
inspect ()
[show source]
     # File lib/benelux.rb, line 124
124:   def Benelux.inspect
125:     str = ["Benelux"]
126:     str << "tracks:" << Benelux.tracks.inspect
127:     str.join $/
128:   end
known_thread? (t=Thread.current)
[show source]
     # File lib/benelux.rb, line 135
135:   def Benelux.known_thread?(t=Thread.current)
136:     Benelux.known_threads.member? t
137:   end
ld (*msg)
[show source]
     # File lib/benelux.rb, line 159
159:   def Benelux.ld(*msg)
160:     @@logger.puts "D:  " << msg.join("#{$/}D:  ") if debug?
161:   end
merge_tracks ()
[show source]
    # File lib/benelux.rb, line 84
84:   def Benelux.merge_tracks
85:     tl = Benelux::Timeline.new
86:     tracks.each_pair do |trackid,track|
87:       tl.merge! track.timeline
88:     end
89:     tl
90:   end
packed_method (klass, meth)
[show source]
     # File lib/benelux.rb, line 139
139:   def Benelux.packed_method(klass, meth)
140:     return nil unless defined?(Benelux.packed_methods[klass][meth])
141:     Benelux.packed_methods[klass][meth]
142:   end
packed_method? (klass, meth)
[show source]
     # File lib/benelux.rb, line 144
144:   def Benelux.packed_method? klass, meth
145:     !Benelux.packed_method(klass, meth).nil?
146:   end
reset ()
[show source]
    # File lib/benelux.rb, line 35
35:   def Benelux.reset
36:     @tracks = SelectableHash.new
37:     @timeline = Timeline.new
38:     @timeline_chunk = Timeline.new  # See: update_global_timeline
39:     @timeline_updates = 0
40:     @known_threads = []
41:     @processed_dead_threads = []
42:   end
supported? (klass)
[show source]
     # File lib/benelux.rb, line 130
130:   def Benelux.supported?(klass)
131:     !NOTSUPPORTED.member?(klass)
132:   end
thread_timeline ()
[show source]
    # File lib/benelux.rb, line 49
49:   def Benelux.thread_timeline
50:     Thread.current.timeline
51:   end
track (name)
[show source]
    # File lib/benelux.rb, line 53
53:   def Benelux.track(name)
54:     raise UnknownTrack unless track? name
55:     @tracks[name]
56:   end
track? (name)
[show source]
    # File lib/benelux.rb, line 58
58:   def Benelux.track?(name)
59:     @tracks.has_key? name
60:   end
update_global_timeline ()

Only updates data from threads that are dead and rotated timelines.

[show source]
     # File lib/benelux.rb, line 94
 94:   def Benelux.update_global_timeline
 95:     @@mutex.synchronize do
 96:       dthreads = Benelux.known_threads.select { |t| 
 97:         !t.timeline.nil? && (t.nil? || !t.status) &&
 98:         !@processed_dead_threads.member?(t)
 99:       }
100:       # Threads that have rotated timelines
101:       rthreads = Benelux.known_threads.select { |t|
102:         !t.rotated_timelines.empty?
103:       }
104:       dtimelines = dthreads.collect { |t| t.timeline }
105:       # Also get all rotated timelines. 
106:       rthreads.each { |t| 
107:         # We loop carefully through the rotated timelines
108:         # incase something was added while we're working. 
109:         while !t.rotated_timelines.empty?
110:           dtimelines.push t.rotated_timelines.shift 
111:         end
112:       }
113:       Benelux.ld [:update_global_timeline, dthreads.size, rthreads.size, dtimelines.size].inspect
114:       # Keep track of this update separately
115:       @timeline_chunk = Benelux::Timeline.new
116:       @timeline_chunk.merge! *dtimelines
117:       @processed_dead_threads.push *dthreads
118:       tl = Benelux.timeline.merge! Benelux.timeline_chunk
119:       @timeline_updates += 1
120:       tl
121:     end
122:   end