hitimes 1.1.1-java → 1.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +45 -0
- data/{HISTORY → HISTORY.rdoc} +14 -1
- data/LICENSE +11 -8
- data/Manifest.txt +44 -0
- data/{README → README.rdoc} +18 -5
- data/Rakefile +20 -62
- data/ext/hitimes/{extconf.rb → c/extconf.rb} +3 -3
- data/ext/hitimes/{hitimes_ext.c → c/hitimes.c} +1 -1
- data/ext/hitimes/{hitimes_instant_clock_gettime.c → c/hitimes_instant_clock_gettime.c} +0 -0
- data/ext/hitimes/c/hitimes_instant_osx.c +45 -0
- data/ext/hitimes/{hitimes_instant_windows.c → c/hitimes_instant_windows.c} +0 -0
- data/ext/hitimes/{hitimes_interval.c → c/hitimes_interval.c} +15 -7
- data/ext/hitimes/{hitimes_interval.h → c/hitimes_interval.h} +5 -5
- data/ext/hitimes/{hitimes_stats.c → c/hitimes_stats.c} +0 -0
- data/ext/hitimes/{hitimes_stats.h → c/hitimes_stats.h} +0 -0
- data/ext/{java → hitimes/java}/src/hitimes/Hitimes.java +1 -1
- data/ext/{java → hitimes/java}/src/hitimes/HitimesInterval.java +8 -1
- data/ext/{java → hitimes/java}/src/hitimes/HitimesService.java +0 -0
- data/ext/{java → hitimes/java}/src/hitimes/HitimesStats.java +0 -0
- data/lib/hitimes.rb +15 -5
- data/lib/hitimes/hitimes.jar +0 -0
- data/lib/hitimes/version.rb +1 -50
- data/spec/hitimes_spec.rb +14 -0
- data/spec/interval_spec.rb +24 -21
- data/spec/metric_spec.rb +8 -10
- data/spec/mutex_stats_spec.rb +8 -6
- data/spec/paths_spec.rb +1 -3
- data/spec/spec_helper.rb +7 -3
- data/spec/stats_spec.rb +26 -28
- data/spec/timed_metric_spec.rb +33 -33
- data/spec/timed_value_metric_spec.rb +45 -46
- data/spec/value_metric_spec.rb +21 -23
- data/spec/version_spec.rb +4 -30
- data/tasks/default.rake +267 -0
- data/tasks/extension.rake +31 -101
- data/tasks/this.rb +209 -0
- metadata +185 -182
- data/ext/hitimes/hitimes_instant_osx.c +0 -16
- data/gemspec.rb +0 -64
- data/tasks/announce.rake +0 -42
- data/tasks/config.rb +0 -109
- data/tasks/distribution.rake +0 -93
- data/tasks/documentation.rake +0 -32
- data/tasks/rspec.rake +0 -33
- data/tasks/rubyforge.rake +0 -55
- data/tasks/utils.rb +0 -80
File without changes
|
File without changes
|
@@ -42,7 +42,7 @@ public class Hitimes {
|
|
42
42
|
}
|
43
43
|
|
44
44
|
static RaiseException newHitimesError( Ruby runtime, String message ) {
|
45
|
-
RubyClass errorClass = runtime.
|
45
|
+
RubyClass errorClass = runtime.getModule("Hitimes").getClass( "Error" );
|
46
46
|
return new RaiseException( RubyException.newException( runtime, errorClass, message ), true );
|
47
47
|
}
|
48
48
|
|
@@ -47,6 +47,13 @@ public class HitimesInterval extends RubyObject {
|
|
47
47
|
@JRubyMethod( name = "duration", alias = { "length", "to_f", "to_seconds" } )
|
48
48
|
public IRubyObject duration() {
|
49
49
|
|
50
|
+
/*
|
51
|
+
* if start has not yet been called, then raise an exception.
|
52
|
+
*/
|
53
|
+
if ( INSTANT_NOT_SET == this.start_instant ) {
|
54
|
+
throw Hitimes.newHitimesError( getRuntime(), "Attempt to report a duration on an interval that has not started");
|
55
|
+
}
|
56
|
+
|
50
57
|
/*
|
51
58
|
* if stop has not yet been called, then return the amount of time so far
|
52
59
|
*/
|
@@ -128,7 +135,7 @@ public class HitimesInterval extends RubyObject {
|
|
128
135
|
@JRubyMethod( name = "stop" )
|
129
136
|
public IRubyObject stop() {
|
130
137
|
if ( INSTANT_NOT_SET == this.start_instant ) {
|
131
|
-
throw Hitimes.newHitimesError( getRuntime(), "Attempt to stop an interval that has not started
|
138
|
+
throw Hitimes.newHitimesError( getRuntime(), "Attempt to stop an interval that has not started" );
|
132
139
|
}
|
133
140
|
|
134
141
|
if ( INSTANT_NOT_SET == this.stop_instant ) {
|
File without changes
|
File without changes
|
data/lib/hitimes.rb
CHANGED
@@ -15,16 +15,26 @@ module Hitimes
|
|
15
15
|
# Base class of all errors in Hitimes
|
16
16
|
#
|
17
17
|
class Error < ::StandardError; end
|
18
|
+
|
19
|
+
# Hitimes.measure { } -> Float
|
20
|
+
#
|
21
|
+
# Times the execution of the block, returning the number of seconds it took
|
22
|
+
def self.measure(&block)
|
23
|
+
Hitimes::Interval.measure(&block)
|
24
|
+
end
|
18
25
|
end
|
19
26
|
require 'hitimes/paths'
|
20
27
|
require 'hitimes/version'
|
21
28
|
|
22
|
-
|
29
|
+
# Load the binary extension, try loading one for the specific version of ruby
|
30
|
+
# and if that fails, then fall back to one in the top of the library.
|
31
|
+
# this is the method recommended by rake-compiler
|
32
|
+
begin
|
33
|
+
# this will be for windows
|
34
|
+
require "hitimes/#{RUBY_VERSION.sub(/\.\d$/,'')}/hitimes"
|
35
|
+
rescue LoadError
|
36
|
+
# everyone else.
|
23
37
|
require 'hitimes/hitimes'
|
24
|
-
else
|
25
|
-
# use a version subdirectory for extensions, initially to support windows, but
|
26
|
-
# why make a special case. It doesn't hurt anyone to have an extra subdir.
|
27
|
-
require "hitimes/#{RUBY_VERSION.sub(/\.\d$/,'')}/hitimes_ext"
|
28
38
|
end
|
29
39
|
|
30
40
|
require 'hitimes/stats'
|
data/lib/hitimes/hitimes.jar
CHANGED
Binary file
|
data/lib/hitimes/version.rb
CHANGED
@@ -4,54 +4,5 @@
|
|
4
4
|
#++
|
5
5
|
|
6
6
|
module Hitimes
|
7
|
-
|
8
|
-
# module containing all the version information about Hitimes
|
9
|
-
#
|
10
|
-
module Version
|
11
|
-
|
12
|
-
# Major version number
|
13
|
-
MAJOR = 1
|
14
|
-
|
15
|
-
# Minor version number
|
16
|
-
MINOR = 1
|
17
|
-
|
18
|
-
# Build number
|
19
|
-
BUILD = 1
|
20
|
-
|
21
|
-
#
|
22
|
-
# :call-seq:
|
23
|
-
# Version.to_a -> [ MAJOR, MINOR, BUILD ]
|
24
|
-
#
|
25
|
-
# Return the version as an array of Integers
|
26
|
-
#
|
27
|
-
def self.to_a
|
28
|
-
[MAJOR, MINOR, BUILD]
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# :call-seq:
|
33
|
-
# Version.to_s -> "MAJOR.MINOR.BUILD"
|
34
|
-
#
|
35
|
-
# Return the version as a String with dotted notation
|
36
|
-
#
|
37
|
-
def self.to_s
|
38
|
-
to_a.join(".")
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# :call-seq:
|
43
|
-
# Version.to_hash -> { :major => ..., :minor => ..., :build => ... }
|
44
|
-
#
|
45
|
-
# Return the version as a Hash
|
46
|
-
#
|
47
|
-
def self.to_hash
|
48
|
-
{ :major => MAJOR, :minor => MINOR, :build => BUILD }
|
49
|
-
end
|
50
|
-
|
51
|
-
# The Version in MAJOR.MINOR.BUILD dotted notation
|
52
|
-
STRING = Version.to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
# The Version in MAJOR.MINOR.BUILD dotted notation
|
56
|
-
VERSION = Version.to_s
|
7
|
+
VERSION = "1.2.0"
|
57
8
|
end
|
@@ -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
|
data/spec/interval_spec.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'hitimes'
|
1
|
+
require "spec_helper"
|
4
2
|
|
5
3
|
describe Hitimes::Interval do
|
6
|
-
it "
|
7
|
-
i = Hitimes::Interval.new
|
8
|
-
i.duration
|
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
|
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
|
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
|
|
data/spec/mutex_stats_spec.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
require
|
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
|
-
|
23
|
-
|
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
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
require '
|
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
|
-
|
7
|
+
require 'rspec/autorun'
|
8
|
+
require 'hitimes'
|
5
9
|
|
data/spec/stats_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require
|
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
|