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/version_spec.rb
CHANGED
data/tasks/this.rb
CHANGED
@@ -25,10 +25,10 @@ class ThisProject
|
|
25
25
|
#
|
26
26
|
# Yields self
|
27
27
|
def initialize(&block)
|
28
|
-
@exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/,
|
28
|
+
@exclude_from_manifest = Regexp.union(/\.(git|DS_Store|fossa.yml)/,
|
29
29
|
/^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/,
|
30
30
|
/^[^\/]+\.gemspec/,
|
31
|
-
/\.(swp|jar|bundle|so|rvmrc|travis.yml|byebug_history)$/,
|
31
|
+
/\.(swp|jar|bundle|so|rvmrc|travis.yml|byebug_history|fossa.yml|ruby-version)$/,
|
32
32
|
/~$/)
|
33
33
|
@gemspecs = Hash.new
|
34
34
|
yield self if block_given?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hitimes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '12.
|
19
|
+
version: '12.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '12.
|
26
|
+
version: '12.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,77 +44,48 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '6.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '6.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
61
|
+
version: '2.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake-compiler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rake-compiler-dock
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.6'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.6'
|
68
|
+
version: '2.2'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
70
|
name: simplecov
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
73
|
- - "~>"
|
102
74
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
75
|
+
version: '0.17'
|
104
76
|
type: :development
|
105
77
|
prerelease: false
|
106
78
|
version_requirements: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
108
80
|
- - "~>"
|
109
81
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
82
|
+
version: '0.17'
|
111
83
|
description: A fast, high resolution timer library for recording peformance metrics.
|
112
|
-
* (http://github.com/copiousfreetime/hitimes) * (http://github.com
|
84
|
+
* (http://github.com/copiousfreetime/hitimes) * (http://github.com/copiousfreetime/hitimes)
|
113
85
|
* email jeremy at copiousfreetime dot org * `git clone url git://github.com/copiousfreetime/hitimes.git`
|
114
86
|
email: jeremy@copiousfreetime.org
|
115
87
|
executables: []
|
116
|
-
extensions:
|
117
|
-
- ext/hitimes/c/extconf.rb
|
88
|
+
extensions: []
|
118
89
|
extra_rdoc_files:
|
119
90
|
- CONTRIBUTING.md
|
120
91
|
- HISTORY.md
|
@@ -129,20 +100,10 @@ files:
|
|
129
100
|
- Rakefile
|
130
101
|
- examples/benchmarks.rb
|
131
102
|
- examples/stats.rb
|
132
|
-
- ext/hitimes/c/extconf.rb
|
133
|
-
- ext/hitimes/c/hitimes.c
|
134
|
-
- ext/hitimes/c/hitimes_instant_clock_gettime.c
|
135
|
-
- ext/hitimes/c/hitimes_instant_osx.c
|
136
|
-
- ext/hitimes/c/hitimes_instant_windows.c
|
137
|
-
- ext/hitimes/c/hitimes_interval.c
|
138
|
-
- ext/hitimes/c/hitimes_interval.h
|
139
|
-
- ext/hitimes/c/hitimes_stats.c
|
140
|
-
- ext/hitimes/c/hitimes_stats.h
|
141
|
-
- ext/hitimes/java/src/hitimes/Hitimes.java
|
142
|
-
- ext/hitimes/java/src/hitimes/HitimesInterval.java
|
143
|
-
- ext/hitimes/java/src/hitimes/HitimesService.java
|
144
|
-
- ext/hitimes/java/src/hitimes/HitimesStats.java
|
145
103
|
- lib/hitimes.rb
|
104
|
+
- lib/hitimes/initialize.rb
|
105
|
+
- lib/hitimes/instant.rb
|
106
|
+
- lib/hitimes/interval.rb
|
146
107
|
- lib/hitimes/metric.rb
|
147
108
|
- lib/hitimes/mutexed_stats.rb
|
148
109
|
- lib/hitimes/paths.rb
|
@@ -163,7 +124,6 @@ files:
|
|
163
124
|
- spec/value_metric_spec.rb
|
164
125
|
- spec/version_spec.rb
|
165
126
|
- tasks/default.rake
|
166
|
-
- tasks/extension.rake
|
167
127
|
- tasks/this.rb
|
168
128
|
homepage: http://github.com/copiousfreetime/hitimes
|
169
129
|
licenses:
|
@@ -188,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
148
|
- !ruby/object:Gem::Version
|
189
149
|
version: '0'
|
190
150
|
requirements: []
|
191
|
-
rubygems_version: 3.0.
|
151
|
+
rubygems_version: 3.0.3
|
192
152
|
signing_key:
|
193
153
|
specification_version: 4
|
194
154
|
summary: A fast, high resolution timer library for recording peformance metrics.
|
data/ext/hitimes/c/extconf.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'mkmf'
|
3
|
-
|
4
|
-
if RbConfig::CONFIG['host_os'] =~ /darwin/ then
|
5
|
-
$CFLAGS += " -DUSE_INSTANT_OSX=1 -Wall"
|
6
|
-
$LDFLAGS += " -framework CoreServices"
|
7
|
-
elsif RbConfig::CONFIG['host_os'] =~ /win(32|64)/ or RbConfig::CONFIG['host_os'] =~ /mingw/ then
|
8
|
-
$CFLAGS += " -DUSE_INSTANT_WINDOWS=1"
|
9
|
-
else
|
10
|
-
if have_library("rt", "clock_gettime") then
|
11
|
-
$CFLAGS += " -DUSE_INSTANT_CLOCK_GETTIME=1"
|
12
|
-
elsif have_library("c", "clock_gettime") then
|
13
|
-
$CFLAGS += " -DUSE_INSTANT_CLOCK_GETTIME=1"
|
14
|
-
else
|
15
|
-
raise NotImplementedError, <<-_
|
16
|
-
Unable to find the function 'clock_gettime' in either libc or librt.
|
17
|
-
Please file an issue at https://github.com/copiousfreetime/hitimes.
|
18
|
-
_
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# put in a different location if on windows so we can have fat binaries
|
23
|
-
subdir = RUBY_VERSION.gsub(/\.\d+$/,'')
|
24
|
-
create_makefile("hitimes/#{subdir}/hitimes")
|
data/ext/hitimes/c/hitimes.c
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
#include <ruby.h>
|
2
|
-
#include "hitimes_interval.h"
|
3
|
-
|
4
|
-
/* Module and Classes */
|
5
|
-
VALUE mH; /* module Hitimes */
|
6
|
-
VALUE eH_Error; /* class Hitimes::Error */
|
7
|
-
|
8
|
-
|
9
|
-
/**
|
10
|
-
* call-seq:
|
11
|
-
* Hitimes.raw_instant -> Integer
|
12
|
-
*
|
13
|
-
* Return the raw instant value from the operating system
|
14
|
-
*/
|
15
|
-
VALUE hitimes_instant_raw( )
|
16
|
-
{
|
17
|
-
unsigned long long i = (unsigned long long)hitimes_get_current_instant( );
|
18
|
-
|
19
|
-
return ULL2NUM(i);
|
20
|
-
}
|
21
|
-
|
22
|
-
/*
|
23
|
-
* Document-class: Hitimes::Error
|
24
|
-
*
|
25
|
-
* General error class for the Hitimes module
|
26
|
-
*/
|
27
|
-
void Init_hitimes( )
|
28
|
-
{
|
29
|
-
mH = rb_define_module("Hitimes");
|
30
|
-
|
31
|
-
eH_Error = rb_define_class_under(mH, "Error", rb_eStandardError);
|
32
|
-
rb_define_const( mH, "INSTANT_CONVERSION_FACTOR", DBL2NUM( HITIMES_INSTANT_CONVERSION_FACTOR ));
|
33
|
-
rb_define_module_function( mH, "raw_instant", hitimes_instant_raw, 0 );
|
34
|
-
|
35
|
-
Init_hitimes_interval();
|
36
|
-
Init_hitimes_stats( );
|
37
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#ifdef USE_INSTANT_CLOCK_GETTIME
|
2
|
-
|
3
|
-
#include "hitimes_interval.h"
|
4
|
-
|
5
|
-
#include <time.h>
|
6
|
-
#ifndef CLOCK_MONOTONIC
|
7
|
-
# include <sys/time.h>
|
8
|
-
# ifndef CLOCK_MONOTONIC
|
9
|
-
# ifdef __linux__
|
10
|
-
# include <linux/time.h>
|
11
|
-
# endif
|
12
|
-
# endif
|
13
|
-
#endif
|
14
|
-
|
15
|
-
hitimes_instant_t hitimes_get_current_instant( )
|
16
|
-
{
|
17
|
-
struct timespec time;
|
18
|
-
int rc;
|
19
|
-
|
20
|
-
rc = clock_gettime( CLOCK_MONOTONIC, &time);
|
21
|
-
if ( 0 != rc ) {
|
22
|
-
char* e = strerror( rc );
|
23
|
-
rb_raise(eH_Error, "Unable to retrieve time for CLOCK_MONOTONIC : %s", e );
|
24
|
-
}
|
25
|
-
|
26
|
-
return ( ( NANOSECONDS_PER_SECOND * (long)time.tv_sec ) + time.tv_nsec );
|
27
|
-
}
|
28
|
-
#endif
|
@@ -1,48 +0,0 @@
|
|
1
|
-
#ifdef USE_INSTANT_OSX
|
2
|
-
|
3
|
-
#include "hitimes_interval.h"
|
4
|
-
#include <mach/mach.h>
|
5
|
-
#include <mach/mach_time.h>
|
6
|
-
|
7
|
-
/* All this OSX code is adapted from
|
8
|
-
* https://developer.apple.com/library/archive/qa/qa1398/_index.html
|
9
|
-
*/
|
10
|
-
|
11
|
-
|
12
|
-
/*
|
13
|
-
* returns the conversion factor, this value is used to convert
|
14
|
-
* the value from hitimes_get_current_instant() into seconds
|
15
|
-
*/
|
16
|
-
long double hitimes_instant_conversion_factor()
|
17
|
-
{
|
18
|
-
static mach_timebase_info_data_t s_timebase_info;
|
19
|
-
static long double conversion_factor;
|
20
|
-
static uint64_t nano_conversion;
|
21
|
-
|
22
|
-
/**
|
23
|
-
* If this is the first time we've run, get the timebase.
|
24
|
-
* We can use denom == 0 to indicate that s_timebase_info is
|
25
|
-
* uninitialised because it makes no sense to have a zero
|
26
|
-
* denominator is a fraction.
|
27
|
-
*/
|
28
|
-
|
29
|
-
if ( s_timebase_info.denom == 0 ) {
|
30
|
-
mach_timebase_info(&s_timebase_info);
|
31
|
-
nano_conversion = s_timebase_info.numer / s_timebase_info.denom;
|
32
|
-
conversion_factor = (long double) (nano_conversion) * (1e9l);
|
33
|
-
}
|
34
|
-
|
35
|
-
return conversion_factor;
|
36
|
-
}
|
37
|
-
|
38
|
-
/*
|
39
|
-
* returns the mach absolute time, which has no meaning outside of a conversion
|
40
|
-
* factor.
|
41
|
-
*/
|
42
|
-
hitimes_instant_t hitimes_get_current_instant()
|
43
|
-
{
|
44
|
-
return mach_absolute_time();
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
#endif
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#ifdef USE_INSTANT_WINDOWS
|
2
|
-
|
3
|
-
#include "hitimes_interval.h"
|
4
|
-
|
5
|
-
|
6
|
-
/*
|
7
|
-
* returns the conversion factor, this value is used to convert
|
8
|
-
* the value from hitimes_get_current_instant() into seconds
|
9
|
-
*/
|
10
|
-
long double hitimes_instant_conversion_factor()
|
11
|
-
{
|
12
|
-
LARGE_INTEGER ticks_per_second;
|
13
|
-
QueryPerformanceFrequency( &ticks_per_second );
|
14
|
-
return (double)ticks_per_second.QuadPart;
|
15
|
-
}
|
16
|
-
|
17
|
-
/*
|
18
|
-
* returns the number of ticks
|
19
|
-
*/
|
20
|
-
hitimes_instant_t hitimes_get_current_instant()
|
21
|
-
{
|
22
|
-
LARGE_INTEGER tick;
|
23
|
-
QueryPerformanceCounter(&tick);
|
24
|
-
return (hitimes_instant_t)tick.QuadPart;
|
25
|
-
}
|
26
|
-
|
27
|
-
#endif
|
@@ -1,370 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) 2008 Jeremy Hinegardner
|
3
|
-
* All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
-
*
|
5
|
-
* vim: shiftwidth=4
|
6
|
-
*/
|
7
|
-
|
8
|
-
#include "hitimes_interval.h"
|
9
|
-
|
10
|
-
/* Modules and Classes -- defined here */
|
11
|
-
VALUE cH_Interval; /* class Hitimes::Interval */
|
12
|
-
|
13
|
-
/**
|
14
|
-
* Allocator and Deallocator for Interval classes
|
15
|
-
*/
|
16
|
-
|
17
|
-
VALUE hitimes_interval_free(hitimes_interval_t* i)
|
18
|
-
{
|
19
|
-
xfree( i );
|
20
|
-
return Qnil;
|
21
|
-
}
|
22
|
-
|
23
|
-
VALUE hitimes_interval_alloc(VALUE klass)
|
24
|
-
{
|
25
|
-
VALUE obj;
|
26
|
-
hitimes_interval_t* i = xmalloc( sizeof( hitimes_interval_t ) );
|
27
|
-
|
28
|
-
i->start_instant = 0L;
|
29
|
-
i->stop_instant = 0L;
|
30
|
-
i->duration = -1.0l;
|
31
|
-
|
32
|
-
obj = Data_Wrap_Struct(klass, NULL, hitimes_interval_free, i);
|
33
|
-
return obj;
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
* call-seq:
|
38
|
-
* Interval.now -> Interval
|
39
|
-
*
|
40
|
-
* Create an interval that has already started
|
41
|
-
*/
|
42
|
-
VALUE hitimes_interval_now( )
|
43
|
-
{
|
44
|
-
VALUE obj;
|
45
|
-
hitimes_interval_t *i = xmalloc( sizeof( hitimes_interval_t ) );
|
46
|
-
|
47
|
-
i->start_instant = hitimes_get_current_instant( );
|
48
|
-
i->stop_instant = 0L;
|
49
|
-
i->duration = -1.0l;
|
50
|
-
|
51
|
-
obj = Data_Wrap_Struct(cH_Interval, NULL, hitimes_interval_free, i);
|
52
|
-
|
53
|
-
return obj;
|
54
|
-
}
|
55
|
-
|
56
|
-
/**
|
57
|
-
* call-seq:
|
58
|
-
* Interval.measure { } -> Float
|
59
|
-
*
|
60
|
-
* Times the execution of the block returning the number of seconds it took
|
61
|
-
*/
|
62
|
-
VALUE hitimes_interval_measure( )
|
63
|
-
{
|
64
|
-
hitimes_instant_t before;
|
65
|
-
hitimes_instant_t after;
|
66
|
-
long double duration;
|
67
|
-
|
68
|
-
if ( !rb_block_given_p() ) {
|
69
|
-
rb_raise(eH_Error, "No block given to Interval.measure" );
|
70
|
-
}
|
71
|
-
|
72
|
-
before = hitimes_get_current_instant( );
|
73
|
-
rb_yield( Qnil );
|
74
|
-
after = hitimes_get_current_instant( );
|
75
|
-
|
76
|
-
duration = ( after - before ) / HITIMES_INSTANT_CONVERSION_FACTOR;
|
77
|
-
return rb_float_new( duration );
|
78
|
-
}
|
79
|
-
|
80
|
-
/**
|
81
|
-
* call-seq:
|
82
|
-
* interval.split -> Interval
|
83
|
-
*
|
84
|
-
* Immediately stop the current interval and start a new interval that has a
|
85
|
-
* start_instant equivalent to the stop_interval of self.
|
86
|
-
*/
|
87
|
-
VALUE hitimes_interval_split( VALUE self )
|
88
|
-
{
|
89
|
-
hitimes_interval_t *first;
|
90
|
-
hitimes_interval_t *second = xmalloc( sizeof( hitimes_interval_t ) );
|
91
|
-
VALUE obj;
|
92
|
-
|
93
|
-
Data_Get_Struct( self, hitimes_interval_t, first );
|
94
|
-
first->stop_instant = hitimes_get_current_instant( );
|
95
|
-
|
96
|
-
second->start_instant = first->stop_instant;
|
97
|
-
second->stop_instant = 0L;
|
98
|
-
second->duration = -1.0l;
|
99
|
-
|
100
|
-
obj = Data_Wrap_Struct(cH_Interval, NULL, hitimes_interval_free, second);
|
101
|
-
|
102
|
-
return obj;
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
/**
|
107
|
-
* call-seq:
|
108
|
-
* interval.start -> boolean
|
109
|
-
*
|
110
|
-
* mark the start of the interval. Calling start on an already started
|
111
|
-
* interval has no effect. An interval can only be started once. If the
|
112
|
-
* interval is truely started +true+ is returned otherwise +false+.
|
113
|
-
*/
|
114
|
-
VALUE hitimes_interval_start( VALUE self )
|
115
|
-
{
|
116
|
-
hitimes_interval_t *i;
|
117
|
-
VALUE rc = Qfalse;
|
118
|
-
|
119
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
120
|
-
if ( 0L == i->start_instant ) {
|
121
|
-
i->start_instant = hitimes_get_current_instant( );
|
122
|
-
i->stop_instant = 0L;
|
123
|
-
i->duration = -1.0l;
|
124
|
-
|
125
|
-
rc = Qtrue;
|
126
|
-
}
|
127
|
-
|
128
|
-
return rc;
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
/**
|
133
|
-
* call-seq:
|
134
|
-
* interval.stop -> bool or Float
|
135
|
-
*
|
136
|
-
* mark the stop of the interval. Calling stop on an already stopped interval
|
137
|
-
* has no effect. An interval can only be stopped once. If the interval is
|
138
|
-
* truely stopped then the duration is returned, otherwise +false+.
|
139
|
-
*/
|
140
|
-
VALUE hitimes_interval_stop( VALUE self )
|
141
|
-
{
|
142
|
-
hitimes_interval_t *i;
|
143
|
-
VALUE rc = Qfalse;
|
144
|
-
|
145
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
146
|
-
if ( 0L == i->start_instant ) {
|
147
|
-
rb_raise(eH_Error, "Attempt to stop an interval that has not started" );
|
148
|
-
}
|
149
|
-
|
150
|
-
if ( 0L == i->stop_instant ) {
|
151
|
-
i->stop_instant = hitimes_get_current_instant( );
|
152
|
-
i->duration = ( i->stop_instant - i->start_instant ) / HITIMES_INSTANT_CONVERSION_FACTOR;
|
153
|
-
rc = rb_float_new( i->duration );
|
154
|
-
}
|
155
|
-
|
156
|
-
return rc;
|
157
|
-
}
|
158
|
-
|
159
|
-
/**
|
160
|
-
* call-seq:
|
161
|
-
* interval.duration_so_far -> Float or false
|
162
|
-
*
|
163
|
-
* return how the duration so far. This will return the duration from the time
|
164
|
-
* the Interval was started if the interval is running, otherwise it will return
|
165
|
-
* false.
|
166
|
-
*/
|
167
|
-
VALUE hitimes_interval_duration_so_far( VALUE self )
|
168
|
-
{
|
169
|
-
hitimes_interval_t *i;
|
170
|
-
VALUE rc = Qfalse;
|
171
|
-
|
172
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
173
|
-
if ( 0L == i->start_instant ) {
|
174
|
-
return rc;
|
175
|
-
}
|
176
|
-
|
177
|
-
if ( 0L == i->stop_instant ) {
|
178
|
-
long double d;
|
179
|
-
hitimes_instant_t now = hitimes_get_current_instant( );
|
180
|
-
d = ( now - i->start_instant ) / HITIMES_INSTANT_CONVERSION_FACTOR;
|
181
|
-
rc = rb_float_new( d );
|
182
|
-
}
|
183
|
-
return rc;
|
184
|
-
}
|
185
|
-
|
186
|
-
|
187
|
-
/**
|
188
|
-
* call-seq:
|
189
|
-
* interval.started? -> boolean
|
190
|
-
*
|
191
|
-
* returns whether or not the interval has been started
|
192
|
-
*/
|
193
|
-
VALUE hitimes_interval_started( VALUE self )
|
194
|
-
{
|
195
|
-
hitimes_interval_t *i;
|
196
|
-
|
197
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
198
|
-
|
199
|
-
return ( 0L == i->start_instant ) ? Qfalse : Qtrue;
|
200
|
-
}
|
201
|
-
|
202
|
-
|
203
|
-
/**
|
204
|
-
* call-seq:
|
205
|
-
* interval.stopped? -> boolean
|
206
|
-
*
|
207
|
-
* returns whether or not the interval has been stopped
|
208
|
-
*/
|
209
|
-
VALUE hitimes_interval_stopped( VALUE self )
|
210
|
-
{
|
211
|
-
hitimes_interval_t *i;
|
212
|
-
|
213
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
214
|
-
|
215
|
-
return ( 0L == i->stop_instant ) ? Qfalse : Qtrue;
|
216
|
-
}
|
217
|
-
|
218
|
-
/**
|
219
|
-
* call-seq:
|
220
|
-
* interval.running? -> boolean
|
221
|
-
*
|
222
|
-
* returns whether or not the interval is running or not. This means that it
|
223
|
-
* has started, but not stopped.
|
224
|
-
*/
|
225
|
-
VALUE hitimes_interval_running( VALUE self )
|
226
|
-
{
|
227
|
-
hitimes_interval_t *i;
|
228
|
-
VALUE rc = Qfalse;
|
229
|
-
|
230
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
231
|
-
if ( ( 0L != i->start_instant ) && ( 0L == i->stop_instant ) ) {
|
232
|
-
rc = Qtrue;
|
233
|
-
}
|
234
|
-
|
235
|
-
return rc;
|
236
|
-
}
|
237
|
-
|
238
|
-
|
239
|
-
/**
|
240
|
-
* call-seq:
|
241
|
-
* interval.start_instant -> Integer
|
242
|
-
*
|
243
|
-
* The integer representing the start instant of the Interval. This value
|
244
|
-
* is not useful on its own. It is a platform dependent value.
|
245
|
-
*/
|
246
|
-
VALUE hitimes_interval_start_instant( VALUE self )
|
247
|
-
{
|
248
|
-
hitimes_interval_t *i;
|
249
|
-
|
250
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
251
|
-
|
252
|
-
return ULL2NUM( i->start_instant );
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
/**
|
257
|
-
* call-seq:
|
258
|
-
* interval.stop_instant -> Integer
|
259
|
-
*
|
260
|
-
* The integer representing the stop instant of the Interval. This value
|
261
|
-
* is not useful on its own. It is a platform dependent value.
|
262
|
-
*/
|
263
|
-
VALUE hitimes_interval_stop_instant( VALUE self )
|
264
|
-
{
|
265
|
-
hitimes_interval_t *i;
|
266
|
-
|
267
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
268
|
-
|
269
|
-
return ULL2NUM( i->stop_instant );
|
270
|
-
}
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
/**
|
275
|
-
* call-seq:
|
276
|
-
* interval.duration -> Float
|
277
|
-
* interval.to_f -> Float
|
278
|
-
* interval.to_seconds -> Float
|
279
|
-
* interval.length -> Float
|
280
|
-
*
|
281
|
-
* Returns the Float value of the interval, the value is in seconds. If the
|
282
|
-
* interval has not had stop called yet, it will report the number of seconds
|
283
|
-
* in the interval up to the current point in time.
|
284
|
-
*
|
285
|
-
* Raises Error if duration is called on an interval that has not started yet.
|
286
|
-
*/
|
287
|
-
VALUE hitimes_interval_duration ( VALUE self )
|
288
|
-
{
|
289
|
-
hitimes_interval_t *i;
|
290
|
-
|
291
|
-
Data_Get_Struct( self, hitimes_interval_t, i );
|
292
|
-
|
293
|
-
/* raise an error if the internval is not started */
|
294
|
-
if ( 0L == i->start_instant ) {
|
295
|
-
rb_raise(eH_Error, "Attempt to report a duration on an interval that has not started" );
|
296
|
-
}
|
297
|
-
|
298
|
-
|
299
|
-
/**
|
300
|
-
* if stop has not yet been called, then return the amount of time so far
|
301
|
-
*/
|
302
|
-
if ( 0L == i->stop_instant ) {
|
303
|
-
long double d;
|
304
|
-
hitimes_instant_t now = hitimes_get_current_instant( );
|
305
|
-
d = ( now - i->start_instant ) / HITIMES_INSTANT_CONVERSION_FACTOR;
|
306
|
-
return rb_float_new( d );
|
307
|
-
}
|
308
|
-
|
309
|
-
/*
|
310
|
-
* stop has been called, calculate the duration and save the result
|
311
|
-
*/
|
312
|
-
if ( i->duration < 0.0 ) {
|
313
|
-
i->duration = ( i->stop_instant - i->start_instant ) / HITIMES_INSTANT_CONVERSION_FACTOR;
|
314
|
-
}
|
315
|
-
|
316
|
-
return rb_float_new( i->duration );
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
/**
|
321
|
-
* Document-class: Hitimes::Interval
|
322
|
-
*
|
323
|
-
* This is the lowest level timing mechanism available. It allows for easy
|
324
|
-
* measuring based upon a block:
|
325
|
-
*
|
326
|
-
* duration = Interval.measure { ... }
|
327
|
-
*
|
328
|
-
* Or measuring something specifically
|
329
|
-
*
|
330
|
-
* interval = Interval.new
|
331
|
-
* interval.start
|
332
|
-
* duration = interval.stop
|
333
|
-
*
|
334
|
-
* Allocating and starting an interval can be done in one method call with
|
335
|
-
*
|
336
|
-
* interval = Interval.now
|
337
|
-
*
|
338
|
-
* Interval is useful when you only need to track a single interval of time, or
|
339
|
-
* if you do not want to track statistics about an operation.
|
340
|
-
*
|
341
|
-
*/
|
342
|
-
void Init_hitimes_interval()
|
343
|
-
{
|
344
|
-
mH = rb_define_module("Hitimes");
|
345
|
-
|
346
|
-
cH_Interval = rb_define_class_under( mH, "Interval", rb_cObject );
|
347
|
-
rb_define_alloc_func( cH_Interval, hitimes_interval_alloc );
|
348
|
-
|
349
|
-
rb_define_module_function( cH_Interval, "now", hitimes_interval_now, 0 ); /* in hitimes_interval.c */
|
350
|
-
rb_define_module_function( cH_Interval, "measure", hitimes_interval_measure, 0 ); /* in hitimes_interval.c */
|
351
|
-
|
352
|
-
rb_define_method( cH_Interval, "duration", hitimes_interval_duration, 0 ); /* in hitimes_interval.c */
|
353
|
-
rb_define_method( cH_Interval, "length", hitimes_interval_duration, 0 );
|
354
|
-
rb_define_method( cH_Interval, "to_f", hitimes_interval_duration, 0 );
|
355
|
-
rb_define_method( cH_Interval, "to_seconds", hitimes_interval_duration, 0 );
|
356
|
-
|
357
|
-
rb_define_method( cH_Interval, "duration_so_far", hitimes_interval_duration_so_far, 0); /* in hitimes_interval.c */
|
358
|
-
|
359
|
-
rb_define_method( cH_Interval, "started?", hitimes_interval_started, 0 ); /* in hitimes_interval.c */
|
360
|
-
rb_define_method( cH_Interval, "running?", hitimes_interval_running, 0 ); /* in hitimes_interval.c */
|
361
|
-
rb_define_method( cH_Interval, "stopped?", hitimes_interval_stopped, 0 ); /* in hitimes_interval.c */
|
362
|
-
|
363
|
-
rb_define_method( cH_Interval, "start_instant", hitimes_interval_start_instant, 0 ); /* in hitimes_interval.c */
|
364
|
-
rb_define_method( cH_Interval, "stop_instant", hitimes_interval_stop_instant, 0 ); /* in hitimes_interval.c */
|
365
|
-
|
366
|
-
rb_define_method( cH_Interval, "start", hitimes_interval_start, 0); /* in hitimes_interval.c */
|
367
|
-
rb_define_method( cH_Interval, "stop", hitimes_interval_stop, 0); /* in hitimes_interval.c */
|
368
|
-
rb_define_method( cH_Interval, "split", hitimes_interval_split, 0); /* in hitimes_interval.c */
|
369
|
-
|
370
|
-
}
|