allotment 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +52 -0
- data/{LICENSE.md → License.md} +0 -0
- data/README.md +121 -33
- data/lib/allotment.rb +80 -45
- data/lib/allotment/array.rb +4 -0
- data/lib/allotment/cucumber.rb +2 -6
- data/lib/allotment/stopwatch.rb +98 -41
- data/lib/allotment/version.rb +5 -3
- data/spec/allotment_spec.rb +66 -76
- data/spec/{stopwatch/array_spec.rb → array_spec.rb} +2 -0
- data/spec/helper.rb +2 -4
- data/spec/stopwatch_spec.rb +268 -0
- metadata +30 -18
- data/allotment.gemspec +0 -29
- data/lib/allotment/methods.rb +0 -23
- data/spec/stopwatch/methods_spec.rb +0 -130
- data/spec/stopwatch/stopwatch_spec.rb +0 -145
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a732dd5ecc0207f646b2bf89f1bbc6adc3183ac9
|
4
|
+
data.tar.gz: 4ee65868e53130c4e6f253cd8db45b4507783717
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c21e210e1c779334d6c9423c013a525aec0e3c143715c94789690bc66174a74293a39ad9ffd8f4665d5f92d1ac36326c07ca541f866a60086417f7e782579a
|
7
|
+
data.tar.gz: ba69049b2c17d5efec5bd7570cba4a96d0f16e8ed81a4f9dfa3c980d32a80b5568bfc6e543b099473cb65a46ff01a413a5eb61437a31ba7acad68d0fe9303774
|
data/History.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# History
|
2
|
+
## Planned Versions
|
3
|
+
### Version 1.1.0
|
4
|
+
#### Minor: Simplify, improve, clean
|
5
|
+
##### Changed
|
6
|
+
* Rescue within an event to ensure that the timing is stopped in the event of a failure
|
7
|
+
* Remove old hooks and add new block management
|
8
|
+
* Remove and old or unrequired code
|
9
|
+
* Improved method naming
|
10
|
+
* Moved history and license into root
|
11
|
+
|
12
|
+
##### Added
|
13
|
+
* Readme completed with hooks, stopwatches and now functionality
|
14
|
+
* 100% coverage rspec tests
|
15
|
+
* Complete commenting of code
|
16
|
+
* Added Rakefile and Tasks
|
17
|
+
|
18
|
+
##### Fixed
|
19
|
+
* Updated Stopwatch
|
20
|
+
* Updated Stopwatch Specs
|
21
|
+
|
22
|
+
### Version 1.0.4
|
23
|
+
#### Patch: Added before and after hooks
|
24
|
+
* Added before and after hooks
|
25
|
+
* Created hooks rspec tests
|
26
|
+
* Had to change allotment into class for hooks
|
27
|
+
* Split instance methods into seprate file
|
28
|
+
* Created release notes
|
29
|
+
|
30
|
+
### Version 1.0.3
|
31
|
+
#### Patch: Updated and added files
|
32
|
+
* Updated Gemfile
|
33
|
+
* Updated gemspec
|
34
|
+
* Added Version
|
35
|
+
* Added Licence
|
36
|
+
|
37
|
+
### Version 1.0.2
|
38
|
+
#### Patch: Results returned as Hashie::Mash
|
39
|
+
* results methods now return results as a Hashie::Mash
|
40
|
+
|
41
|
+
### Version 1.0.1
|
42
|
+
#### Patch: Added instance methods
|
43
|
+
* Added instance methods so that the module can be included into a class and allotment does not need to be called every time.
|
44
|
+
* Cleaned up stopwatch so that it had lap and split
|
45
|
+
|
46
|
+
## Released Versions
|
47
|
+
### Version 1.0.0
|
48
|
+
#### Major: Inital release version.
|
49
|
+
* Allotment has the ablility to record blocks and procs, and to record from two separate points within the code.
|
50
|
+
* Stopwatch has been completed and can start, stop, split, lap and restart.
|
51
|
+
* There is an extention of Array for an average.
|
52
|
+
* There is Cucumber support, a cucumber file has been included that will record scenario and test time.
|
data/{LICENSE.md → License.md}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
## "Time is what we want most, but what we use worst."
|
2
2
|
|
3
3
|
[](https://codeclimate.com/github/benSlaughter/allotment)
|
4
4
|
[](https://travis-ci.org/benSlaughter/allotment)
|
@@ -6,18 +6,31 @@
|
|
6
6
|
[](https://coveralls.io/r/benSlaughter/allotment)
|
7
7
|
[](http://badge.fury.io/rb/allotment)
|
8
8
|
|
9
|
-
Allotment is a performance
|
10
|
-
|
9
|
+
Allotment is a performance time recording gem.
|
10
|
+
It makes recording performance simple, while still being powerful and flexible.
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
Allotment gives you the ability to record the performance of code with ease, and all the while it will store all your results as your code runs.
|
13
|
+
Results can be acessed at any time from anywhere.
|
14
|
+
Recordings are grouped together under their name and an average of the results can be caluculated easily.
|
15
|
+
No threads where harmed in the making of this gem, no threads are used, and this makes Allotment lightweight and simple.
|
14
16
|
|
15
|
-
|
17
|
+
### Cucumber
|
18
|
+
|
19
|
+
Allotment also plays well with cucumber.
|
20
|
+
|
21
|
+
A before and after hook records each scenarios completion time.
|
22
|
+
|
23
|
+
_See [Cucumber](#using-allotment-with-cucumber)_
|
24
|
+
|
25
|
+
### Limitations
|
26
|
+
|
27
|
+
* Allotment cannot run two simultaneous recordings of the same name at the same time.
|
28
|
+
* Allotment has only one set of results and cannot record to diferent results. (e.g. performance and load)
|
16
29
|
|
17
30
|
## Setup
|
18
31
|
|
19
32
|
Allotment has been tested with Ruby 1.9.2 and later.
|
20
|
-
To install
|
33
|
+
To install:
|
21
34
|
|
22
35
|
```bash
|
23
36
|
gem install allotment
|
@@ -25,7 +38,8 @@ gem install allotment
|
|
25
38
|
|
26
39
|
## Using Allotment with Cucumber
|
27
40
|
|
28
|
-
If you are using Cucumber you can record each scenario
|
41
|
+
If you are using Cucumber you can record each scenario.
|
42
|
+
Add this line into your env.rb file:
|
29
43
|
|
30
44
|
```ruby
|
31
45
|
require 'allotment/cucumber'
|
@@ -33,70 +47,87 @@ require 'allotment/cucumber'
|
|
33
47
|
|
34
48
|
## Using Allotment
|
35
49
|
|
36
|
-
|
37
|
-
|
38
|
-
Require Allotment at the start of your code:
|
50
|
+
Require Allotment at the start of your code
|
39
51
|
|
40
52
|
```ruby
|
41
53
|
require 'allotment'
|
42
54
|
```
|
43
55
|
|
44
56
|
### Recording a Block
|
45
|
-
|
46
|
-
The basic way of recording a block is as follows:
|
57
|
+
Recording a block of code could not be simpler.
|
47
58
|
|
48
59
|
```ruby
|
49
|
-
Allotment.
|
60
|
+
Allotment.record('my_recording') { # code here }
|
50
61
|
```
|
51
62
|
```ruby
|
52
|
-
Allotment.
|
63
|
+
Allotment.record('my_recording') do
|
53
64
|
# code here
|
54
65
|
end
|
55
66
|
```
|
56
67
|
|
57
|
-
When an event has been completed the performance timing is returned by the method
|
68
|
+
When an event has been completed the performance timing is returned by the method.
|
58
69
|
|
59
70
|
```ruby
|
60
|
-
performance = Allotment.
|
71
|
+
performance = Allotment.record { # code here }
|
61
72
|
```
|
62
73
|
```ruby
|
63
|
-
performance = Allotment.
|
74
|
+
performance = Allotment.record do
|
64
75
|
# code here
|
65
76
|
end
|
66
77
|
```
|
67
78
|
|
68
|
-
### Record point to point
|
79
|
+
### Record point to point
|
69
80
|
|
70
|
-
|
81
|
+
Sometime you may want to record performance of more than just a block.
|
82
|
+
Allotment can do that too.
|
71
83
|
|
72
84
|
```ruby
|
73
|
-
|
74
|
-
|
75
|
-
Allotment.start_recording 'my_recording'
|
85
|
+
Allotment.start 'my_recording'
|
76
86
|
# code here
|
77
|
-
Allotment.
|
87
|
+
Allotment.stop 'my_recording'
|
78
88
|
```
|
79
89
|
|
80
|
-
When stop
|
90
|
+
When stop is called the performance timing is returned by the method.
|
81
91
|
|
82
92
|
```ruby
|
83
|
-
performance = Allotment.
|
93
|
+
performance = Allotment.stop 'my_recording'
|
84
94
|
```
|
85
95
|
|
86
|
-
When start recording is called the timing stopwatch is returned by the method
|
96
|
+
When start recording is called the timing stopwatch is returned by the method.
|
87
97
|
|
88
98
|
```ruby
|
89
|
-
stopwatch = Allotment.
|
99
|
+
stopwatch = Allotment.start 'my_recording'
|
90
100
|
```
|
91
101
|
|
92
102
|
_More on [stopwatches](#allotment-stopwatches)_
|
93
103
|
|
94
|
-
If a recording name does not exists, then a NameError
|
104
|
+
**Warning!** If a recording name does not exists, then a NameError is raised.
|
105
|
+
|
106
|
+
### Hooks
|
107
|
+
|
108
|
+
Allotment has two inbuilt hooks, on_start, and on_stop.
|
109
|
+
Each hook contains a single proc that is called at points within recordings.
|
110
|
+
|
111
|
+
The on_start hook is called before the timer is started.
|
112
|
+
The on_stop hook is called after the timer is stopped.
|
113
|
+
|
114
|
+
A hook can be redefined at any time.
|
115
|
+
To define a hook call the hook and pass in a proc.
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
Allotment.on_start { # Extra code here }
|
119
|
+
```
|
120
|
+
```ruby
|
121
|
+
Allotment.on_start do
|
122
|
+
# Extra code here
|
123
|
+
end
|
124
|
+
```
|
95
125
|
|
96
126
|
### Accessing performance results
|
97
127
|
|
98
|
-
|
99
|
-
|
128
|
+
Allotment stores all the performance recordings as and when they happen.
|
129
|
+
If multiple recording of the same event exist they are stored in an array.
|
130
|
+
Allotment also patches Array with an average function.
|
100
131
|
|
101
132
|
```ruby
|
102
133
|
hash = Allotment.results
|
@@ -111,7 +142,64 @@ result = Allotment.results["my_recording"].first
|
|
111
142
|
result = Allotment.results["my_recording"].average
|
112
143
|
```
|
113
144
|
|
114
|
-
|
145
|
+
## Allotment Stopwatches
|
146
|
+
|
147
|
+
Stopwatches are what Allotment uses to keep track of time.
|
148
|
+
Strangely enough they act just like a stopwatch.
|
149
|
+
|
150
|
+
### Basic usage
|
151
|
+
|
152
|
+
Stopwatches live inside the Allotment module.
|
153
|
+
When created, a stopwatch is not running, however the start method returns the stopwatch, and so can be called inline.
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
sw = Allotment::Stopwatch.new
|
157
|
+
```
|
158
|
+
```ruby
|
159
|
+
sw = Allotment::Stopwatch.new.start
|
160
|
+
```
|
161
|
+
|
162
|
+
When stopping a stopwatch, the time that is currently on the stopwatch is returned
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
time = sw.stop
|
166
|
+
```
|
167
|
+
|
168
|
+
Reset will wipe all times clean, and completely reset the time.
|
169
|
+
Reset can be called at any time.
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
sw.reset
|
173
|
+
```
|
174
|
+
|
175
|
+
### Advanced usage
|
176
|
+
|
177
|
+
A stopwatch has the ability to lap, spit, and view the current time.
|
178
|
+
Each method behaves in a slightly different way.
|
179
|
+
* Lap is the time elapsed from the last time a lap was called.
|
180
|
+
* Split is the time from the last time the stopwatch was started.
|
181
|
+
* Time is the total time from when the stopwatch was first started.
|
182
|
+
|
183
|
+
When the stop watch is run and the methods are called.
|
184
|
+
```
|
185
|
+
30 seconds
|
186
|
+
start end
|
187
|
+
|--------------------------|
|
188
|
+
Lap |---10---|---10---|---10---|
|
189
|
+
Split |---10---|---20---|---30---|
|
190
|
+
Time |---10---|---20---|---30---|
|
191
|
+
```
|
192
|
+
|
193
|
+
When the stopwatch is stopped and the methods are called.
|
194
|
+
```
|
195
|
+
30 seconds with 10 second stop
|
196
|
+
start
|
197
|
+
Lap |---10---| |---10---|
|
198
|
+
Split |---10---| |---10---|
|
199
|
+
Time |---10---| |---20---|
|
200
|
+
```
|
115
201
|
|
116
|
-
|
202
|
+
## Notes
|
117
203
|
|
204
|
+
Stopwatches use ruby Time to calculate the time between a start and a stop.
|
205
|
+
Allotment rspec tests need to be improved upon.
|
data/lib/allotment.rb
CHANGED
@@ -1,49 +1,84 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'hashie'
|
3
|
+
|
1
4
|
require 'allotment/array'
|
2
5
|
require 'allotment/stopwatch'
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
7
|
+
# Allotment
|
8
|
+
# "Time is what we want most, but what we use worst."
|
9
|
+
#
|
10
|
+
# require 'allotment'
|
11
|
+
#
|
12
|
+
# Allotment.record 'my_event' do
|
13
|
+
# # code here
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Allotment.start 'my_event'
|
17
|
+
# # code here
|
18
|
+
# Allotment.stop 'my_event'
|
19
|
+
#
|
20
|
+
module Allotment
|
21
|
+
@watches = Hashie::Mash.new
|
22
|
+
@results = Hashie::Mash.new
|
23
|
+
|
24
|
+
# Allotment module methods
|
25
|
+
class << self
|
26
|
+
# Called when a recording is started
|
27
|
+
# @return [Proc] the stored request proc
|
28
|
+
#
|
29
|
+
def on_start &block
|
30
|
+
block_given? ? @on_start = block : @on_start
|
31
|
+
end
|
32
|
+
|
33
|
+
# Called when a recording is stopped
|
34
|
+
# @return [Proc] the stored request proc
|
35
|
+
#
|
36
|
+
def on_stop &block
|
37
|
+
block_given? ? @on_stop = block : @on_stop
|
38
|
+
end
|
39
|
+
|
40
|
+
# Start recording
|
41
|
+
# @param name [String] the name of the event
|
42
|
+
#
|
43
|
+
def start name = 'unnamed_recording'
|
44
|
+
on_start.call if on_start
|
45
|
+
@watches[name] = Stopwatch.new(name).start
|
46
|
+
end
|
47
|
+
|
48
|
+
# Stop recording
|
49
|
+
# @param name [String] the name of the event
|
50
|
+
# @raise [NameError] if the recording does not exist
|
51
|
+
#
|
52
|
+
def stop name
|
53
|
+
result = @watches.delete(name){ |n| raise NameError, "Unknown recording:" + n }.stop
|
54
|
+
on_stop.call if on_stop
|
55
|
+
|
56
|
+
# Dealing with the results
|
57
|
+
@results[name] ||= Array.new
|
58
|
+
@results[name] << result
|
59
|
+
return result
|
60
|
+
end
|
61
|
+
|
62
|
+
# Record event
|
63
|
+
# Expects a block to be passed
|
64
|
+
# @param name [String] the name of the event
|
65
|
+
# @yield [] runs the event
|
66
|
+
#
|
67
|
+
def record name = 'unnamed_event'
|
68
|
+
start name
|
69
|
+
begin
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
result = stop name
|
73
|
+
end
|
74
|
+
result
|
75
|
+
end
|
76
|
+
|
77
|
+
# Results at that present moment
|
78
|
+
# @return [Hashie::Mash] the current results
|
79
|
+
#
|
80
|
+
def results
|
81
|
+
@results
|
82
|
+
end
|
83
|
+
end
|
49
84
|
end
|
data/lib/allotment/array.rb
CHANGED
data/lib/allotment/cucumber.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'allotment'
|
2
2
|
|
3
3
|
Before do |scenario|
|
4
|
-
|
4
|
+
Allotment.start scenario.title
|
5
5
|
end
|
6
6
|
|
7
7
|
After do |scenario|
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
at_exit do
|
12
|
-
puts Allotment.results_string
|
8
|
+
Allotment.stop scenario.title
|
13
9
|
end
|