Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

0.6.0 (Thread now belongs to Track)

  • Loading branch information...
commit 79fec050de8dc8fdc0d811f1b3fdb314a2484057 1 parent ba53054
@delano authored
View
4 CHANGES.txt
@@ -1,6 +1,10 @@
BENELUX, CHANGES
+#### 0.6.0 (2010-09-05) ##############################
+
+* CHANGE: Thread now belongs to Track (previously reversed)
+
#### 0.5.16 (2010-06-08) ##############################
* ADDED: Support for timing class methods.
View
4 benelux.gemspec
@@ -1,7 +1,7 @@
@spec = Gem::Specification.new do |s|
s.name = "benelux"
s.rubyforge_project = 'benelux'
- s.version = "0.5.16"
+ s.version = "0.6.0"
s.summary = "Benelux: A mad way to time Ruby codes"
s.description = s.summary
s.author = "Delano Mandelbaum"
@@ -13,7 +13,7 @@
s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
s.require_paths = %w[lib]
- s.add_dependency("storable", [">= 0.6.5"])
+ s.add_dependency("storable", [">= 0.8.0"])
# = MANIFEST =
# git ls-files
View
28 lib/benelux.rb
@@ -5,7 +5,7 @@
require 'storable'
module Benelux
- VERSION = "0.5.16"
+ VERSION = "0.6.0"
NOTSUPPORTED = [Class, Object, Kernel]
class BeneluxError < RuntimeError; end
@@ -66,15 +66,13 @@ def Benelux.track?(name)
# If +track+ is nil, it returns the Track object for the
# Track associated to the current thread.
#
- def Benelux.current_track(name=nil,group=nil)
+ 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
- Thread.current.timeline ||= Benelux::Timeline.new
- Thread.current.rotated_timelines ||= []
- @tracks[name] ||= Track.new(name, group)
+ @tracks[name] ||= Track.new(name, timeline || Thread.current.timeline || Benelux::Timeline.new)
@tracks[name].add_thread Thread.current
@known_threads << Thread.current
end
@@ -83,6 +81,14 @@ def Benelux.current_track(name=nil,group=nil)
end
Benelux.current_track :main
+ def Benelux.merge_tracks
+ tl = Benelux::Timeline.new
+ tracks.each_pair do |trackid,track|
+ tl.merge! track.timeline
+ end
+ tl
+ end
+
# Only updates data from threads that
# are dead and rotated timelines.
def Benelux.update_global_timeline
@@ -115,18 +121,6 @@ def Benelux.update_global_timeline
end
end
- # Thread tags become the default for any new Mark or Range.
- def Benelux.add_thread_tags(args=Selectable::Tags.new)
- Benelux.thread_timeline.add_default_tags args
- end
- def Benelux.add_thread_tag(*args) add_thread_tags *args end
-
- def Benelux.remove_thread_tags(*args)
- Benelux.thread_timeline.remove_default_tags *args
- end
- def Benelux.remove_thread_tag(*args) remove_thread_tags *args end
-
-
def Benelux.inspect
str = ["Benelux"]
str << "tracks:" << Benelux.tracks.inspect
View
11 lib/benelux/packer.rb
@@ -116,18 +116,21 @@ def install_method
def generate_packed_method
%Q{
def #{@meth}(*args, &block)
+ #p ["#{@meth} 1"]
call_id = "" << self.object_id.abs.to_s << args.object_id.abs.to_s
Benelux.current_track :global unless Benelux.known_thread?
- mark_a = Benelux.thread_timeline.add_mark :'#{@aliaz}_a'
+ mark_a = Benelux.current_track.timeline.add_mark :'#{@aliaz}_a'
mark_a.add_tag :call_id => call_id
tags = mark_a.tags
ret = #{@methorig}(*args, &block)
+ #p ["#{@meth} 2"]
+ ret
rescue => ex # We do this so we can use
raise ex # ex in the ensure block.
ensure
- mark_z = Benelux.thread_timeline.add_mark :'#{@aliaz}_z'
+ mark_z = Benelux.current_track.timeline.add_mark :'#{@aliaz}_z'
mark_z.tags = tags # In case tags were added between these marks
- range = Benelux.thread_timeline.add_range :'#{@aliaz}', mark_a, mark_z
+ range = Benelux.current_track.timeline.add_range :'#{@aliaz}', mark_a, mark_z
range.exception = ex if defined?(ex) && !ex.nil?
end
}
@@ -149,7 +152,7 @@ def #{@meth}(*args, &block)
ret = #{@methorig}(*args, &block)
count = cmd.determine_count(args, ret)
#Benelux.ld "COUNT(:#{@meth}): \#{count}"
- Benelux.thread_timeline.add_count :'#{@meth}', count
+ Benelux.current_track.timeline.add_count :'#{@meth}', count
ret
end
}
View
2  lib/benelux/stats.rb
@@ -151,7 +151,7 @@ def reset
@min, @max = 0.0, 0.0
end
- def samples(*args)
+ def samples(*args)
args.flatten.each { |s| sample(s) }
end
View
21 lib/benelux/track.rb
@@ -5,9 +5,11 @@ class Track
attr_reader :name
attr_reader :thread_group
attr_reader :timeline
- def initialize(n,g=nil)
- @name, @thgrp = n, (g || ThreadGroup.new)
- @timeline = Benelux::Timeline.new
+ attr_reader :rotated_timelines
+ def initialize(n,t)
+ @name, @thgrp = n, ThreadGroup.new
+ @timeline = t || Benelux::Timeline.new
+ @rotated_timelines = []
end
def add_thread(t=Thread.current)
@thgrp.add t
@@ -16,5 +18,18 @@ def add_thread(t=Thread.current)
def threads
@thgrp.list
end
+ def add_tags(args=Selectable::Tags.new)
+ timeline.add_default_tags args
+ end
+ def remove_tags(*args)
+ timeline.remove_default_tags *args
+ end
+ ##def rotate_timeline
+ ## self.rotated_timelines << self.timeline
+ ## tags = self.timeline.default_tags.clone
+ ## self.timeline = Benelux::Timeline.new
+ ## self.timeline.default_tags = tags
+ ## self.timeline
+ ##end
end
end
View
2  lib/selectable/tags.rb
@@ -78,7 +78,7 @@ def compare_Array(b)
end
def method_missing(meth, *args)
- raise SelectableError, "#{meth}: #{args.first} is not a Hash or Array"
+ raise SelectableError, "#{meth}: #{args.first} is not a Hash or Array #{self}"
end
## NOTE: This is helpful but defensive. Ponder!
Please sign in to comment.
Something went wrong with that request. Please try again.