hitimes 1.0.0-x86-mswin32-60 → 1.0.1-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +5 -0
- data/examples/benchmarks.rb +38 -11
- data/examples/stats.rb +3 -1
- data/ext/hitimes_interval.c +30 -0
- data/lib/hitimes.rb +1 -1
- data/lib/hitimes/metric.rb +51 -13
- data/lib/hitimes/stats.rb +1 -1
- data/lib/hitimes/timed_metric.rb +17 -21
- data/lib/hitimes/timed_value_metric.rb +17 -22
- data/lib/hitimes/value_metric.rb +6 -3
- data/lib/hitimes/version.rb +1 -1
- data/lib/hitimes_ext.so +0 -0
- data/spec/interval_spec.rb +12 -0
- data/spec/timed_metric_spec.rb +3 -3
- data/tasks/config.rb +1 -1
- metadata +2 -3
data/HISTORY
CHANGED
data/examples/benchmarks.rb
CHANGED
@@ -44,16 +44,39 @@ end
|
|
44
44
|
# Use a new timer each time
|
45
45
|
#
|
46
46
|
def hitimes_duration_t1
|
47
|
-
Hitimes::
|
47
|
+
Hitimes::TimedMetric.now('duration_t1').stop
|
48
48
|
end
|
49
49
|
|
50
50
|
#
|
51
51
|
# reuse the same timer over and over
|
52
52
|
#
|
53
|
-
|
53
|
+
HT2= Hitimes::TimedMetric.new( 'duration_t2' )
|
54
54
|
def hitimes_duration_t2
|
55
|
-
|
56
|
-
|
55
|
+
HT2.start
|
56
|
+
HT2.stop
|
57
|
+
end
|
58
|
+
|
59
|
+
HT3 = Hitimes::TimedMetric.new( 'duration_t3' )
|
60
|
+
def hitimes_duration_t3
|
61
|
+
HT3.measure { nil }
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Check out the speed of the TimedValueMetric too
|
66
|
+
#
|
67
|
+
def hitimes_duration_tv1
|
68
|
+
Hitimes::TimedValueMetric.now( 'duration_tv1' ).stop( 42 )
|
69
|
+
end
|
70
|
+
|
71
|
+
HTV2 = Hitimes::TimedValueMetric.new( 'duration_tv2' )
|
72
|
+
def hitimes_duration_tv2
|
73
|
+
HTV2.start
|
74
|
+
HTV2.stop( 42 )
|
75
|
+
end
|
76
|
+
|
77
|
+
HTV3 = Hitimes::TimedValueMetric.new( 'duration_tv3' )
|
78
|
+
def hitimes_duration_tv3
|
79
|
+
HTV3.measure( 42 ) { nil }
|
57
80
|
end
|
58
81
|
|
59
82
|
#
|
@@ -76,11 +99,15 @@ end
|
|
76
99
|
|
77
100
|
puts "Testing time sampling 100,000 times"
|
78
101
|
|
79
|
-
bm(
|
80
|
-
x.report("Process")
|
81
|
-
x.report("Time")
|
82
|
-
x.report("Hitimes::
|
83
|
-
x.report("Hitimes::
|
84
|
-
x.report("Hitimes::
|
85
|
-
x.report("Hitimes::Interval
|
102
|
+
bm(30) do |x|
|
103
|
+
x.report("Process") { 100_000.times { process_duration } }
|
104
|
+
x.report("Time") { 100_000.times { time_duration } }
|
105
|
+
x.report("Hitimes::TimedMetric 1") { 100_000.times { hitimes_duration_t1 } }
|
106
|
+
x.report("Hitimes::TimedMetric 2") { 100_000.times { hitimes_duration_t2 } }
|
107
|
+
x.report("Hitimes::TimedMetric 3") { 100_000.times { hitimes_duration_t3 } }
|
108
|
+
x.report("Hitimes::Interval 1") { 100_000.times { hitimes_duration_i1 } }
|
109
|
+
x.report("Hitimes::Interval 2") { 100_000.times { hitimes_duration_i2 } }
|
110
|
+
x.report("Hitimes::TimedValueMetric 1") { 100_000.times { hitimes_duration_tv1 } }
|
111
|
+
x.report("Hitimes::TimedValueMetric 2") { 100_000.times { hitimes_duration_tv2 } }
|
112
|
+
x.report("Hitimes::TimedValueMetric 3") { 100_000.times { hitimes_duration_tv3 } }
|
86
113
|
end
|
data/examples/stats.rb
CHANGED
data/ext/hitimes_interval.c
CHANGED
@@ -164,6 +164,34 @@ VALUE hitimes_interval_stop( VALUE self )
|
|
164
164
|
return rc;
|
165
165
|
}
|
166
166
|
|
167
|
+
/**
|
168
|
+
* call-seq:
|
169
|
+
* interval.duration_so_far -> Float or false
|
170
|
+
*
|
171
|
+
* return how the duration so far. This will return the duration from the time
|
172
|
+
* the Interval was started if the interval is running, otherwise it will return
|
173
|
+
* false.
|
174
|
+
*/
|
175
|
+
VALUE hitimes_interval_duration_so_far( VALUE self )
|
176
|
+
{
|
177
|
+
hitimes_interval_t *i;
|
178
|
+
VALUE rc = Qfalse;
|
179
|
+
double d;
|
180
|
+
|
181
|
+
Data_Get_Struct( self, hitimes_interval_t, i );
|
182
|
+
if ( 0L == i->start_instant ) {
|
183
|
+
return rc;
|
184
|
+
}
|
185
|
+
|
186
|
+
if ( 0L == i->stop_instant ) {
|
187
|
+
hitimes_instant_t now = hitimes_get_current_instant( );
|
188
|
+
d = ( now - i->start_instant ) / HITIMES_INSTANT_CONVERSION_FACTOR;
|
189
|
+
rc = rb_float_new( d );
|
190
|
+
}
|
191
|
+
return rc;
|
192
|
+
}
|
193
|
+
|
194
|
+
|
167
195
|
/**
|
168
196
|
* call-seq:
|
169
197
|
* interval.started? -> boolean
|
@@ -328,6 +356,8 @@ void Init_hitimes_interval()
|
|
328
356
|
rb_define_method( cH_Interval, "length", hitimes_interval_duration, 0 );
|
329
357
|
rb_define_method( cH_Interval, "to_f", hitimes_interval_duration, 0 );
|
330
358
|
rb_define_method( cH_Interval, "to_seconds", hitimes_interval_duration, 0 );
|
359
|
+
|
360
|
+
rb_define_method( cH_Interval, "duration_so_far", hitimes_interval_duration_so_far, 0); /* in hitimes_interval.c */
|
331
361
|
|
332
362
|
rb_define_method( cH_Interval, "started?", hitimes_interval_started, 0 ); /* in hitimes_interval.c */
|
333
363
|
rb_define_method( cH_Interval, "running?", hitimes_interval_running, 0 ); /* in hitimes_interval.c */
|
data/lib/hitimes.rb
CHANGED
data/lib/hitimes/metric.rb
CHANGED
@@ -16,13 +16,8 @@ module Hitimes
|
|
16
16
|
#
|
17
17
|
class Metric
|
18
18
|
|
19
|
-
# the
|
20
|
-
|
21
|
-
attr_accessor :sampling_start_time
|
22
|
-
|
23
|
-
# the time at which the last sample was taken.
|
24
|
-
# This is the number of microseconds since UNIX epoch UTC as a Float
|
25
|
-
attr_accessor :sampling_stop_time
|
19
|
+
# the number of seconds as a float since the sampling_start_time
|
20
|
+
attr_reader :sampling_delta
|
26
21
|
|
27
22
|
# An additional hash of data to associate with the metric
|
28
23
|
attr_reader :additional_data
|
@@ -41,12 +36,55 @@ module Hitimes
|
|
41
36
|
# +name+ may be anything that follows the +to_s+ protocol.
|
42
37
|
#
|
43
38
|
def initialize( name, additional_data = {} )
|
44
|
-
@sampling_start_time
|
45
|
-
@
|
39
|
+
@sampling_start_time = nil
|
40
|
+
@sampling_start_interval = nil
|
41
|
+
@sampling_delta = 0
|
42
|
+
|
46
43
|
@name = name.to_s
|
47
44
|
@additional_data = additional_data.to_hash
|
48
45
|
end
|
49
46
|
|
47
|
+
#
|
48
|
+
# :call-seq:
|
49
|
+
# metric.sampling_start_time -> Float or nil
|
50
|
+
#
|
51
|
+
# The time at which the first sample was taken.
|
52
|
+
# This is the number of microseconds since UNIX epoch UTC as a Float
|
53
|
+
#
|
54
|
+
# If the metric has not started measuring then the start time is nil.
|
55
|
+
#
|
56
|
+
def sampling_start_time
|
57
|
+
if @sampling_start_interval then
|
58
|
+
@sampling_start_time ||= self.utc_microseconds()
|
59
|
+
else
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# :call-seq:
|
66
|
+
# metric.sampling_stop_time -> Float or nil
|
67
|
+
#
|
68
|
+
# The time at which the last sample was taken
|
69
|
+
# This is the number of microseconds since UNIX epoch UTC as a Float
|
70
|
+
#
|
71
|
+
# If the metric has not completely measured at least one thing then
|
72
|
+
# stop time is nil.
|
73
|
+
#
|
74
|
+
# Because accessing the actual 'time of day' is an expesive operation, we
|
75
|
+
# only get the time of day at the beginning of the first measurement and we
|
76
|
+
# keep track of the offset from that point in @sampling_delta.
|
77
|
+
#
|
78
|
+
# When sampling_stop_time is called, the actual time of day is caculated.
|
79
|
+
#
|
80
|
+
def sampling_stop_time
|
81
|
+
if @sampling_delta > 0 then
|
82
|
+
(self.sampling_start_time + (@sampling_delta * 1_000_000))
|
83
|
+
else
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
50
88
|
#
|
51
89
|
# :call-seq:
|
52
90
|
# metric.to_hash -> Hash
|
@@ -55,10 +93,10 @@ module Hitimes
|
|
55
93
|
# Convert the metric to a Hash.
|
56
94
|
#
|
57
95
|
def to_hash
|
58
|
-
{ 'sampling_start_time' =>
|
59
|
-
'sampling_stop_time' =>
|
60
|
-
'additional_data' =>
|
61
|
-
'name' =>
|
96
|
+
{ 'sampling_start_time' => self.sampling_start_time,
|
97
|
+
'sampling_stop_time' => self.sampling_stop_time,
|
98
|
+
'additional_data' => self.additional_data,
|
99
|
+
'name' => self.name }
|
62
100
|
end
|
63
101
|
|
64
102
|
#
|
data/lib/hitimes/stats.rb
CHANGED
data/lib/hitimes/timed_metric.rb
CHANGED
@@ -60,17 +60,7 @@ module Hitimes
|
|
60
60
|
def initialize( name, additional_data = {} )
|
61
61
|
super( name, additional_data )
|
62
62
|
@stats = Stats.new
|
63
|
-
@current_interval =
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# :call-seq:
|
68
|
-
# timed_metric.current_interval -> Interval
|
69
|
-
#
|
70
|
-
# Return the current interval, if one doesn't exist create one.
|
71
|
-
#
|
72
|
-
def current_interval
|
73
|
-
@current_interval ||= Interval.new
|
63
|
+
@current_interval = Interval.new
|
74
64
|
end
|
75
65
|
|
76
66
|
#
|
@@ -80,7 +70,7 @@ module Hitimes
|
|
80
70
|
# return whether or not the timer is currently running.
|
81
71
|
#
|
82
72
|
def running?
|
83
|
-
current_interval.running?
|
73
|
+
@current_interval.running?
|
84
74
|
end
|
85
75
|
|
86
76
|
#
|
@@ -91,8 +81,11 @@ module Hitimes
|
|
91
81
|
# this is a noop.
|
92
82
|
#
|
93
83
|
def start
|
94
|
-
current_interval.
|
95
|
-
|
84
|
+
if not @current_interval.running? then
|
85
|
+
@current_interval.start
|
86
|
+
@sampling_start_time ||= self.utc_microseconds()
|
87
|
+
@sampling_start_interval ||= Interval.now
|
88
|
+
end
|
96
89
|
nil
|
97
90
|
end
|
98
91
|
|
@@ -106,11 +99,14 @@ module Hitimes
|
|
106
99
|
# no stats are updated.
|
107
100
|
#
|
108
101
|
def stop
|
109
|
-
if running? then
|
110
|
-
d = current_interval.stop
|
111
|
-
@current_interval = nil
|
112
|
-
@sampling_stop_time = self.utc_microseconds()
|
102
|
+
if @current_interval.running? then
|
103
|
+
d = @current_interval.stop
|
113
104
|
@stats.update( d )
|
105
|
+
@current_interval = Interval.new
|
106
|
+
|
107
|
+
# update the length of time we have been sampling
|
108
|
+
@sampling_delta = @sampling_start_interval.duration_so_far
|
109
|
+
|
114
110
|
return d
|
115
111
|
end
|
116
112
|
return false
|
@@ -148,9 +144,9 @@ module Hitimes
|
|
148
144
|
# happens and false is returned.
|
149
145
|
#
|
150
146
|
def split
|
151
|
-
if running? then
|
152
|
-
next_interval = current_interval.split
|
153
|
-
d = current_interval.duration
|
147
|
+
if @current_interval.running? then
|
148
|
+
next_interval = @current_interval.split
|
149
|
+
d = @current_interval.duration
|
154
150
|
@stats.update( d )
|
155
151
|
@current_interval = next_interval
|
156
152
|
return d
|
@@ -59,22 +59,11 @@ module Hitimes
|
|
59
59
|
#
|
60
60
|
def initialize( name, additional_data = {} )
|
61
61
|
super( name, additional_data )
|
62
|
-
@current_interval = nil
|
63
62
|
@timed_stats = Stats.new
|
64
63
|
@value_stats = Stats.new
|
64
|
+
@current_interval = Interval.new
|
65
65
|
end
|
66
66
|
|
67
|
-
#
|
68
|
-
# :call-seq:
|
69
|
-
# timed_value_metric.current_interval -> Interval
|
70
|
-
#
|
71
|
-
# Return the current interval, if one doesn't exist create one.
|
72
|
-
#
|
73
|
-
def current_interval
|
74
|
-
@current_interval ||= Interval.new
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
67
|
#
|
79
68
|
# :call-seq:
|
80
69
|
# timed_value_metric.running? -> true or false
|
@@ -82,7 +71,7 @@ module Hitimes
|
|
82
71
|
# return whether or not the metric is currently timing something.
|
83
72
|
#
|
84
73
|
def running?
|
85
|
-
current_interval.running?
|
74
|
+
@current_interval.running?
|
86
75
|
end
|
87
76
|
|
88
77
|
#
|
@@ -93,8 +82,11 @@ module Hitimes
|
|
93
82
|
# this is a noop.
|
94
83
|
#
|
95
84
|
def start
|
96
|
-
current_interval.
|
97
|
-
|
85
|
+
if not @current_interval.running? then
|
86
|
+
@current_interval.start
|
87
|
+
@sampling_start_time ||= self.utc_microseconds()
|
88
|
+
@sampling_start_interval ||= Interval.now
|
89
|
+
end
|
98
90
|
nil
|
99
91
|
end
|
100
92
|
|
@@ -114,12 +106,15 @@ module Hitimes
|
|
114
106
|
#
|
115
107
|
#
|
116
108
|
def stop( value )
|
117
|
-
if running? then
|
118
|
-
d = current_interval.stop
|
119
|
-
@current_interval = nil
|
120
|
-
@sampling_stop_time = self.utc_microseconds()
|
109
|
+
if @current_interval.running? then
|
110
|
+
d = @current_interval.stop
|
121
111
|
@timed_stats.update( d )
|
112
|
+
@current_interval = Interval.new
|
122
113
|
@value_stats.update( value )
|
114
|
+
|
115
|
+
# update the lenght of time we have been sampling
|
116
|
+
@sampling_delta = @sampling_start_interval.duration_so_far
|
117
|
+
|
123
118
|
return d
|
124
119
|
end
|
125
120
|
return false
|
@@ -159,9 +154,9 @@ module Hitimes
|
|
159
154
|
#
|
160
155
|
#
|
161
156
|
def split( value )
|
162
|
-
if running? then
|
163
|
-
next_interval = current_interval.split
|
164
|
-
d = current_interval.duration
|
157
|
+
if @current_interval.running? then
|
158
|
+
next_interval = @current_interval.split
|
159
|
+
d = @current_interval.duration
|
165
160
|
@timed_stats.update( d )
|
166
161
|
@value_stats.update( value )
|
167
162
|
@current_interval = next_interval
|
data/lib/hitimes/value_metric.rb
CHANGED
@@ -42,10 +42,13 @@ module Hitimes
|
|
42
42
|
# Give the +value+ as the measurement to the metric. The value is returned
|
43
43
|
#
|
44
44
|
def measure( value )
|
45
|
-
|
46
|
-
@
|
47
|
-
|
45
|
+
@sampling_start_time ||= self.utc_microseconds()
|
46
|
+
@sampling_start_interval ||= Interval.now
|
47
|
+
|
48
48
|
@stats.update( value )
|
49
|
+
|
50
|
+
# update the length of time we have been sampling
|
51
|
+
@sampling_delta = @sampling_start_interval.duration_so_far
|
49
52
|
end
|
50
53
|
|
51
54
|
#
|
data/lib/hitimes/version.rb
CHANGED
data/lib/hitimes_ext.so
CHANGED
Binary file
|
data/spec/interval_spec.rb
CHANGED
@@ -94,6 +94,18 @@ describe Hitimes::Interval do
|
|
94
94
|
x.object_id.should == y.object_id
|
95
95
|
end
|
96
96
|
|
97
|
+
it "can return how much time has elapsed from the start without stopping the interval" do
|
98
|
+
i = Hitimes::Interval.new
|
99
|
+
i.start
|
100
|
+
x = i.duration_so_far
|
101
|
+
i.should be_running
|
102
|
+
y = i.duration_so_far
|
103
|
+
i.stop
|
104
|
+
x.should < y
|
105
|
+
x.should < i.duration
|
106
|
+
y.should < i.duration
|
107
|
+
end
|
108
|
+
|
97
109
|
describe "#split" do
|
98
110
|
|
99
111
|
it "creates a new Interval object" do
|
data/spec/timed_metric_spec.rb
CHANGED
@@ -95,9 +95,9 @@ describe Hitimes::TimedMetric do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
it "keeps track of the last stop time of all the intervals" do
|
98
|
-
f1 = Time.now.gmtime.to_f *
|
98
|
+
f1 = Time.now.gmtime.to_f * 1_000_000
|
99
99
|
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
|
100
|
-
f2 = Time.now.gmtime.to_f *
|
100
|
+
f2 = Time.now.gmtime.to_f * 1_000_000
|
101
101
|
@tm.sampling_stop_time.should > f1
|
102
102
|
@tm.sampling_stop_time.should < f2
|
103
103
|
# distance from now to max stop time time should be less than the distance
|
@@ -131,7 +131,7 @@ describe Hitimes::TimedMetric do
|
|
131
131
|
h['name'].should == "test-timed-metric"
|
132
132
|
end
|
133
133
|
|
134
|
-
it "has an empty
|
134
|
+
it "has an empty hash for additional_data" do
|
135
135
|
h = @tm.to_hash
|
136
136
|
h['additional_data'].should == Hash.new
|
137
137
|
h['additional_data'].size.should == 0
|
data/tasks/config.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hitimes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: x86-mswin32-60
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-13 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -119,7 +119,6 @@ homepage: http://copiousfreetime.rubyforge.org/hitimes/
|
|
119
119
|
post_install_message:
|
120
120
|
rdoc_options:
|
121
121
|
- --line-numbers
|
122
|
-
- --inline-source
|
123
122
|
- --main
|
124
123
|
- README
|
125
124
|
require_paths:
|