time_bandits 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17110b29f1ba8ee80a3ca0de9909218131cdf064
4
- data.tar.gz: 4dfb3e7de75bc3501e6f85cfb18c07cd0f518868
3
+ metadata.gz: 116ff4f8110fea48a1fce36cea8362c06d9df6f5
4
+ data.tar.gz: 700559c495052c511e3b7ec61162249181653fcc
5
5
  SHA512:
6
- metadata.gz: 2463780ec2f4d803d685aec3aa32ba3026b51fc416a4651763abf109183b9102a166e2f8f50241df224d79e91045e95cbdbf17d8b395297519e7bf6c4c3e740a
7
- data.tar.gz: 01e05bdadc84b9c14c6a1e8b0437c7794d67b1a69243d85c2bdee7b627bbcfee3506333fe113c9bafe057512d192205d30206e7bd36af7762a478055e30b3d99
6
+ metadata.gz: 6e215bb352bd437f48d955a387514006feedabb8b636fe3fe9abc65265af289a90d80e5c8eabba0cc3249b53729df2b2d37c0a1d00165ae857f5222b56726920
7
+ data.tar.gz: b761564d4c867a55bec84221c674901cf223312de4788714e37a5cb999c044b001a2857f03b318740a335b109e6f8e74ea383715b7f92d78d701a31d334923bd
@@ -37,6 +37,11 @@ module TimeBandits
37
37
  time_bandits.map{|b| b.consumed}.sum
38
38
  end
39
39
 
40
+ def self.current_runtime(except = [])
41
+ except = Array(except)
42
+ time_bandits.map{|b| except.include?(b) ? 0 : b.current_runtime}.sum
43
+ end
44
+
40
45
  def self.runtimes
41
46
  time_bandits.map{|b| b.runtime}.reject{|t| t.blank?}
42
47
  end
@@ -54,6 +54,8 @@ module TimeBandits::TimeConsumers
54
54
  @counters[0]
55
55
  end
56
56
 
57
+ alias_method :current_runtime, :consumed
58
+
57
59
  def runtime
58
60
  values = metrics.values_at(*self.class.runtime_keys)
59
61
  if values.all?{|v|v==0}
@@ -26,6 +26,10 @@ module TimeBandits
26
26
  i.time += time
27
27
  end
28
28
 
29
+ def current_runtime
30
+ Database.instance.time + ActiveRecord::LogSubscriber.runtime
31
+ end
32
+
29
33
  private
30
34
 
31
35
  def reset_stats
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.7.4"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -26,6 +26,7 @@ class NoTimeBanditsTest < Test::Unit::TestCase
26
26
  def test_clean_state
27
27
  assert_equal Hash.new, TimeBandits.metrics
28
28
  assert_equal 0, TimeBandits.consumed
29
+ assert_equal 0, TimeBandits.current_runtime
29
30
  assert_equal "", TimeBandits.runtime
30
31
  end
31
32
  end
@@ -33,9 +34,10 @@ end
33
34
  class DummyConsumerTest < Test::Unit::TestCase
34
35
  module DummyConsumer
35
36
  extend self
36
- def consumed; 0; end
37
+ def consumed; 1; end
38
+ def current_runtime; 1; end
37
39
  def runtime; "Dummy: 0ms"; end
38
- def metrics; {:dummy_time => 0, :dummy_calls => 0}; end
40
+ def metrics; {:dummy_time => 1, :dummy_calls => 1}; end
39
41
  def reset; end
40
42
  end
41
43
 
@@ -57,7 +59,19 @@ class DummyConsumerTest < Test::Unit::TestCase
57
59
  assert_nothing_raised { TimeBandits.reset }
58
60
  end
59
61
 
62
+ test "consumed" do
63
+ assert_equal 1, TimeBandits.consumed
64
+ end
65
+
66
+ test "current_runtime" do
67
+ assert_equal 1, TimeBandits.current_runtime
68
+ end
69
+
70
+ test "current_runtime without DummyConsumer" do
71
+ assert_equal 0, TimeBandits.current_runtime(DummyConsumer)
72
+ end
73
+
60
74
  test "getting metrics" do
61
- assert_equal({:dummy_time => 0, :dummy_calls => 0}, TimeBandits.metrics)
75
+ assert_equal({:dummy_time => 1, :dummy_calls => 1}, TimeBandits.metrics)
62
76
  end
63
77
  end
@@ -0,0 +1,47 @@
1
+ require_relative '../test_helper'
2
+ require 'active_record'
3
+ require 'time_bandits/monkey_patches/active_record'
4
+
5
+ class DatabaseTest < Test::Unit::TestCase
6
+ def setup
7
+ TimeBandits.time_bandits = []
8
+ TimeBandits.add TimeBandits::TimeConsumers::Database
9
+ TimeBandits.reset
10
+ end
11
+
12
+ test "getting metrics" do
13
+ nothing_measured = {
14
+ :db_time => 0,
15
+ :db_calls => 0,
16
+ :db_sql_query_cache_hits => 0
17
+ }
18
+ assert_equal nothing_measured, TimeBandits.metrics
19
+ end
20
+
21
+ test "formatting" do
22
+ log_subscriber.runtime += 1.234
23
+ log_subscriber.call_count += 3
24
+ log_subscriber.query_cache_hits += 1
25
+ TimeBandits.consumed
26
+ assert_equal "ActiveRecord: 1.234ms(3q,1h)", TimeBandits.runtime
27
+ end
28
+
29
+ test "accessing current runtime" do
30
+ log_subscriber.runtime += 1.234
31
+ assert_equal 1.234, TimeBandits.consumed
32
+ assert_equal 0, log_subscriber.runtime
33
+ log_subscriber.runtime += 4.0
34
+ assert_equal 5.234, bandit.current_runtime
35
+ assert_equal "ActiveRecord: 1.234ms(0q,0h)", TimeBandits.runtime
36
+ end
37
+
38
+ private
39
+
40
+ def bandit
41
+ TimeBandits::TimeConsumers::Database.instance
42
+ end
43
+
44
+ def log_subscriber
45
+ ActiveRecord::LogSubscriber
46
+ end
47
+ end
@@ -25,12 +25,13 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency("appraisal")
26
26
  s.add_development_dependency("byebug")
27
27
  s.add_development_dependency("dalli")
28
- s.add_development_dependency("memcached")
28
+ s.add_development_dependency("memcached", "~> 1.8.0")
29
29
  s.add_development_dependency("minitest", "~> 5.5")
30
30
  s.add_development_dependency("mocha")
31
31
  s.add_development_dependency("mysql2")
32
32
  s.add_development_dependency("rake")
33
33
  s.add_development_dependency("redis")
34
34
  s.add_development_dependency("sequel")
35
+ s.add_development_dependency("activerecord")
35
36
  end
36
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_bandits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-05 00:00:00.000000000 Z
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_variables
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: memcached
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 1.8.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 1.8.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: minitest
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: activerecord
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description: Rails Completed Line on Steroids
196
210
  email:
197
211
  - skaes@railsexpress.de
@@ -233,6 +247,7 @@ files:
233
247
  - test/unit/active_support_notifications_test.rb
234
248
  - test/unit/base_test.rb
235
249
  - test/unit/dalli_test.rb
250
+ - test/unit/database_test.rb
236
251
  - test/unit/duplicate_bandits.rb
237
252
  - test/unit/gc_consumer_test.rb
238
253
  - test/unit/memcached_test.rb
@@ -268,6 +283,7 @@ test_files:
268
283
  - test/unit/active_support_notifications_test.rb
269
284
  - test/unit/base_test.rb
270
285
  - test/unit/dalli_test.rb
286
+ - test/unit/database_test.rb
271
287
  - test/unit/duplicate_bandits.rb
272
288
  - test/unit/gc_consumer_test.rb
273
289
  - test/unit/memcached_test.rb