stella 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +14 -10
- data/Rakefile +22 -36
- data/lib/daemonize.rb +56 -0
- data/lib/stella/adapter/ab.rb +49 -39
- data/lib/stella/adapter/base.rb +17 -8
- data/lib/stella/adapter/httperf.rb +24 -18
- data/lib/stella/adapter/pcap_watcher.rb +1 -1
- data/lib/stella/adapter/siege.rb +15 -12
- data/lib/stella/cli/localtest.rb +2 -3
- data/lib/stella/cli/sysinfo.rb +0 -1
- data/lib/stella/cli.rb +10 -55
- data/lib/stella/command/base.rb +0 -62
- data/lib/stella/command/localtest.rb +35 -36
- data/lib/stella/data/domain.rb +18 -11
- data/lib/stella/data/http.rb +23 -16
- data/lib/stella/logger.rb +29 -19
- data/lib/stella/response.rb +5 -2
- data/lib/stella/storable.rb +138 -52
- data/lib/stella/support.rb +107 -8
- data/lib/stella/sysinfo.rb +26 -16
- data/lib/stella/test/definition.rb +1 -1
- data/lib/stella/test/run/summary.rb +23 -13
- data/lib/stella/test/stats.rb +114 -0
- data/lib/stella/text/resource.rb +1 -1
- data/lib/stella.rb +29 -4
- data/lib/utils/mathutil.rb +0 -76
- data/lib/utils/stats.rb +88 -0
- data/lib/win32/Console/ANSI.rb +305 -305
- data/lib/win32/Console.rb +970 -970
- data/support/ruby-pcap-takuma-patch.txt +13 -13
- data/support/text/en.yaml +11 -8
- data/support/text/nl.yaml +7 -1
- data/{spec/show-agents_spec.rb → tests/01-util_test.rb} +0 -0
- data/tests/02-stella-util_test.rb +42 -0
- data/tests/10-stella_test.rb +104 -0
- data/tests/11-stella-storable_test.rb +68 -0
- data/tests/60-stella-command_test.rb +248 -0
- data/tests/80-stella-cli_test.rb +45 -0
- data/tests/spec-helper.rb +31 -0
- data/vendor/{frylock/README.textile → drydock/LICENSE.txt} +2 -52
- data/vendor/drydock/README.textile +57 -0
- data/vendor/{frylock → drydock}/bin/example +14 -14
- data/vendor/{frylock/frylock.gemspec → drydock/drydock.gemspec} +1 -1
- data/vendor/{frylock/lib/frylock → drydock/lib/drydock}/exceptions.rb +1 -1
- data/vendor/{frylock/lib/frylock.rb → drydock/lib/drydock.rb} +8 -8
- data/vendor/{frylock → drydock}/test/command_test.rb +0 -0
- metadata +34 -61
- data/lib/stella/test/base.rb +0 -38
- data/lib/stella/test/summary.rb +0 -82
- data/vendor/hitimes-0.4.0/HISTORY +0 -28
- data/vendor/hitimes-0.4.0/LICENSE.txt +0 -19
- data/vendor/hitimes-0.4.0/README +0 -80
- data/vendor/hitimes-0.4.0/Rakefile +0 -63
- data/vendor/hitimes-0.4.0/examples/benchmarks.rb +0 -86
- data/vendor/hitimes-0.4.0/examples/stats.rb +0 -29
- data/vendor/hitimes-0.4.0/ext/extconf.rb +0 -15
- data/vendor/hitimes-0.4.0/ext/hitimes_ext.c +0 -21
- data/vendor/hitimes-0.4.0/ext/hitimes_instant_clock_gettime.c +0 -20
- data/vendor/hitimes-0.4.0/ext/hitimes_instant_osx.c +0 -16
- data/vendor/hitimes-0.4.0/ext/hitimes_instant_windows.c +0 -27
- data/vendor/hitimes-0.4.0/ext/hitimes_interval.c +0 -340
- data/vendor/hitimes-0.4.0/ext/hitimes_interval.h +0 -73
- data/vendor/hitimes-0.4.0/ext/hitimes_stats.c +0 -242
- data/vendor/hitimes-0.4.0/ext/hitimes_stats.h +0 -30
- data/vendor/hitimes-0.4.0/ext/rbconfig-mingw.rb +0 -178
- data/vendor/hitimes-0.4.0/ext/rbconfig.rb +0 -178
- data/vendor/hitimes-0.4.0/gemspec.rb +0 -54
- data/vendor/hitimes-0.4.0/lib/hitimes/mutexed_stats.rb +0 -23
- data/vendor/hitimes-0.4.0/lib/hitimes/paths.rb +0 -54
- data/vendor/hitimes-0.4.0/lib/hitimes/stats.rb +0 -29
- data/vendor/hitimes-0.4.0/lib/hitimes/timer.rb +0 -223
- data/vendor/hitimes-0.4.0/lib/hitimes/version.rb +0 -42
- data/vendor/hitimes-0.4.0/lib/hitimes.rb +0 -24
- data/vendor/hitimes-0.4.0/spec/interval_spec.rb +0 -115
- data/vendor/hitimes-0.4.0/spec/mutex_stats_spec.rb +0 -34
- data/vendor/hitimes-0.4.0/spec/paths_spec.rb +0 -14
- data/vendor/hitimes-0.4.0/spec/spec_helper.rb +0 -6
- data/vendor/hitimes-0.4.0/spec/stats_spec.rb +0 -72
- data/vendor/hitimes-0.4.0/spec/timer_spec.rb +0 -105
- data/vendor/hitimes-0.4.0/spec/version_spec.rb +0 -27
- data/vendor/hitimes-0.4.0/tasks/announce.rake +0 -39
- data/vendor/hitimes-0.4.0/tasks/config.rb +0 -107
- data/vendor/hitimes-0.4.0/tasks/distribution.rake +0 -53
- data/vendor/hitimes-0.4.0/tasks/documentation.rake +0 -33
- data/vendor/hitimes-0.4.0/tasks/extension.rake +0 -64
- data/vendor/hitimes-0.4.0/tasks/rspec.rake +0 -31
- data/vendor/hitimes-0.4.0/tasks/rubyforge.rake +0 -52
- data/vendor/hitimes-0.4.0/tasks/utils.rb +0 -80
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'hitimes'
|
2
|
-
require 'thread'
|
3
|
-
|
4
|
-
module Hitimes
|
5
|
-
class MutexedStats < Stats
|
6
|
-
def initialize
|
7
|
-
@mutex = Mutex.new
|
8
|
-
end
|
9
|
-
|
10
|
-
# call-seq:
|
11
|
-
# mutex_stat.update( val ) -> nil
|
12
|
-
#
|
13
|
-
# Update the running stats with the new value in a threadsafe manner.
|
14
|
-
#
|
15
|
-
def update( value )
|
16
|
-
@mutex.synchronize do
|
17
|
-
super( value )
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
@@ -1,54 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
-
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
-
#++
|
5
|
-
#
|
6
|
-
module Hitimes
|
7
|
-
#
|
8
|
-
# Access to various paths inside the project programatically
|
9
|
-
#
|
10
|
-
module Paths
|
11
|
-
#
|
12
|
-
# :call-seq:
|
13
|
-
# Hitimes::Paths.root_dir -> String
|
14
|
-
#
|
15
|
-
# Returns The full expanded path of the parent directory of +lib+
|
16
|
-
# going up the path from the current file. A trailing File::SEPARATOR
|
17
|
-
# is guaranteed.
|
18
|
-
#
|
19
|
-
def self.root_dir
|
20
|
-
unless @root_dir
|
21
|
-
path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR)
|
22
|
-
lib_index = path_parts.rindex("lib")
|
23
|
-
@root_dir = path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR
|
24
|
-
end
|
25
|
-
return @root_dir
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# :call-seq:
|
30
|
-
# Hitimes::Paths.lib_path( *args ) -> String
|
31
|
-
#
|
32
|
-
# Returns The full expanded path of the +lib+ directory below
|
33
|
-
# _root_dir_. All parameters passed in are joined onto the
|
34
|
-
# result. A trailing File::SEPARATOR is guaranteed if
|
35
|
-
# _args_ are *not* present.
|
36
|
-
#
|
37
|
-
def self.lib_path(*args)
|
38
|
-
self.sub_path("lib", *args)
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# :call-seq:
|
43
|
-
# Hitimes::Paths.sub_path( sub, *args ) -> String
|
44
|
-
#
|
45
|
-
# Returns the full expanded path of the +sub+ directory below _root_dir. All
|
46
|
-
# _arg_ parameters passed in are joined onto the result. A trailing
|
47
|
-
# File::SEPARATOR is guaranteed if _args_ are *not* present.
|
48
|
-
#
|
49
|
-
def self.sub_path(sub,*args)
|
50
|
-
sp = ::File.join(root_dir, sub) + File::SEPARATOR
|
51
|
-
sp = ::File.join(sp, *args) if args
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Hitimes
|
2
|
-
class Stats
|
3
|
-
# A list of the available stats
|
4
|
-
STATS = %w[ count max mean min rate stddev sum ]
|
5
|
-
|
6
|
-
#
|
7
|
-
# call-seq:
|
8
|
-
# stat.to_hash -> Hash
|
9
|
-
# stat.to_hash( %w[ count max mean ]) -> Hash
|
10
|
-
#
|
11
|
-
# return a hash of the stats. By default this returns a hash of all stats
|
12
|
-
# but passing in an array of items will limit the stats returned to only
|
13
|
-
# those in the Array.
|
14
|
-
#
|
15
|
-
# If passed in an empty array or nil to to_hash then STATS is assumed to be
|
16
|
-
# the list of stats to return in the hash.
|
17
|
-
#
|
18
|
-
def to_hash( *args )
|
19
|
-
h = {}
|
20
|
-
args = [ args ].flatten
|
21
|
-
args = STATS if args.empty?
|
22
|
-
args.each do |meth|
|
23
|
-
h[meth] = self.send( meth )
|
24
|
-
end
|
25
|
-
return h
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,223 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
-
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
-
#++
|
5
|
-
|
6
|
-
require 'hitimes'
|
7
|
-
require 'hitimes_ext'
|
8
|
-
|
9
|
-
module Hitimes
|
10
|
-
#
|
11
|
-
# A Timer combines together an Interval and a Stats object to provide
|
12
|
-
# aggregate information about timings.
|
13
|
-
#
|
14
|
-
# A Timer has many of the same methods as an Interval and would be used in
|
15
|
-
# preference to an Interval in those situations where you want to track
|
16
|
-
# statistics about the item you are monitoring.
|
17
|
-
#
|
18
|
-
class Timer
|
19
|
-
|
20
|
-
# holds all the statistics
|
21
|
-
attr_reader :stats
|
22
|
-
|
23
|
-
class << self
|
24
|
-
|
25
|
-
#
|
26
|
-
# :call-seq:
|
27
|
-
# Timer.now -> Timer
|
28
|
-
#
|
29
|
-
# Return a newly allocated Timer that has already been started
|
30
|
-
#
|
31
|
-
def now
|
32
|
-
t = Timer.new
|
33
|
-
t.start
|
34
|
-
return t
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# :call-seq:
|
39
|
-
# Timer.measure { ... } -> Float
|
40
|
-
#
|
41
|
-
# Return the number of seconds that a block of code took to
|
42
|
-
# execute.
|
43
|
-
#
|
44
|
-
def measure( &block )
|
45
|
-
Interval.measure { yield }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
#
|
50
|
-
# :call-seq:
|
51
|
-
# Timer.new -> Timer
|
52
|
-
#
|
53
|
-
def initialize
|
54
|
-
@stats = Stats.new
|
55
|
-
@current_interval = nil
|
56
|
-
end
|
57
|
-
|
58
|
-
#
|
59
|
-
# :call-seq:
|
60
|
-
# timer.current_interval -> Interval
|
61
|
-
#
|
62
|
-
# Return the current interval, if one doesn't exist create one.
|
63
|
-
#
|
64
|
-
def current_interval
|
65
|
-
@current_interval ||= Interval.new
|
66
|
-
end
|
67
|
-
|
68
|
-
#
|
69
|
-
# :call-seq:
|
70
|
-
# timer.running? -> true or false
|
71
|
-
#
|
72
|
-
# return whether or not the timer is currently running.
|
73
|
-
#
|
74
|
-
def running?
|
75
|
-
current_interval.running?
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# :call-seq:
|
80
|
-
# timer.start -> nil
|
81
|
-
#
|
82
|
-
# Start the current timer, if the current timer is already started, then
|
83
|
-
# this is a noop.
|
84
|
-
#
|
85
|
-
def start
|
86
|
-
current_interval.start unless running?
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# :call-seq:
|
92
|
-
# timer.stop -> Float or nil
|
93
|
-
#
|
94
|
-
# Stop the current timer. This updates the stats and removes the current
|
95
|
-
# interval. If the timer is not running then this is a noop. If the
|
96
|
-
# timer was stopped then the duration of the last Interval is returned. If
|
97
|
-
# the timer was already stopped then false is returned.
|
98
|
-
#
|
99
|
-
def stop
|
100
|
-
if running? then
|
101
|
-
d = current_interval.stop
|
102
|
-
@current_interval = nil
|
103
|
-
stats.update( d )
|
104
|
-
return d
|
105
|
-
end
|
106
|
-
return false
|
107
|
-
end
|
108
|
-
|
109
|
-
#
|
110
|
-
# :call-seq:
|
111
|
-
# timer.measure { ... } -> Float
|
112
|
-
#
|
113
|
-
# Measure the execution of a block and add those stats to the running stats.
|
114
|
-
#
|
115
|
-
def measure( &block )
|
116
|
-
t = 0.0
|
117
|
-
begin
|
118
|
-
start
|
119
|
-
yield
|
120
|
-
ensure
|
121
|
-
t = stop
|
122
|
-
end
|
123
|
-
return t
|
124
|
-
end
|
125
|
-
|
126
|
-
#
|
127
|
-
# :call-seq:
|
128
|
-
# timer.split -> Flaot
|
129
|
-
#
|
130
|
-
# Split the current timer. Essentially, mark a split time. This means
|
131
|
-
# stop the current interval and create a new interval, but make sure
|
132
|
-
# that the new interval lines up exactly, timewise, behind the previous
|
133
|
-
# interval.
|
134
|
-
#
|
135
|
-
# If the timer is running, then split returns the duration of the previous
|
136
|
-
# interval, i.e. the split-time. If the timer is not running, nothing
|
137
|
-
# happens and false is returned.
|
138
|
-
#
|
139
|
-
def split
|
140
|
-
if running? then
|
141
|
-
next_interval = current_interval.split
|
142
|
-
d = current_interval.duration
|
143
|
-
stats.update( d )
|
144
|
-
@current_interval = next_interval
|
145
|
-
return d
|
146
|
-
end
|
147
|
-
return false
|
148
|
-
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# :call-seq:
|
152
|
-
# timer.sum -> Float
|
153
|
-
# timer.duration -> Float
|
154
|
-
#
|
155
|
-
# The total time the timer has been measuring.
|
156
|
-
#
|
157
|
-
def sum
|
158
|
-
stats.sum
|
159
|
-
end
|
160
|
-
alias duration sum
|
161
|
-
|
162
|
-
#
|
163
|
-
# :call-seq:
|
164
|
-
# timer.mean -> Float
|
165
|
-
#
|
166
|
-
# The mean value of all the the stopped intervals. The current interval, if
|
167
|
-
# it is still running, is not included.
|
168
|
-
#
|
169
|
-
def mean
|
170
|
-
stats.mean
|
171
|
-
end
|
172
|
-
|
173
|
-
#
|
174
|
-
# :call-seq:
|
175
|
-
# timer.rate -> Float
|
176
|
-
#
|
177
|
-
# Return the rate of the states, which is the count / duration
|
178
|
-
#
|
179
|
-
def rate
|
180
|
-
stats.rate
|
181
|
-
end
|
182
|
-
|
183
|
-
#
|
184
|
-
# :call-seq:
|
185
|
-
# timer.stddev -> Float
|
186
|
-
#
|
187
|
-
# The standard deviation of all the intervals
|
188
|
-
#
|
189
|
-
def stddev
|
190
|
-
stats.stddev
|
191
|
-
end
|
192
|
-
|
193
|
-
#
|
194
|
-
# :call-seq:
|
195
|
-
# timer.count -> Integer
|
196
|
-
#
|
197
|
-
# The count of intervals in this timer
|
198
|
-
#
|
199
|
-
def count
|
200
|
-
stats.count
|
201
|
-
end
|
202
|
-
|
203
|
-
#
|
204
|
-
# :call-seq:
|
205
|
-
# timer.max -> Float
|
206
|
-
#
|
207
|
-
# The maximum duration of all the intervals this Timer has seen
|
208
|
-
#
|
209
|
-
def max
|
210
|
-
stats.max
|
211
|
-
end
|
212
|
-
|
213
|
-
#
|
214
|
-
# :call-seq:
|
215
|
-
# timer.min -> Float
|
216
|
-
#
|
217
|
-
# The minimum duration of all the intervals this Timer has seen
|
218
|
-
#
|
219
|
-
def min
|
220
|
-
stats.min
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
-
# All rights reserved. See LICENSE and/or COPYING for details
|
4
|
-
#++
|
5
|
-
|
6
|
-
module Hitimes
|
7
|
-
#
|
8
|
-
# module containing all the version information about Hitimes
|
9
|
-
#
|
10
|
-
module Version
|
11
|
-
|
12
|
-
MAJOR = 0
|
13
|
-
MINOR = 4
|
14
|
-
BUILD = 0
|
15
|
-
|
16
|
-
#
|
17
|
-
# :call-seq:
|
18
|
-
# Version.to_a -> [ MAJOR, MINOR, BUILD ]
|
19
|
-
#
|
20
|
-
# Return the version as an array of Integers
|
21
|
-
#
|
22
|
-
def to_a
|
23
|
-
[MAJOR, MINOR, BUILD]
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# :call-seq:
|
28
|
-
# Version.to_s -> MAJOR.MINOR.BUILD
|
29
|
-
#
|
30
|
-
# Return the version as a String with dotted notation
|
31
|
-
#
|
32
|
-
def to_s
|
33
|
-
to_a.join(".")
|
34
|
-
end
|
35
|
-
|
36
|
-
module_function :to_a
|
37
|
-
module_function :to_s
|
38
|
-
|
39
|
-
STRING = Version.to_s
|
40
|
-
end
|
41
|
-
VERSION = Version.to_s
|
42
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
-
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
-
#++
|
5
|
-
|
6
|
-
#
|
7
|
-
# The top level module containing the contents of the hitimes library
|
8
|
-
#
|
9
|
-
# use the library with:
|
10
|
-
#
|
11
|
-
# require 'hitimes'
|
12
|
-
#
|
13
|
-
module Hitimes
|
14
|
-
#
|
15
|
-
# Base class of all errors in Hitimes
|
16
|
-
#
|
17
|
-
class Error < ::StandardError; end
|
18
|
-
end
|
19
|
-
require 'hitimes/paths'
|
20
|
-
require 'hitimes/version'
|
21
|
-
require 'hitimes/stats'
|
22
|
-
require 'hitimes/mutexed_stats'
|
23
|
-
require 'hitimes/timer'
|
24
|
-
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
-
|
3
|
-
require 'hitimes_ext'
|
4
|
-
|
5
|
-
describe Hitimes::Interval do
|
6
|
-
it "has a 0 duration when newly created" do
|
7
|
-
i = Hitimes::Interval.new
|
8
|
-
i.duration == 0.0
|
9
|
-
end
|
10
|
-
|
11
|
-
it "knows if it has been started" do
|
12
|
-
i = Hitimes::Interval.new
|
13
|
-
i.should_not be_started
|
14
|
-
|
15
|
-
i.start
|
16
|
-
i.should be_started
|
17
|
-
end
|
18
|
-
|
19
|
-
it "knows if it has been stopped" do
|
20
|
-
i = Hitimes::Interval.new
|
21
|
-
i.start
|
22
|
-
i.should_not be_stopped
|
23
|
-
i.stop
|
24
|
-
i.should be_stopped
|
25
|
-
end
|
26
|
-
|
27
|
-
it "knows if it is currently running" do
|
28
|
-
i = Hitimes::Interval.new
|
29
|
-
i.should_not be_running
|
30
|
-
i.start
|
31
|
-
i.should be_running
|
32
|
-
i.stop
|
33
|
-
i.should_not be_running
|
34
|
-
end
|
35
|
-
|
36
|
-
it "can time a block of code" do
|
37
|
-
d = Hitimes::Interval.measure do
|
38
|
-
sleep 0.2
|
39
|
-
end
|
40
|
-
d.should be_close(0.2, 0.01)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "raises an error if measure is called with no block" do
|
44
|
-
lambda{ Hitimes::Interval.measure }.should raise_error( Hitimes::Error )
|
45
|
-
end
|
46
|
-
|
47
|
-
it "creates an interval via #now" do
|
48
|
-
i = Hitimes::Interval.now
|
49
|
-
i.should be_started
|
50
|
-
i.should_not be_stopped
|
51
|
-
end
|
52
|
-
|
53
|
-
it "calling duration multiple times returns successivly grater durations" do
|
54
|
-
i = Hitimes::Interval.new
|
55
|
-
i.start
|
56
|
-
y = i.duration
|
57
|
-
z = i.duration
|
58
|
-
z.should > y
|
59
|
-
end
|
60
|
-
|
61
|
-
it "calling start multiple times on has no effect after the first call" do
|
62
|
-
i = Hitimes::Interval.new
|
63
|
-
i.start.should == true
|
64
|
-
x = i.start_instant
|
65
|
-
i.start_instant.should > 0
|
66
|
-
i.start.should == false
|
67
|
-
x.should == i.start_instant
|
68
|
-
end
|
69
|
-
|
70
|
-
it "returns the duration on the first call to stop" do
|
71
|
-
i = Hitimes::Interval.now
|
72
|
-
d = i.stop
|
73
|
-
d.should be_instance_of( Float )
|
74
|
-
end
|
75
|
-
|
76
|
-
it "calling stop multiple times on has no effect after the first call" do
|
77
|
-
i = Hitimes::Interval.new
|
78
|
-
i.start.should == true
|
79
|
-
i.stop
|
80
|
-
|
81
|
-
x = i.stop_instant
|
82
|
-
i.stop_instant.should > 0
|
83
|
-
i.stop.should == false
|
84
|
-
x.should == i.stop_instant
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
it "only calculates duration once after stop is called" do
|
89
|
-
i = Hitimes::Interval.new
|
90
|
-
i.start
|
91
|
-
i.stop
|
92
|
-
x = i.duration
|
93
|
-
y = i.duration
|
94
|
-
x.object_id.should == y.object_id
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#split" do
|
98
|
-
|
99
|
-
it "creates a new Interval object" do
|
100
|
-
i = Hitimes::Interval.new
|
101
|
-
i.start
|
102
|
-
i2 = i.split
|
103
|
-
i.object_id.should_not == i2.object_id
|
104
|
-
end
|
105
|
-
|
106
|
-
it "with the stop instant equivialent to the previous Interval's start instant" do
|
107
|
-
i = Hitimes::Interval.new
|
108
|
-
i.start
|
109
|
-
i2 = i.split
|
110
|
-
i.stop_instant.should == i2.start_instant
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
-
|
3
|
-
require 'hitimes_ext'
|
4
|
-
require 'hitimes/mutexed_stats'
|
5
|
-
|
6
|
-
describe Hitimes::MutexedStats do
|
7
|
-
before( :each ) do
|
8
|
-
@threads = 5
|
9
|
-
@iters = 10_000
|
10
|
-
@final_value = @threads * @iters
|
11
|
-
end
|
12
|
-
|
13
|
-
def run_with_scissors( stats, threads, iters )
|
14
|
-
spool = []
|
15
|
-
threads.times do |t|
|
16
|
-
spool << Thread.new { iters.times{ stats.update( 1 ) } }
|
17
|
-
end
|
18
|
-
spool.each { |t| t.join }
|
19
|
-
return stats
|
20
|
-
end
|
21
|
-
|
22
|
-
it "is unsafe normally" do
|
23
|
-
pending "not for MRI -- not interruptable in this C extension" do
|
24
|
-
stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
|
25
|
-
stats.count.should_not == @final_value
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "has a threadsafe update" do
|
30
|
-
stats = run_with_scissors( ::Hitimes::MutexedStats.new, @threads, @iters )
|
31
|
-
stats.count.should == @final_value
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
-
|
3
|
-
require 'hitimes/paths'
|
4
|
-
|
5
|
-
describe Hitimes::Paths do
|
6
|
-
it "can access the root dir of the project" do
|
7
|
-
Hitimes::Paths.root_dir.should == File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
|
8
|
-
end
|
9
|
-
|
10
|
-
it "can access the lib path of the project" do
|
11
|
-
Hitimes::Paths.lib_path.should == File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
-
|
3
|
-
require 'hitimes_ext'
|
4
|
-
|
5
|
-
describe Hitimes::Stats do
|
6
|
-
before( :each ) do
|
7
|
-
@stats = Hitimes::Stats.new
|
8
|
-
@full_stats = Hitimes::Stats.new
|
9
|
-
|
10
|
-
[ 1, 2, 3].each { |i| @full_stats.update( i ) }
|
11
|
-
end
|
12
|
-
|
13
|
-
it "is initialized with 0 values" do
|
14
|
-
@stats.count.should == 0
|
15
|
-
@stats.min.should == 0.0
|
16
|
-
@stats.max.should == 0.0
|
17
|
-
@stats.sum.should == 0.0
|
18
|
-
@stats.rate.should == 0.0
|
19
|
-
end
|
20
|
-
|
21
|
-
it "calculates the mean correctly" do
|
22
|
-
@full_stats.mean.should == 2.0
|
23
|
-
end
|
24
|
-
|
25
|
-
it "calculates the rate correctly" do
|
26
|
-
@full_stats.rate.should == 0.5
|
27
|
-
end
|
28
|
-
|
29
|
-
it "tracks the maximum value" do
|
30
|
-
@full_stats.max.should == 3.0
|
31
|
-
end
|
32
|
-
|
33
|
-
it "tracks the minimum value" do
|
34
|
-
@full_stats.min.should == 1.0
|
35
|
-
end
|
36
|
-
|
37
|
-
it "tracks the count" do
|
38
|
-
@full_stats.count.should == 3
|
39
|
-
end
|
40
|
-
|
41
|
-
it "tracks the sum" do
|
42
|
-
@full_stats.sum.should == 6.0
|
43
|
-
end
|
44
|
-
|
45
|
-
it "calculates the standard deviation" do
|
46
|
-
@full_stats.stddev.should == 1.0
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#to_hash " do
|
50
|
-
it "converts to a Hash" do
|
51
|
-
h = @full_stats.to_hash
|
52
|
-
h.size.should == ::Hitimes::Stats::STATS.size
|
53
|
-
h.keys.sort.should == ::Hitimes::Stats::STATS
|
54
|
-
end
|
55
|
-
|
56
|
-
it "converts to a limited Hash if given arguments" do
|
57
|
-
h = @full_stats.to_hash( "min", "max", "mean" )
|
58
|
-
h.size.should == 3
|
59
|
-
h.keys.sort.should == %w[ max mean min ]
|
60
|
-
|
61
|
-
h = @full_stats.to_hash( %w[ count rate ] )
|
62
|
-
h.size.should == 2
|
63
|
-
h.keys.sort.should == %w[ count rate ]
|
64
|
-
end
|
65
|
-
|
66
|
-
it "raises NoMethodError if an invalid stat is used" do
|
67
|
-
lambda { @full_stats.to_hash( "wibble" ) }.should raise_error( NoMethodError )
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|