hitimes 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +0 -11
- data/HISTORY.md +8 -1
- data/Manifest.txt +3 -14
- data/README.md +8 -18
- data/Rakefile +4 -13
- data/lib/hitimes.rb +2 -30
- data/lib/hitimes/initialize.rb +65 -0
- data/lib/hitimes/instant.rb +65 -0
- data/lib/hitimes/interval.rb +171 -0
- data/lib/hitimes/mutexed_stats.rb +1 -16
- data/lib/hitimes/stats.rb +98 -1
- data/lib/hitimes/version.rb +1 -1
- data/spec/hitimes_spec.rb +4 -4
- data/spec/interval_spec.rb +33 -33
- data/spec/metric_spec.rb +7 -7
- data/spec/mutex_stats_spec.rb +4 -11
- data/spec/paths_spec.rb +2 -2
- data/spec/stats_spec.rb +28 -28
- data/spec/timed_metric_spec.rb +36 -36
- data/spec/timed_value_metric_spec.rb +48 -48
- data/spec/value_metric_spec.rb +24 -24
- data/spec/version_spec.rb +1 -1
- data/tasks/this.rb +2 -2
- metadata +16 -56
- data/ext/hitimes/c/extconf.rb +0 -24
- data/ext/hitimes/c/hitimes.c +0 -37
- data/ext/hitimes/c/hitimes_instant_clock_gettime.c +0 -28
- data/ext/hitimes/c/hitimes_instant_osx.c +0 -48
- data/ext/hitimes/c/hitimes_instant_windows.c +0 -27
- data/ext/hitimes/c/hitimes_interval.c +0 -370
- data/ext/hitimes/c/hitimes_interval.h +0 -73
- data/ext/hitimes/c/hitimes_stats.c +0 -269
- data/ext/hitimes/c/hitimes_stats.h +0 -30
- data/ext/hitimes/java/src/hitimes/Hitimes.java +0 -63
- data/ext/hitimes/java/src/hitimes/HitimesInterval.java +0 -176
- data/ext/hitimes/java/src/hitimes/HitimesService.java +0 -16
- data/ext/hitimes/java/src/hitimes/HitimesStats.java +0 -112
- data/tasks/extension.rake +0 -38
data/spec/timed_metric_spec.rb
CHANGED
@@ -6,90 +6,90 @@ describe Hitimes::TimedMetric do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "knows if it is running or not" do
|
9
|
-
@tm.running
|
9
|
+
_(@tm.running?).must_equal false
|
10
10
|
@tm.start
|
11
|
-
@tm.running
|
11
|
+
_(@tm.running?).must_equal true
|
12
12
|
@tm.stop
|
13
|
-
@tm.running
|
13
|
+
_(@tm.running?).must_equal false
|
14
14
|
end
|
15
15
|
|
16
16
|
it "#split returns the last duration and the timer is still running" do
|
17
17
|
@tm.start
|
18
18
|
d = @tm.split
|
19
|
-
@tm.running
|
20
|
-
d.must_be :>, 0
|
21
|
-
@tm.count.must_equal 1
|
22
|
-
@tm.duration.must_equal d
|
19
|
+
_(@tm.running?).must_equal true
|
20
|
+
_(d).must_be :>, 0
|
21
|
+
_(@tm.count).must_equal 1
|
22
|
+
_(@tm.duration).must_equal d
|
23
23
|
end
|
24
24
|
|
25
25
|
it "#stop returns false if called more than once in a row" do
|
26
26
|
@tm.start
|
27
|
-
@tm.stop.must_be :>, 0
|
28
|
-
@tm.stop.must_equal false
|
27
|
+
_(@tm.stop).must_be :>, 0
|
28
|
+
_(@tm.stop).must_equal false
|
29
29
|
end
|
30
30
|
|
31
31
|
it "does not count a currently running interval as an interval in calculations" do
|
32
32
|
@tm.start
|
33
|
-
@tm.count.must_equal 0
|
33
|
+
_(@tm.count).must_equal 0
|
34
34
|
@tm.split
|
35
|
-
@tm.count.must_equal 1
|
35
|
+
_(@tm.count).must_equal 1
|
36
36
|
end
|
37
37
|
|
38
38
|
it "#split called on a stopped timer does nothing" do
|
39
39
|
@tm.start
|
40
40
|
@tm.stop
|
41
|
-
@tm.split.must_equal false
|
41
|
+
_(@tm.split).must_equal false
|
42
42
|
end
|
43
43
|
|
44
44
|
it "calculates the mean of the durations" do
|
45
45
|
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
46
|
-
@tm.mean.must_be_close_to(0.05, 0.002)
|
46
|
+
_(@tm.mean).must_be_close_to(0.05, 0.002)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "calculates the rate of the counts " do
|
50
50
|
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
51
|
-
@tm.rate.must_be_close_to(20.00, 0.5)
|
51
|
+
_(@tm.rate).must_be_close_to(20.00, 0.5)
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
55
|
it "calculates the stddev of the durations" do
|
56
56
|
3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop }
|
57
|
-
@tm.stddev.must_be_close_to(0.05)
|
57
|
+
_(@tm.stddev).must_be_close_to(0.05)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "returns 0.0 for stddev if there is no data" do
|
61
|
-
@tm.stddev.must_equal 0.0
|
61
|
+
_(@tm.stddev).must_equal 0.0
|
62
62
|
end
|
63
63
|
|
64
64
|
it "keeps track of the min value" do
|
65
65
|
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
66
|
-
@tm.min.must_be_close_to(0.05, 0.01)
|
66
|
+
_(@tm.min).must_be_close_to(0.05, 0.01)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "keeps track of the max value" do
|
70
70
|
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
71
|
-
@tm.max.must_be_close_to(0.05, 0.01)
|
71
|
+
_(@tm.max).must_be_close_to(0.05, 0.01)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "keeps track of the sum value" do
|
75
75
|
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
76
|
-
@tm.sum.must_be_close_to(0.10, 0.01)
|
76
|
+
_(@tm.sum).must_be_close_to(0.10, 0.01)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "keeps track of the sum of squars value" do
|
80
80
|
3.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
81
|
-
@tm.sumsq.must_be_close_to(0.0075)
|
81
|
+
_(@tm.sumsq).must_be_close_to(0.0075)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "keeps track of the minimum start time of all the intervals" do
|
85
85
|
f1 = Time.now.gmtime.to_f * 1_000_000
|
86
86
|
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
87
87
|
f2 = Time.now.gmtime.to_f * 1_000_000
|
88
|
-
@tm.sampling_start_time.must_be :>=, f1
|
89
|
-
@tm.sampling_start_time.must_be :<, f2
|
88
|
+
_(@tm.sampling_start_time).must_be :>=, f1
|
89
|
+
_(@tm.sampling_start_time).must_be :<, f2
|
90
90
|
# distance from now to start time should be greater than the distance from
|
91
91
|
# the start to the min start_time
|
92
|
-
(f2 - @tm.sampling_start_time).must_be :>, ( @tm.sampling_start_time - f1 )
|
92
|
+
_((f2 - @tm.sampling_start_time)).must_be :>, ( @tm.sampling_start_time - f1 )
|
93
93
|
end
|
94
94
|
|
95
95
|
it "keeps track of the last stop time of all the intervals" do
|
@@ -98,49 +98,49 @@ describe Hitimes::TimedMetric do
|
|
98
98
|
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
99
99
|
sleep 0.01
|
100
100
|
f2 = Time.now.gmtime.to_f * 1_000_000
|
101
|
-
@tm.sampling_stop_time.must_be :>, f1
|
102
|
-
@tm.sampling_stop_time.must_be :<=, f2
|
101
|
+
_(@tm.sampling_stop_time).must_be :>, f1
|
102
|
+
_(@tm.sampling_stop_time).must_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
|
-
(f2 - @tm.sampling_stop_time).must_be :<, ( @tm.sampling_stop_time - f1 )
|
105
|
+
_((f2 - @tm.sampling_stop_time)).must_be :<, ( @tm.sampling_stop_time - f1 )
|
106
106
|
end
|
107
107
|
|
108
108
|
it "can create an already running timer" do
|
109
109
|
t = Hitimes::TimedMetric.now( 'already-running' )
|
110
|
-
t.running
|
110
|
+
_(t.running?).must_equal true
|
111
111
|
end
|
112
112
|
|
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.must_be_close_to(0.15, 0.01)
|
117
|
-
t.count.must_equal 3
|
116
|
+
_(t.duration).must_be_close_to(0.15, 0.01)
|
117
|
+
_(t.count).must_equal 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.must_be_close_to(0.05, 0.002)
|
124
|
-
x.must_equal 42
|
123
|
+
_(t.duration).must_be_close_to(0.05, 0.002)
|
124
|
+
_(x).must_equal 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'].must_equal "test-timed-metric"
|
131
|
+
_(h['name']).must_equal "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'].must_equal Hash.new
|
137
|
-
h['additional_data'].size.must_equal 0
|
136
|
+
_(h['additional_data']).must_equal Hash.new
|
137
|
+
_(h['additional_data'].size).must_equal 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'].must_be_close_to(0.45, 0.01)
|
143
|
+
_(h['sum']).must_be_close_to(0.45, 0.01)
|
144
144
|
end
|
145
145
|
|
146
146
|
fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
|
@@ -148,7 +148,7 @@ describe Hitimes::TimedMetric do
|
|
148
148
|
it "has a value for #{f}" do
|
149
149
|
@tm.measure { sleep 0.001 }
|
150
150
|
h = @tm.to_hash
|
151
|
-
h[f].wont_be_nil
|
151
|
+
_(h[f]).wont_be_nil
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
@@ -6,100 +6,100 @@ describe Hitimes::TimedValueMetric do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "knows if it is running or not" do
|
9
|
-
@tm.running
|
9
|
+
_(@tm.running?).must_equal false
|
10
10
|
@tm.start
|
11
|
-
@tm.running
|
11
|
+
_(@tm.running?).must_equal true
|
12
12
|
@tm.stop( 1 )
|
13
|
-
@tm.running
|
13
|
+
_(@tm.running?).must_equal false
|
14
14
|
end
|
15
15
|
|
16
16
|
it "#split returns the last duration and the timer is still running" do
|
17
17
|
@tm.start
|
18
18
|
d = @tm.split( 1 )
|
19
|
-
@tm.running
|
20
|
-
d.must_be :>, 0
|
21
|
-
@tm.value_stats.count.must_equal 1
|
22
|
-
@tm.timed_stats.count.must_equal 1
|
23
|
-
@tm.duration.must_equal d
|
19
|
+
_(@tm.running?).must_equal true
|
20
|
+
_(d).must_be :>, 0
|
21
|
+
_(@tm.value_stats.count).must_equal 1
|
22
|
+
_(@tm.timed_stats.count).must_equal 1
|
23
|
+
_(@tm.duration).must_equal d
|
24
24
|
end
|
25
25
|
|
26
26
|
it "#stop returns false if called more than once in a row" do
|
27
27
|
@tm.start
|
28
|
-
@tm.stop( 1 ).must_be :>, 0
|
29
|
-
@tm.stop( 1 ).must_equal false
|
28
|
+
_(@tm.stop( 1 )).must_be :>, 0
|
29
|
+
_(@tm.stop( 1 )).must_equal false
|
30
30
|
end
|
31
31
|
|
32
32
|
it "does not count a currently running interval as an interval in calculations" do
|
33
33
|
@tm.start
|
34
|
-
@tm.value_stats.count.must_equal 0
|
35
|
-
@tm.timed_stats.count.must_equal 0
|
34
|
+
_(@tm.value_stats.count).must_equal 0
|
35
|
+
_(@tm.timed_stats.count).must_equal 0
|
36
36
|
@tm.split( 1 )
|
37
|
-
@tm.value_stats.count.must_equal 1
|
38
|
-
@tm.timed_stats.count.must_equal 1
|
37
|
+
_(@tm.value_stats.count).must_equal 1
|
38
|
+
_(@tm.timed_stats.count).must_equal 1
|
39
39
|
end
|
40
40
|
|
41
41
|
it "#split called on a stopped timer does nothing" do
|
42
42
|
@tm.start
|
43
43
|
@tm.stop( 1 )
|
44
|
-
@tm.split( 1 ).must_equal false
|
44
|
+
_(@tm.split( 1 )).must_equal false
|
45
45
|
end
|
46
46
|
|
47
47
|
it "calculates the mean of the durations" do
|
48
48
|
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop(x) }
|
49
|
-
@tm.timed_stats.mean.must_be_close_to(0.05, 0.01)
|
50
|
-
@tm.value_stats.mean.must_equal 1.00
|
49
|
+
_(@tm.timed_stats.mean).must_be_close_to(0.05, 0.01)
|
50
|
+
_(@tm.value_stats.mean).must_equal 1.00
|
51
51
|
end
|
52
52
|
|
53
53
|
it "calculates the rate of the counts " do
|
54
54
|
5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
55
|
-
@tm.rate.must_be_close_to(40.0, 1.0)
|
55
|
+
_(@tm.rate).must_be_close_to(40.0, 1.0)
|
56
56
|
end
|
57
57
|
|
58
58
|
|
59
59
|
it "calculates the stddev of the durations" do
|
60
60
|
3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop(x) }
|
61
|
-
@tm.timed_stats.stddev.must_be_close_to(0.05, 0.001)
|
62
|
-
@tm.value_stats.stddev.must_equal 1.0
|
61
|
+
_(@tm.timed_stats.stddev).must_be_close_to(0.05, 0.001)
|
62
|
+
_(@tm.value_stats.stddev).must_equal 1.0
|
63
63
|
end
|
64
64
|
|
65
65
|
it "returns 0.0 for stddev if there is no data" do
|
66
|
-
@tm.timed_stats.stddev.must_equal 0.0
|
67
|
-
@tm.value_stats.stddev.must_equal 0.0
|
66
|
+
_(@tm.timed_stats.stddev).must_equal 0.0
|
67
|
+
_(@tm.value_stats.stddev).must_equal 0.0
|
68
68
|
end
|
69
69
|
|
70
70
|
it "keeps track of the min value" do
|
71
71
|
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
72
|
-
@tm.timed_stats.min.must_be_close_to( 0.05, 0.003 )
|
73
|
-
@tm.value_stats.min.must_equal 0
|
72
|
+
_(@tm.timed_stats.min).must_be_close_to( 0.05, 0.003 )
|
73
|
+
_(@tm.value_stats.min).must_equal 0
|
74
74
|
end
|
75
75
|
|
76
76
|
it "keeps track of the max value" do
|
77
77
|
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
78
|
-
@tm.timed_stats.max.must_be_close_to( 0.05, 0.003 )
|
79
|
-
@tm.value_stats.max.must_equal 2
|
78
|
+
_(@tm.timed_stats.max).must_be_close_to( 0.05, 0.003 )
|
79
|
+
_(@tm.value_stats.max).must_equal 2
|
80
80
|
end
|
81
81
|
|
82
82
|
it "keeps track of the sum value" do
|
83
83
|
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
84
|
-
@tm.timed_stats.sum.must_be_close_to( 0.15, 0.01 )
|
85
|
-
@tm.value_stats.sum.must_equal 3
|
84
|
+
_(@tm.timed_stats.sum).must_be_close_to( 0.15, 0.01 )
|
85
|
+
_(@tm.value_stats.sum).must_equal 3
|
86
86
|
end
|
87
87
|
|
88
88
|
it "keeps track of the sum of squares value" do
|
89
89
|
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
90
|
-
@tm.timed_stats.sumsq.must_be_close_to(0.0075, 0.0005)
|
91
|
-
@tm.value_stats.sumsq.must_equal 5
|
90
|
+
_(@tm.timed_stats.sumsq).must_be_close_to(0.0075, 0.0005)
|
91
|
+
_(@tm.value_stats.sumsq).must_equal 5
|
92
92
|
end
|
93
93
|
|
94
94
|
it "keeps track of the minimum start time of all the intervals" do
|
95
95
|
f1 = Time.now.gmtime.to_f * 1000000
|
96
96
|
5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
|
97
97
|
f2 = Time.now.gmtime.to_f * 1000000
|
98
|
-
@tm.sampling_start_time.must_be :>=, f1
|
99
|
-
@tm.sampling_start_time.must_be :<, f2
|
98
|
+
_(@tm.sampling_start_time).must_be :>=, f1
|
99
|
+
_(@tm.sampling_start_time).must_be :<, f2
|
100
100
|
# distance from now to start time should be greater than the distance from
|
101
101
|
# the start to the min start_time
|
102
|
-
(f2 - @tm.sampling_start_time).must_be :>, ( @tm.sampling_start_time - f1 )
|
102
|
+
_((f2 - @tm.sampling_start_time)).must_be :>, ( @tm.sampling_start_time - f1 )
|
103
103
|
end
|
104
104
|
|
105
105
|
it "keeps track of the last stop time of all the intervals" do
|
@@ -107,56 +107,56 @@ describe Hitimes::TimedValueMetric do
|
|
107
107
|
5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
|
108
108
|
sleep 0.05
|
109
109
|
f2 = Time.now.gmtime.to_f * 1_000_000
|
110
|
-
@tm.sampling_stop_time.must_be :>, f1
|
111
|
-
@tm.sampling_stop_time.must_be :<=, f2
|
110
|
+
_(@tm.sampling_stop_time).must_be :>, f1
|
111
|
+
_(@tm.sampling_stop_time).must_be :<=, f2
|
112
112
|
# distance from now to max stop time time should be less than the distance
|
113
113
|
# from the start to the max stop time
|
114
|
-
(f2 - @tm.sampling_stop_time).must_be :<, ( @tm.sampling_stop_time - f1 )
|
114
|
+
_((f2 - @tm.sampling_stop_time)).must_be :<, ( @tm.sampling_stop_time - f1 )
|
115
115
|
end
|
116
116
|
|
117
117
|
it "can create an already running timer" do
|
118
118
|
t = Hitimes::TimedValueMetric.now( 'already-running' )
|
119
|
-
t.running
|
119
|
+
_(t.running?).must_equal true
|
120
120
|
end
|
121
121
|
|
122
122
|
it "can measure a block of code from an instance" do
|
123
123
|
t = Hitimes::TimedValueMetric.new( 'measure a block' )
|
124
124
|
3.times { t.measure( 1 ) { sleep 0.05 } }
|
125
|
-
t.duration.must_be_close_to(0.15, 0.004)
|
126
|
-
t.timed_stats.count.must_equal 3
|
127
|
-
t.value_stats.count.must_equal 3
|
125
|
+
_(t.duration).must_be_close_to(0.15, 0.004)
|
126
|
+
_(t.timed_stats.count).must_equal 3
|
127
|
+
_(t.value_stats.count).must_equal 3
|
128
128
|
end
|
129
129
|
|
130
130
|
it "returns the value of the block when measuring" do
|
131
131
|
t = Hitimes::TimedValueMetric.new( 'measure a block' )
|
132
132
|
x = t.measure( 42 ) { sleep 0.05; 42 }
|
133
|
-
t.duration.must_be_close_to(0.05, 0.002)
|
134
|
-
x.must_equal 42
|
133
|
+
_(t.duration).must_be_close_to(0.05, 0.002)
|
134
|
+
_(x).must_equal 42
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "#to_hash" do
|
138
138
|
|
139
139
|
it "has name value" do
|
140
140
|
h = @tm.to_hash
|
141
|
-
h['name'].must_equal "test-timed-value-metric"
|
141
|
+
_(h['name']).must_equal "test-timed-value-metric"
|
142
142
|
end
|
143
143
|
|
144
144
|
it "has an empty has for additional_data" do
|
145
145
|
h = @tm.to_hash
|
146
|
-
h['additional_data'].must_equal Hash.new
|
147
|
-
h['additional_data'].size.must_equal 0
|
146
|
+
_(h['additional_data']).must_equal Hash.new
|
147
|
+
_(h['additional_data'].size).must_equal 0
|
148
148
|
end
|
149
149
|
|
150
150
|
it "has a rate" do
|
151
151
|
5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
152
152
|
h = @tm.to_hash
|
153
|
-
h['rate'].must_be_close_to(40.0, 1.0)
|
153
|
+
_(h['rate']).must_be_close_to(40.0, 1.0)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "has a unit_count" do
|
157
157
|
5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
|
158
158
|
h = @tm.to_hash
|
159
|
-
h['unit_count'].must_equal 10
|
159
|
+
_(h['unit_count']).must_equal 10
|
160
160
|
end
|
161
161
|
|
162
162
|
fields = %w[ name additional_data sampling_start_time sampling_stop_time value_stats timed_stats rate unit_count ]
|
@@ -164,7 +164,7 @@ describe Hitimes::TimedValueMetric do
|
|
164
164
|
it "has a value for #{f}" do
|
165
165
|
3.times { |x| @tm.measure(x) { sleep 0.001 } }
|
166
166
|
h = @tm.to_hash
|
167
|
-
h[f].wont_be_nil
|
167
|
+
_(h[f]).wont_be_nil
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
data/spec/value_metric_spec.rb
CHANGED
@@ -7,50 +7,50 @@ describe Hitimes::ValueMetric do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'has a name' do
|
10
|
-
@metric.name.must_equal "testing"
|
10
|
+
_(@metric.name).must_equal "testing"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "has associated data from initialization" do
|
14
14
|
m = Hitimes::ValueMetric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
|
15
|
-
m.additional_data['foo'].must_equal 'bar'
|
16
|
-
m.additional_data['this'].must_equal 'that'
|
15
|
+
_(m.additional_data['foo']).must_equal 'bar'
|
16
|
+
_(m.additional_data['this']).must_equal 'that'
|
17
17
|
|
18
18
|
m = Hitimes::ValueMetric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
|
19
|
-
m.additional_data['foo'].must_equal 'bar'
|
20
|
-
m.additional_data['this'].must_equal 'that'
|
19
|
+
_(m.additional_data['foo']).must_equal 'bar'
|
20
|
+
_(m.additional_data['this']).must_equal 'that'
|
21
21
|
end
|
22
22
|
|
23
23
|
it "calculates the mean of the measurements" do
|
24
|
-
@metric.mean.must_equal 4.5
|
24
|
+
_(@metric.mean).must_equal 4.5
|
25
25
|
end
|
26
26
|
|
27
27
|
it "calculates the stddev of the measurements" do
|
28
|
-
@metric.stddev.must_be :>, 0.0
|
28
|
+
_(@metric.stddev).must_be :>, 0.0
|
29
29
|
end
|
30
30
|
|
31
31
|
it "returns 0.0 for stddev if there is no data" do
|
32
32
|
m = Hitimes::ValueMetric.new('0-data')
|
33
|
-
m.stddev.must_equal 0.0
|
33
|
+
_(m.stddev).must_equal 0.0
|
34
34
|
end
|
35
35
|
|
36
36
|
it "keeps track of the sum of data" do
|
37
|
-
@metric.sum.must_equal 45.0
|
37
|
+
_(@metric.sum).must_equal 45.0
|
38
38
|
end
|
39
39
|
|
40
40
|
it "keeps track of the sum of squars of data" do
|
41
|
-
@metric.sumsq.must_equal 285.0
|
41
|
+
_(@metric.sumsq).must_equal 285.0
|
42
42
|
end
|
43
43
|
|
44
44
|
it "retuns 0.0 for mean if there is no data" do
|
45
|
-
Hitimes::ValueMetric.new('0-data').mean.must_equal 0.0
|
45
|
+
_(Hitimes::ValueMetric.new('0-data').mean).must_equal 0.0
|
46
46
|
end
|
47
47
|
|
48
48
|
it "keeps track of the min value" do
|
49
|
-
@metric.min.must_equal 0
|
49
|
+
_(@metric.min).must_equal 0
|
50
50
|
end
|
51
51
|
|
52
52
|
it "keeps track of the max value" do
|
53
|
-
@metric.max.must_equal 9
|
53
|
+
_(@metric.max).must_equal 9
|
54
54
|
end
|
55
55
|
|
56
56
|
it "keeps track of the first start time of all the measurements" do
|
@@ -58,11 +58,11 @@ describe Hitimes::ValueMetric do
|
|
58
58
|
f1 = Time.now.gmtime.to_f * 1_000_000
|
59
59
|
10.times{ |x| m.measure( x ); sleep 0.1 }
|
60
60
|
f2 = Time.now.gmtime.to_f * 1_000_000
|
61
|
-
m.sampling_start_time.must_be :>=, f1
|
62
|
-
m.sampling_start_time.must_be :<, f2
|
61
|
+
_(m.sampling_start_time).must_be :>=, f1
|
62
|
+
_(m.sampling_start_time).must_be :<, f2
|
63
63
|
# distance from now to start time should be greater than the distance from
|
64
64
|
# the start to the min start_time
|
65
|
-
(f2 - m.sampling_start_time).must_be :>, ( m.sampling_start_time - f1 )
|
65
|
+
_((f2 - m.sampling_start_time)).must_be :>, ( m.sampling_start_time - f1 )
|
66
66
|
end
|
67
67
|
|
68
68
|
it "keeps track of the last stop time of all the intervals" do
|
@@ -70,29 +70,29 @@ describe Hitimes::ValueMetric do
|
|
70
70
|
f1 = Time.now.gmtime.to_f * 1_000_000
|
71
71
|
10.times {|x| m.measure( x ); sleep 0.1 }
|
72
72
|
f2 = Time.now.gmtime.to_f * 1_000_000
|
73
|
-
m.sampling_stop_time.must_be :>, f1
|
74
|
-
m.sampling_stop_time.must_be :<=, f2
|
73
|
+
_(m.sampling_stop_time).must_be :>, f1
|
74
|
+
_(m.sampling_stop_time).must_be :<=, f2
|
75
75
|
# distance from now to max stop time time should be less than the distance
|
76
76
|
# from the start to the max stop time
|
77
|
-
(f2 - m.sampling_stop_time).must_be :<, ( m.sampling_stop_time - f1 )
|
77
|
+
_((f2 - m.sampling_stop_time)).must_be :<, ( m.sampling_stop_time - f1 )
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "#to_hash" do
|
81
81
|
|
82
82
|
it "has name value" do
|
83
83
|
h = @metric.to_hash
|
84
|
-
h['name'].must_equal "testing"
|
84
|
+
_(h['name']).must_equal "testing"
|
85
85
|
end
|
86
86
|
|
87
87
|
it "has an empty has for additional_data" do
|
88
88
|
h = @metric.to_hash
|
89
|
-
h['additional_data'].must_equal Hash.new
|
90
|
-
h['additional_data'].size.must_equal 0
|
89
|
+
_(h['additional_data']).must_equal Hash.new
|
90
|
+
_(h['additional_data'].size).must_equal 0
|
91
91
|
end
|
92
92
|
|
93
93
|
it "has the right sum" do
|
94
94
|
h = @metric.to_hash
|
95
|
-
h['sum'].must_equal 45
|
95
|
+
_(h['sum']).must_equal 45
|
96
96
|
end
|
97
97
|
|
98
98
|
fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
|
@@ -100,7 +100,7 @@ describe Hitimes::ValueMetric do
|
|
100
100
|
fields.each do |f|
|
101
101
|
it "has a value for #{f}" do
|
102
102
|
h = @metric.to_hash
|
103
|
-
h[f].wont_be_nil
|
103
|
+
_(h[f]).wont_be_nil
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|