hitimes 1.1.1-x86-mswin32 → 1.2.0-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CONTRIBUTING.md +45 -0
  2. data/{HISTORY → HISTORY.rdoc} +14 -1
  3. data/LICENSE +11 -8
  4. data/Manifest.txt +44 -0
  5. data/{README → README.rdoc} +18 -5
  6. data/Rakefile +20 -62
  7. data/ext/hitimes/{extconf.rb → c/extconf.rb} +3 -3
  8. data/ext/hitimes/{hitimes_ext.c → c/hitimes.c} +1 -1
  9. data/ext/hitimes/{hitimes_instant_clock_gettime.c → c/hitimes_instant_clock_gettime.c} +0 -0
  10. data/ext/hitimes/c/hitimes_instant_osx.c +45 -0
  11. data/ext/hitimes/{hitimes_instant_windows.c → c/hitimes_instant_windows.c} +0 -0
  12. data/ext/hitimes/{hitimes_interval.c → c/hitimes_interval.c} +15 -7
  13. data/ext/hitimes/{hitimes_interval.h → c/hitimes_interval.h} +5 -5
  14. data/ext/hitimes/{hitimes_stats.c → c/hitimes_stats.c} +0 -0
  15. data/ext/hitimes/{hitimes_stats.h → c/hitimes_stats.h} +0 -0
  16. data/ext/hitimes/java/src/hitimes/Hitimes.java +54 -0
  17. data/ext/hitimes/java/src/hitimes/HitimesInterval.java +181 -0
  18. data/ext/hitimes/java/src/hitimes/HitimesService.java +16 -0
  19. data/ext/hitimes/java/src/hitimes/HitimesStats.java +112 -0
  20. data/lib/hitimes.rb +15 -5
  21. data/lib/hitimes/1.8/hitimes.so +0 -0
  22. data/lib/hitimes/1.9/hitimes.so +0 -0
  23. data/lib/hitimes/version.rb +1 -50
  24. data/spec/hitimes_spec.rb +14 -0
  25. data/spec/interval_spec.rb +24 -21
  26. data/spec/metric_spec.rb +8 -10
  27. data/spec/mutex_stats_spec.rb +8 -6
  28. data/spec/paths_spec.rb +1 -3
  29. data/spec/spec_helper.rb +7 -3
  30. data/spec/stats_spec.rb +26 -28
  31. data/spec/timed_metric_spec.rb +33 -33
  32. data/spec/timed_value_metric_spec.rb +45 -46
  33. data/spec/value_metric_spec.rb +21 -23
  34. data/spec/version_spec.rb +4 -30
  35. data/tasks/default.rake +267 -0
  36. data/tasks/extension.rake +31 -101
  37. data/tasks/this.rb +209 -0
  38. metadata +89 -88
  39. data/ext/hitimes/hitimes_instant_osx.c +0 -16
  40. data/gemspec.rb +0 -64
  41. data/lib/hitimes/1.8/hitimes_ext.so +0 -0
  42. data/lib/hitimes/1.9/hitimes_ext.so +0 -0
  43. data/tasks/announce.rake +0 -42
  44. data/tasks/config.rb +0 -109
  45. data/tasks/distribution.rake +0 -93
  46. data/tasks/documentation.rake +0 -32
  47. data/tasks/rspec.rake +0 -33
  48. data/tasks/rubyforge.rake +0 -55
  49. data/tasks/utils.rb +0 -80
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hitimes do
4
+ it "can time a block of code" do
5
+ d = Hitimes.measure do
6
+ sleep 0.2
7
+ end
8
+ d.should be_within(0.02).of(0.2)
9
+ end
10
+
11
+ it "raises an error if measure is called with no block" do
12
+ lambda{ Hitimes.measure }.should raise_error( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
13
+ end
14
+ end
@@ -1,11 +1,14 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes'
1
+ require "spec_helper"
4
2
 
5
3
  describe Hitimes::Interval do
6
- it "has a 0 duration when newly created" do
7
- i = Hitimes::Interval.new
8
- i.duration == 0.0
4
+ it "raises an error if duration is called on a non-started interval" do
5
+ i = Hitimes::Interval.new
6
+ lambda{ i.duration }.should raise_error( Hitimes::Error, /\AAttempt to report a duration on an interval that has not started\Z/ )
7
+ end
8
+
9
+ it "raises an error if stop is called on a non-started interval" do
10
+ i = Hitimes::Interval.new
11
+ lambda { i.stop }.should raise_error( Hitimes::Error, /\AAttempt to stop an interval that has not started\Z/ )
9
12
  end
10
13
 
11
14
  it "knows if it has been started" do
@@ -37,11 +40,11 @@ describe Hitimes::Interval do
37
40
  d = Hitimes::Interval.measure do
38
41
  sleep 0.2
39
42
  end
40
- d.should be_close(0.2, 0.02)
43
+ d.should be_within(0.02).of(0.2)
41
44
  end
42
45
 
43
46
  it "raises an error if measure is called with no block" do
44
- lambda{ Hitimes::Interval.measure }.should raise_error( Hitimes::Error )
47
+ lambda{ Hitimes::Interval.measure }.should raise_error( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
45
48
  end
46
49
 
47
50
  it "creates an interval via #now" do
@@ -60,10 +63,10 @@ describe Hitimes::Interval do
60
63
 
61
64
  it "calling start multiple times on has no effect after the first call" do
62
65
  i = Hitimes::Interval.new
63
- i.start.should == true
66
+ i.start.should be == true
64
67
  x = i.start_instant
65
- i.start_instant.should > 0
66
- i.start.should == false
68
+ i.start_instant.should be > 0
69
+ i.start.should be == false
67
70
  x.should == i.start_instant
68
71
  end
69
72
 
@@ -75,12 +78,12 @@ describe Hitimes::Interval do
75
78
 
76
79
  it "calling stop multiple times on has no effect after the first call" do
77
80
  i = Hitimes::Interval.new
78
- i.start.should == true
81
+ i.start.should be == true
79
82
  i.stop
80
83
 
81
84
  x = i.stop_instant
82
- i.stop_instant.should > 0
83
- i.stop.should == false
85
+ i.stop_instant.should be > 0
86
+ i.stop.should be == false
84
87
  x.should == i.stop_instant
85
88
 
86
89
  end
@@ -90,14 +93,14 @@ describe Hitimes::Interval do
90
93
  i.start
91
94
  x = i.stop
92
95
  y = i.duration
93
- i.stop.should == false
96
+ i.stop.should be == false
94
97
 
95
98
  z = i.duration
96
99
 
97
- x.should == y
98
- x.should == z
100
+ x.should be == y
101
+ x.should be == z
99
102
 
100
- y.should == z
103
+ y.should be == z
101
104
  end
102
105
 
103
106
  it "can return how much time has elapsed from the start without stopping the interval" do
@@ -107,9 +110,9 @@ describe Hitimes::Interval do
107
110
  i.should be_running
108
111
  y = i.duration_so_far
109
112
  i.stop
110
- x.should < y
111
- x.should < i.duration
112
- y.should < i.duration
113
+ x.should be < y
114
+ x.should be < i.duration
115
+ y.should be < i.duration
113
116
  end
114
117
 
115
118
  describe "#split" do
data/spec/metric_spec.rb CHANGED
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/metric'
1
+ require "spec_helper"
4
2
 
5
3
  describe Hitimes::Metric do
6
4
  before( :each ) do
@@ -8,22 +6,22 @@ describe Hitimes::Metric do
8
6
  end
9
7
 
10
8
  it 'has a name' do
11
- @metric.name.should == "testing"
9
+ @metric.name.should be == "testing"
12
10
  end
13
11
 
14
12
  it "has associated data from initialization" do
15
13
  m = Hitimes::Metric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
16
- m.additional_data['foo'].should == 'bar'
17
- m.additional_data['this'].should == 'that'
14
+ m.additional_data['foo'].should be == 'bar'
15
+ m.additional_data['this'].should be == 'that'
18
16
 
19
17
  m = Hitimes::Metric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
20
- m.additional_data['foo'].should == 'bar'
21
- m.additional_data['this'].should == 'that'
18
+ m.additional_data['foo'].should be == 'bar'
19
+ m.additional_data['this'].should be == 'that'
22
20
  end
23
21
 
24
22
  it "initially has no sampling times" do
25
- @metric.sampling_start_time.should == nil
26
- @metric.sampling_stop_time.should == nil
23
+ @metric.sampling_start_time.should be == nil
24
+ @metric.sampling_stop_time.should be == nil
27
25
  end
28
26
  end
29
27
 
@@ -1,7 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes'
4
- require 'hitimes/mutexed_stats'
1
+ require 'spec_helper'
5
2
 
6
3
  describe Hitimes::MutexedStats do
7
4
  before( :each ) do
@@ -19,8 +16,13 @@ describe Hitimes::MutexedStats do
19
16
  return stats
20
17
  end
21
18
 
22
- it "is unsafe normally" do
23
- pending "not for MRI -- not interruptable in this C extension" do
19
+ if (not defined? RUBY_ENGINE) or (RUBY_ENGINE == "ruby") then
20
+ it "Hitimes::Stats is threadsafe" do
21
+ stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
22
+ stats.count.should== @final_value
23
+ end
24
+ else
25
+ it "Hitimes::Stats is not threadsafe" do
24
26
  stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
25
27
  stats.count.should_not == @final_value
26
28
  end
data/spec/paths_spec.rb CHANGED
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/paths'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Hitimes::Paths do
6
4
  it "can access the root dir of the project" do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
- require 'rubygems'
2
- require 'spec'
1
+ if RUBY_VERSION >= '1.9.2' then
2
+ require 'simplecov'
3
+ puts "Using coverage!"
4
+ SimpleCov.start if ENV['COVERAGE']
5
+ end
3
6
 
4
- $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
7
+ require 'rspec/autorun'
8
+ require 'hitimes'
5
9
 
data/spec/stats_spec.rb CHANGED
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/stats'
1
+ require 'spec_helper'
4
2
  require 'json'
5
3
 
6
4
  describe Hitimes::Stats do
@@ -12,60 +10,60 @@ describe Hitimes::Stats do
12
10
  end
13
11
 
14
12
  it "is initialized with 0 values" do
15
- @stats.count.should == 0
16
- @stats.min.should == 0.0
17
- @stats.max.should == 0.0
18
- @stats.sum.should == 0.0
19
- @stats.rate.should == 0.0
13
+ @stats.count.should be == 0
14
+ @stats.min.should be == 0.0
15
+ @stats.max.should be == 0.0
16
+ @stats.sum.should be == 0.0
17
+ @stats.rate.should be == 0.0
20
18
  end
21
19
 
22
20
  it "calculates the mean correctly" do
23
- @full_stats.mean.should == 2.0
21
+ @full_stats.mean.should be == 2.0
24
22
  end
25
23
 
26
24
  it "calculates the rate correctly" do
27
- @full_stats.rate.should == 0.5
25
+ @full_stats.rate.should be == 0.5
28
26
  end
29
27
 
30
28
  it "tracks the maximum value" do
31
- @full_stats.max.should == 3.0
29
+ @full_stats.max.should be == 3.0
32
30
  end
33
31
 
34
32
  it "tracks the minimum value" do
35
- @full_stats.min.should == 1.0
33
+ @full_stats.min.should be == 1.0
36
34
  end
37
35
 
38
36
  it "tracks the count" do
39
- @full_stats.count.should == 3
37
+ @full_stats.count.should be == 3
40
38
  end
41
39
 
42
40
  it "tracks the sum" do
43
- @full_stats.sum.should == 6.0
41
+ @full_stats.sum.should be == 6.0
44
42
  end
45
43
 
46
44
  it "calculates the standard deviation" do
47
- @full_stats.stddev.should == 1.0
45
+ @full_stats.stddev.should be == 1.0
48
46
  end
49
47
 
50
48
  it "calculates the sum of squares " do
51
- @full_stats.sumsq.should == 14.0
49
+ @full_stats.sumsq.should be == 14.0
52
50
  end
53
51
 
54
52
  describe "#to_hash " do
55
53
  it "converts to a Hash" do
56
54
  h = @full_stats.to_hash
57
- h.size.should == ::Hitimes::Stats::STATS.size
58
- h.keys.sort.should == ::Hitimes::Stats::STATS
55
+ h.size.should be == ::Hitimes::Stats::STATS.size
56
+ h.keys.sort.should be == ::Hitimes::Stats::STATS
59
57
  end
60
58
 
61
59
  it "converts to a limited Hash if given arguments" do
62
60
  h = @full_stats.to_hash( "min", "max", "mean" )
63
- h.size.should == 3
64
- h.keys.sort.should == %w[ max mean min ]
61
+ h.size.should be == 3
62
+ h.keys.sort.should be == %w[ max mean min ]
65
63
 
66
64
  h = @full_stats.to_hash( %w[ count rate ] )
67
- h.size.should == 2
68
- h.keys.sort.should == %w[ count rate ]
65
+ h.size.should be == 2
66
+ h.keys.sort.should be == %w[ count rate ]
69
67
  end
70
68
 
71
69
  it "raises NoMethodError if an invalid stat is used" do
@@ -77,20 +75,20 @@ describe Hitimes::Stats do
77
75
  it "converts to a json string" do
78
76
  j = @full_stats.to_json
79
77
  h = JSON.parse( j )
80
- h.size.should == ::Hitimes::Stats::STATS.size
81
- h.keys.sort.should == ::Hitimes::Stats::STATS
78
+ h.size.should be == ::Hitimes::Stats::STATS.size
79
+ h.keys.sort.should be == ::Hitimes::Stats::STATS
82
80
  end
83
81
 
84
82
  it "converts to a limited Hash if given arguments" do
85
83
  j = @full_stats.to_json( "min", "max", "mean" )
86
84
  h = JSON.parse( j )
87
- h.size.should == 3
88
- h.keys.sort.should == %w[ max mean min ]
85
+ h.size.should be == 3
86
+ h.keys.sort.should be == %w[ max mean min ]
89
87
 
90
88
  j = @full_stats.to_json( %w[ count rate ] )
91
89
  h = JSON.parse( j )
92
- h.size.should == 2
93
- h.keys.sort.should == %w[ count rate ]
90
+ h.size.should be == 2
91
+ h.keys.sort.should be == %w[ count rate ]
94
92
  end
95
93
 
96
94
  it "raises NoMethodError if an invalid stat is used" do
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/timed_metric'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Hitimes::TimedMetric do
6
4
  before( :each ) do
@@ -19,76 +17,76 @@ describe Hitimes::TimedMetric do
19
17
  @tm.start
20
18
  d = @tm.split
21
19
  @tm.should be_running
22
- d.should > 0
23
- @tm.count.should == 1
24
- @tm.duration.should == d
20
+ d.should be > 0
21
+ @tm.count.should be == 1
22
+ @tm.duration.should be == d
25
23
  end
26
24
 
27
25
  it "#stop returns false if called more than once in a row" do
28
26
  @tm.start
29
- @tm.stop.should > 0
30
- @tm.stop.should == false
27
+ @tm.stop.should be > 0
28
+ @tm.stop.should be == false
31
29
  end
32
30
 
33
31
  it "does not count a currently running interval as an interval in calculations" do
34
32
  @tm.start
35
- @tm.count.should == 0
33
+ @tm.count.should be == 0
36
34
  @tm.split
37
- @tm.count.should == 1
35
+ @tm.count.should be == 1
38
36
  end
39
37
 
40
38
  it "#split called on a stopped timer does nothing" do
41
39
  @tm.start
42
40
  @tm.stop
43
- @tm.split.should == false
41
+ @tm.split.should be == false
44
42
  end
45
43
 
46
44
  it "calculates the mean of the durations" do
47
45
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
48
- @tm.mean.should be_close( 0.05, 0.01 )
46
+ @tm.mean.should be_within(0.01).of(0.05)
49
47
  end
50
48
 
51
49
  it "calculates the rate of the counts " do
52
50
  5.times { @tm.start ; sleep 0.05 ; @tm.stop }
53
- @tm.rate.should be_close( 20.00, 0.1 )
51
+ @tm.rate.should be_within(1.0).of(20.00)
54
52
  end
55
53
 
56
54
 
57
55
  it "calculates the stddev of the durations" do
58
- 3.times { |x| @tm.start ; sleep (0.05 * x) ; @tm.stop }
59
- @tm.stddev.should be_close( 0.05, 0.001)
56
+ 3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop }
57
+ @tm.stddev.should be_within(0.002).of( 0.05)
60
58
  end
61
59
 
62
60
  it "returns 0.0 for stddev if there is no data" do
63
- @tm.stddev.should == 0.0
61
+ @tm.stddev.should be == 0.0
64
62
  end
65
63
 
66
64
  it "keeps track of the min value" do
67
65
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
68
- @tm.min.should be_close( 0.05, 0.002 )
66
+ @tm.min.should be_within( 0.002 ).of(0.05)
69
67
  end
70
68
 
71
69
  it "keeps track of the max value" do
72
70
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
73
- @tm.max.should be_close( 0.05, 0.002 )
71
+ @tm.max.should be_within( 0.002 ).of(0.05)
74
72
  end
75
73
 
76
74
  it "keeps track of the sum value" do
77
75
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
78
- @tm.sum.should be_close( 0.10, 0.002 )
76
+ @tm.sum.should be_within( 0.005 ).of(0.10)
79
77
  end
80
-
78
+
81
79
  it "keeps track of the sum of squars value" do
82
80
  3.times { @tm.start ; sleep 0.05 ; @tm.stop }
83
- @tm.sumsq.should be_close( 0.0075, 0.0001 )
81
+ @tm.sumsq.should be_within(0.001).of(0.0075)
84
82
  end
85
83
 
86
84
  it "keeps track of the minimum start time of all the intervals" do
87
85
  f1 = Time.now.gmtime.to_f * 1_000_000
88
86
  5.times { @tm.start ; sleep 0.05 ; @tm.stop }
89
87
  f2 = Time.now.gmtime.to_f * 1_000_000
90
- @tm.sampling_start_time.should >= f1
91
- @tm.sampling_start_time.should < f2
88
+ @tm.sampling_start_time.should be >= f1
89
+ @tm.sampling_start_time.should be < f2
92
90
  # distance from now to start time should be greater than the distance from
93
91
  # the start to the min start_time
94
92
  (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
@@ -96,10 +94,12 @@ describe Hitimes::TimedMetric do
96
94
 
97
95
  it "keeps track of the last stop time of all the intervals" do
98
96
  f1 = Time.now.gmtime.to_f * 1_000_000
97
+ sleep 0.01
99
98
  5.times { @tm.start ; sleep 0.05 ; @tm.stop }
99
+ sleep 0.01
100
100
  f2 = Time.now.gmtime.to_f * 1_000_000
101
- @tm.sampling_stop_time.should > f1
102
- @tm.sampling_stop_time.should <= f2
101
+ @tm.sampling_stop_time.should be > f1
102
+ @tm.sampling_stop_time.should be <= f2
103
103
  # distance from now to max stop time time should be less than the distance
104
104
  # from the start to the max stop time
105
105
  (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
@@ -113,34 +113,34 @@ describe Hitimes::TimedMetric do
113
113
  it "can measure a block of code from an instance" do
114
114
  t = Hitimes::TimedMetric.new( 'measure a block' )
115
115
  3.times { t.measure { sleep 0.05 } }
116
- t.duration.should be_close( 0.15, 0.001 )
117
- t.count.should == 3
116
+ t.duration.should be_within(0.01).of(0.15)
117
+ t.count.should be == 3
118
118
  end
119
119
 
120
120
  it "returns the value of the block when measuring" do
121
121
  t = Hitimes::TimedMetric.new( 'measure a block' )
122
122
  x = t.measure { sleep 0.05; 42 }
123
- t.duration.should be_close( 0.05, 0.001 )
124
- x.should == 42
123
+ t.duration.should be_within(0.002).of(0.05)
124
+ x.should be == 42
125
125
  end
126
126
 
127
127
  describe "#to_hash" do
128
128
 
129
129
  it "has name value" do
130
130
  h = @tm.to_hash
131
- h['name'].should == "test-timed-metric"
131
+ h['name'].should be == "test-timed-metric"
132
132
  end
133
133
 
134
134
  it "has an empty hash for additional_data" do
135
135
  h = @tm.to_hash
136
- h['additional_data'].should == Hash.new
137
- h['additional_data'].size.should == 0
136
+ h['additional_data'].should be == Hash.new
137
+ h['additional_data'].size.should be == 0
138
138
  end
139
139
 
140
140
  it "has the right sum" do
141
141
  10.times { |x| @tm.measure { sleep 0.01*x } }
142
142
  h = @tm.to_hash
143
- h['sum'].should be_close( 0.45, 0.003 )
143
+ h['sum'].should be_within( 0.01).of(0.45)
144
144
  end
145
145
 
146
146
  fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]