hitimes 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/HISTORY +69 -0
  2. data/LICENSE +13 -0
  3. data/README +134 -0
  4. data/Rakefile +66 -0
  5. data/examples/benchmarks.rb +113 -0
  6. data/examples/stats.rb +31 -0
  7. data/ext/hitimes/extconf.rb +17 -0
  8. data/ext/hitimes/hitimes_ext.c +21 -0
  9. data/ext/hitimes/hitimes_instant_clock_gettime.c +28 -0
  10. data/ext/hitimes/hitimes_instant_osx.c +16 -0
  11. data/ext/hitimes/hitimes_instant_windows.c +27 -0
  12. data/ext/hitimes/hitimes_interval.c +362 -0
  13. data/ext/hitimes/hitimes_interval.h +73 -0
  14. data/ext/hitimes/hitimes_stats.c +269 -0
  15. data/ext/hitimes/hitimes_stats.h +30 -0
  16. data/ext/java/src/hitimes/Hitimes.java +54 -0
  17. data/ext/java/src/hitimes/HitimesInterval.java +174 -0
  18. data/ext/java/src/hitimes/HitimesService.java +16 -0
  19. data/ext/java/src/hitimes/HitimesStats.java +112 -0
  20. data/gemspec.rb +65 -0
  21. data/lib/hitimes.rb +37 -0
  22. data/lib/hitimes/hitimes.jar +0 -0
  23. data/lib/hitimes/metric.rb +118 -0
  24. data/lib/hitimes/mutexed_stats.rb +32 -0
  25. data/lib/hitimes/paths.rb +53 -0
  26. data/lib/hitimes/stats.rb +58 -0
  27. data/lib/hitimes/timed_metric.rb +176 -0
  28. data/lib/hitimes/timed_value_metric.rb +233 -0
  29. data/lib/hitimes/value_metric.rb +71 -0
  30. data/lib/hitimes/version.rb +57 -0
  31. data/spec/interval_spec.rb +133 -0
  32. data/spec/metric_spec.rb +30 -0
  33. data/spec/mutex_stats_spec.rb +34 -0
  34. data/spec/paths_spec.rb +13 -0
  35. data/spec/spec_helper.rb +5 -0
  36. data/spec/stats_spec.rb +100 -0
  37. data/spec/timed_metric_spec.rb +155 -0
  38. data/spec/timed_value_metric_spec.rb +172 -0
  39. data/spec/value_metric_spec.rb +110 -0
  40. data/spec/version_spec.rb +33 -0
  41. data/tasks/announce.rake +42 -0
  42. data/tasks/config.rb +109 -0
  43. data/tasks/distribution.rake +93 -0
  44. data/tasks/documentation.rake +32 -0
  45. data/tasks/extension.rake +108 -0
  46. data/tasks/rspec.rake +33 -0
  47. data/tasks/rubyforge.rake +55 -0
  48. data/tasks/utils.rb +80 -0
  49. metadata +191 -0
@@ -0,0 +1,172 @@
1
+ require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
+
3
+ require 'hitimes/timed_value_metric'
4
+
5
+ describe Hitimes::TimedValueMetric do
6
+ before( :each ) do
7
+ @tm = Hitimes::TimedValueMetric.new( 'test-timed-value-metric' )
8
+ end
9
+
10
+ it "knows if it is running or not" do
11
+ @tm.should_not be_running
12
+ @tm.start
13
+ @tm.should be_running
14
+ @tm.stop( 1 )
15
+ @tm.should_not be_running
16
+ end
17
+
18
+ it "#split returns the last duration and the timer is still running" do
19
+ @tm.start
20
+ d = @tm.split( 1 )
21
+ @tm.should be_running
22
+ d.should > 0
23
+ @tm.value_stats.count.should == 1
24
+ @tm.timed_stats.count.should == 1
25
+ @tm.duration.should == d
26
+ end
27
+
28
+ it "#stop returns false if called more than once in a row" do
29
+ @tm.start
30
+ @tm.stop( 1 ).should > 0
31
+ @tm.stop( 1 ).should == false
32
+ end
33
+
34
+ it "does not count a currently running interval as an interval in calculations" do
35
+ @tm.start
36
+ @tm.value_stats.count.should == 0
37
+ @tm.timed_stats.count.should == 0
38
+ @tm.split( 1 )
39
+ @tm.value_stats.count.should == 1
40
+ @tm.timed_stats.count.should == 1
41
+ end
42
+
43
+ it "#split called on a stopped timer does nothing" do
44
+ @tm.start
45
+ @tm.stop( 1 )
46
+ @tm.split( 1 ).should == false
47
+ end
48
+
49
+ it "calculates the mean of the durations" do
50
+ 3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop(x) }
51
+ @tm.timed_stats.mean.should be_close( 0.05, 0.01 )
52
+ @tm.value_stats.mean.should == 1.00
53
+ end
54
+
55
+ it "calculates the rate of the counts " do
56
+ 5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
57
+ @tm.rate.should be_close( 40.0, 0.2)
58
+ end
59
+
60
+
61
+ it "calculates the stddev of the durations" do
62
+ 3.times { |x| @tm.start ; sleep (0.05 * x) ; @tm.stop(x) }
63
+ @tm.timed_stats.stddev.should be_close( 0.05, 0.001)
64
+ @tm.value_stats.stddev.should == 1.0
65
+ end
66
+
67
+ it "returns 0.0 for stddev if there is no data" do
68
+ @tm.timed_stats.stddev.should == 0.0
69
+ @tm.value_stats.stddev.should == 0.0
70
+ end
71
+
72
+ it "keeps track of the min value" do
73
+ 3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
74
+ @tm.timed_stats.min.should be_close( 0.05, 0.001 )
75
+ @tm.value_stats.min.should == 0
76
+ end
77
+
78
+ it "keeps track of the max value" do
79
+ 3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
80
+ @tm.timed_stats.max.should be_close( 0.05, 0.001)
81
+ @tm.value_stats.max.should == 2
82
+ end
83
+
84
+ it "keeps track of the sum value" do
85
+ 3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
86
+ @tm.timed_stats.sum.should be_close( 0.15, 0.01 )
87
+ @tm.value_stats.sum.should == 3
88
+ end
89
+
90
+ it "keeps track of the sum of squares value" do
91
+ 3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
92
+ @tm.timed_stats.sumsq.should be_close( 0.0075, 0.0001 )
93
+ @tm.value_stats.sumsq.should == 5
94
+ end
95
+
96
+ it "keeps track of the minimum start time of all the intervals" do
97
+ f1 = Time.now.gmtime.to_f * 1000000
98
+ 5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
99
+ f2 = Time.now.gmtime.to_f * 1000000
100
+ @tm.sampling_start_time.should >= f1
101
+ @tm.sampling_start_time.should < f2
102
+ # distance from now to start time should be greater than the distance from
103
+ # the start to the min start_time
104
+ (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
105
+ end
106
+
107
+ it "keeps track of the last stop time of all the intervals" do
108
+ f1 = Time.now.gmtime.to_f * 1000000
109
+ 5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
110
+ f2 = Time.now.gmtime.to_f * 1000000
111
+ @tm.sampling_stop_time.should > f1
112
+ @tm.sampling_stop_time.should <= f2
113
+ # distance from now to max stop time time should be less than the distance
114
+ # from the start to the max stop time
115
+ (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
116
+ end
117
+
118
+ it "can create an already running timer" do
119
+ t = Hitimes::TimedValueMetric.now( 'already-running' )
120
+ t.should be_running
121
+ end
122
+
123
+ it "can measure a block of code from an instance" do
124
+ t = Hitimes::TimedValueMetric.new( 'measure a block' )
125
+ 3.times { t.measure( 1 ) { sleep 0.05 } }
126
+ t.duration.should be_close( 0.15, 0.001 )
127
+ t.timed_stats.count.should == 3
128
+ t.value_stats.count.should == 3
129
+ end
130
+
131
+ it "returns the value of the block when measuring" do
132
+ t = Hitimes::TimedValueMetric.new( 'measure a block' )
133
+ x = t.measure( 42 ) { sleep 0.05; 42 }
134
+ t.duration.should be_close( 0.05, 0.001 )
135
+ x.should == 42
136
+ end
137
+
138
+ describe "#to_hash" do
139
+
140
+ it "has name value" do
141
+ h = @tm.to_hash
142
+ h['name'].should == "test-timed-value-metric"
143
+ end
144
+
145
+ it "has an empty has for additional_data" do
146
+ h = @tm.to_hash
147
+ h['additional_data'].should == Hash.new
148
+ h['additional_data'].size.should == 0
149
+ end
150
+
151
+ it "has a rate" do
152
+ 5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
153
+ h = @tm.to_hash
154
+ h['rate'].should be_close( 40.0, 0.3 )
155
+ end
156
+
157
+ it "has a unit_count" do
158
+ 5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
159
+ h = @tm.to_hash
160
+ h['unit_count'].should == 10
161
+ end
162
+
163
+ fields = %w[ name additional_data sampling_start_time sampling_stop_time value_stats timed_stats rate unit_count ]
164
+ fields.each do |f|
165
+ it "should have a value for #{f}" do
166
+ 3.times { |x| @tm.measure(x) { sleep 0.001 } }
167
+ h = @tm.to_hash
168
+ h[f].should_not be_nil
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,110 @@
1
+ require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
+
3
+ require 'hitimes/value_metric'
4
+
5
+ describe Hitimes::ValueMetric do
6
+ before( :each ) do
7
+ @metric = Hitimes::ValueMetric.new( "testing" )
8
+ 10.times { |x| @metric.measure( x ) }
9
+ end
10
+
11
+ it 'has a name' do
12
+ @metric.name.should == "testing"
13
+ end
14
+
15
+ it "has associated data from initialization" do
16
+ m = Hitimes::ValueMetric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
17
+ m.additional_data['foo'].should == 'bar'
18
+ m.additional_data['this'].should == 'that'
19
+
20
+ m = Hitimes::ValueMetric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
21
+ m.additional_data['foo'].should == 'bar'
22
+ m.additional_data['this'].should == 'that'
23
+ end
24
+
25
+ it "calculates the mean of the measurements" do
26
+ @metric.mean.should == 4.5
27
+ end
28
+
29
+ it "calculates the stddev of the measurements" do
30
+ @metric.stddev.should > 0.0
31
+ end
32
+
33
+ it "returns 0.0 for stddev if there is no data" do
34
+ m = Hitimes::ValueMetric.new('0-data')
35
+ m.stddev.should == 0.0
36
+ end
37
+
38
+ it "keeps track of the sum of data" do
39
+ @metric.sum.should == 45.0
40
+ end
41
+
42
+ it "keeps track of the sum of squars of data" do
43
+ @metric.sumsq.should == 285.0
44
+ end
45
+
46
+ it "retuns 0.0 for mean if there is no data" do
47
+ Hitimes::ValueMetric.new('0-data').mean.should == 0.0
48
+ end
49
+
50
+ it "keeps track of the min value" do
51
+ @metric.min.should == 0
52
+ end
53
+
54
+ it "keeps track of the max value" do
55
+ @metric.max.should == 9
56
+ end
57
+
58
+ it "keeps track of the first start time of all the measurements" do
59
+ m = Hitimes::ValueMetric.new( "first-start-time" )
60
+ f1 = Time.now.gmtime.to_f * 1_000_000
61
+ 10.times{ |x| m.measure( x ); sleep 0.1 }
62
+ f2 = Time.now.gmtime.to_f * 1_000_000
63
+ m.sampling_start_time.should >= f1
64
+ m.sampling_start_time.should < f2
65
+ # distance from now to start time should be greater than the distance from
66
+ # the start to the min start_time
67
+ (f2 - m.sampling_start_time).should > ( m.sampling_start_time - f1 )
68
+ end
69
+
70
+ it "keeps track of the last stop time of all the intervals" do
71
+ m = Hitimes::ValueMetric.new( "last-stop-time" )
72
+ f1 = Time.now.gmtime.to_f * 1_000_000
73
+ 10.times {|x| m.measure( x ); sleep 0.1 }
74
+ f2 = Time.now.gmtime.to_f * 1_000_000
75
+ m.sampling_stop_time.should > f1
76
+ m.sampling_stop_time.should <= f2
77
+ # distance from now to max stop time time should be less than the distance
78
+ # from the start to the max stop time
79
+ (f2 - m.sampling_stop_time).should < ( m.sampling_stop_time - f1 )
80
+ end
81
+
82
+ describe "#to_hash" do
83
+
84
+ it "has name value" do
85
+ h = @metric.to_hash
86
+ h['name'].should == "testing"
87
+ end
88
+
89
+ it "has an empty has for additional_data" do
90
+ h = @metric.to_hash
91
+ h['additional_data'].should == Hash.new
92
+ h['additional_data'].size.should == 0
93
+ end
94
+
95
+ it "has the right sum" do
96
+ h = @metric.to_hash
97
+ h['sum'].should == 45
98
+ end
99
+
100
+ fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
101
+ fields = fields - [ 'rate' ]
102
+ fields.each do |f|
103
+ it "should have a value for #{f}" do
104
+ h = @metric.to_hash
105
+ h[f].should_not be_nil
106
+ end
107
+ end
108
+ end
109
+ end
110
+
@@ -0,0 +1,33 @@
1
+ require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper" ) )
2
+
3
+ describe "Hitimes::Version" do
4
+ it "should have a major numbers that is >= 0" do
5
+ Hitimes::Version::MAJOR.should >= 0
6
+ end
7
+
8
+ it "should have a minor number that is >= 0" do
9
+ Hitimes::Version::MINOR.should >= 0
10
+ end
11
+
12
+ it "should have a tiny number that is >= 0" do
13
+ Hitimes::Version::BUILD.should >= 0
14
+ end
15
+
16
+ it "should have an array representation" do
17
+ Hitimes::Version.to_a.should have(3).items
18
+ end
19
+
20
+ it "should have a string representation" do
21
+ Hitimes::Version.to_s.should match(/\d+\.\d+\.\d+/)
22
+ end
23
+
24
+ it "should have a hash representation" do
25
+ [ :major, :minor, :build ].each do |k|
26
+ Hitimes::Version.to_hash[k].should_not be_nil
27
+ end
28
+ end
29
+
30
+ it "should be accessable as a constant" do
31
+ Hitimes::VERSION.should match(/\d+\.\d+\.\d+/)
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ require 'tasks/config'
2
+ #-------------------------------------------------------------------------------
3
+ # announcement methods
4
+ #-------------------------------------------------------------------------------
5
+
6
+ proj_config = Configuration.for('project')
7
+ namespace :announce do
8
+ desc "create email for ruby-talk"
9
+ task :email do
10
+ info = Utils.announcement
11
+
12
+ File.open("email.txt", "w") do |mail|
13
+ mail.puts "From: #{proj_config.author} <#{proj_config.email}>"
14
+ mail.puts "To: ruby-talk@ruby-lang.org"
15
+ mail.puts "Date: #{Time.now.rfc2822}"
16
+ mail.puts "Subject: [ANN] #{info[:subject]}"
17
+ mail.puts
18
+ mail.puts info[:title]
19
+ mail.puts
20
+ mail.puts "{{ Release notes for Version #{Hitimes::VERSION} }}"
21
+ mail.puts
22
+ mail.puts info[:release_notes]
23
+ mail.puts
24
+ mail.puts " #{info[:urls]}"
25
+ mail.puts
26
+ mail.puts "=== Installation"
27
+ mail.puts
28
+ mail.puts " gem install #{Hitimes::GEM_SPEC.name}"
29
+ mail.puts
30
+ mail.puts "=== Description"
31
+ mail.puts
32
+ mail.puts info[:description]
33
+ end
34
+ puts "Created the following as email.txt:"
35
+ puts "-" * 72
36
+ puts File.read("email.txt")
37
+ puts "-" * 72
38
+ end
39
+
40
+ CLOBBER << "email.txt"
41
+ end
42
+
@@ -0,0 +1,109 @@
1
+ require 'configuration'
2
+
3
+ require 'rake'
4
+ require 'tasks/utils'
5
+ require 'yaml'
6
+
7
+ #-----------------------------------------------------------------------
8
+ # General project configuration
9
+ #-----------------------------------------------------------------------
10
+ Configuration.for('project') {
11
+ name "hitimes"
12
+ version Hitimes::Version.to_s
13
+ author "Jeremy Hinegardner"
14
+ email "jeremy at copiousfreetime dot org"
15
+ homepage "http://copiousfreetime.rubyforge.org/hitimes/"
16
+ description Utils.section_of("README", "description")
17
+ summary description.split(".").first
18
+ history "HISTORY"
19
+ license FileList["LICENSE"]
20
+ readme "README"
21
+ }
22
+
23
+ #-----------------------------------------------------------------------
24
+ # Packaging
25
+ #-----------------------------------------------------------------------
26
+ Configuration.for('packaging') {
27
+ # files in the project
28
+ proj_conf = Configuration.for('project')
29
+ files {
30
+ bin FileList["bin/*"]
31
+ ext FileList["ext/hitimes/*.{c,h,rb}"]
32
+ examples FileList["examples/*.rb"]
33
+ lib FileList["lib/**/*.rb"]
34
+ test FileList["spec/**/*.rb", "test/**/*.rb"]
35
+ data FileList["data/**/*"]
36
+ tasks FileList["tasks/**/*.r{ake,b}"]
37
+ rdoc FileList[proj_conf.readme, proj_conf.history,
38
+ proj_conf.license] + lib + FileList["ext/*.c"]
39
+ all bin + examples + ext + lib + test + data + rdoc + tasks + FileList["Rakefile"]
40
+ }
41
+
42
+ # ways to package the results
43
+ formats {
44
+ tgz true
45
+ zip true
46
+ rubygem Configuration::Table.has_key?('gem')
47
+ }
48
+ }
49
+
50
+ #-----------------------------------------------------------------------
51
+ # Gem packaging
52
+ #-----------------------------------------------------------------------
53
+ Configuration.for("gem") {
54
+ spec "gemspec.rb"
55
+ Configuration.for('packaging').files.all << spec
56
+ }
57
+
58
+ #-----------------------------------------------------------------------
59
+ # Testing
60
+ # - change mode to 'testunit' to use unit testing
61
+ #-----------------------------------------------------------------------
62
+ Configuration.for('test') {
63
+ mode "spec"
64
+ files Configuration.for("packaging").files.test
65
+ options %w[ --format specdoc --color ]
66
+ ruby_opts %w[ ]
67
+ }
68
+
69
+ #-----------------------------------------------------------------------
70
+ # Rcov
71
+ #-----------------------------------------------------------------------
72
+ Configuration.for('rcov') {
73
+ output_dir "coverage"
74
+ libs %w[ lib ]
75
+ rcov_opts %w[ --html ]
76
+ ruby_opts %w[ ]
77
+ test_files Configuration.for('packaging').files.test
78
+ }
79
+
80
+ #-----------------------------------------------------------------------
81
+ # Rdoc
82
+ #-----------------------------------------------------------------------
83
+ Configuration.for('rdoc') {
84
+ files Configuration.for('packaging').files.rdoc
85
+ main_page files.first
86
+ title Configuration.for('project').name
87
+ options %w[ --line-numbers ]
88
+ output_dir "doc"
89
+ }
90
+
91
+ #-----------------------------------------------------------------------
92
+ # Extension
93
+ #-----------------------------------------------------------------------
94
+ Configuration.for('extension') {
95
+ configs Configuration.for('packaging').files.ext.find_all { |x| %w[ mkrf_conf.rb extconf.rb ].include?(File.basename(x)) }
96
+ cross_rbconfig ::YAML::load_file( File.expand_path("~/.rake-compiler/config.yml"))
97
+ }
98
+
99
+ #-----------------------------------------------------------------------
100
+ # Rubyforge
101
+ #-----------------------------------------------------------------------
102
+ Configuration.for('rubyforge') {
103
+ project "copiousfreetime"
104
+ user "jjh"
105
+ host "rubyforge.org"
106
+ rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}/hitimes"
107
+ }
108
+
109
+