time_bandits 0.6.5 → 0.6.6

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: 57b5dc842db4022fe784671d7387d31aba84fa23
4
- data.tar.gz: 6c821882f1104e05d02aabb24c568cec412757fe
3
+ metadata.gz: cd2fea3396b9dc6b70fe418f7acd0955eba13231
4
+ data.tar.gz: 84ce369bee8fe66c3d610a52eb1baaf74bab6b54
5
5
  SHA512:
6
- metadata.gz: d0046d74137b95d4ab0993e184f38c8992bf668f6ca0e869245418b5147a15895f53d43b5e50ab353508d66ced9fab0c8b160b4381b5619908831848f6b5c882
7
- data.tar.gz: f31f4da71e755fdb3fe4014bbdf7e390398150ff9f276265ab88f1e56f143a32c175109fcc1d4c200aae45d17cabcb30f585f0179c1382baac0624c05a0bbaab
6
+ metadata.gz: 3088b4806584633d9ea8b67f8f6ca9d50d0c3c6cd2c0780edcf88aa2db04f3d13690098d003259c678aae19682338dd601331b64ea1e3871f9bebede96a7f6b9
7
+ data.tar.gz: e03a9141f1107232b757e94df87f5fda7aac3b63315260e87e4f91d56c3cf2477e961734be5c0d599df4f4866669932c08c7e404cd0154a808679aa564f261c7
@@ -42,18 +42,29 @@ module ActiveRecord
42
42
  hits
43
43
  end
44
44
 
45
- def render_bind(column, value)
46
- if column
47
- if column.type == :binary
48
- value = "<#{value.bytesize} bytes of binary data>"
45
+ # Rails 4.1 uses method_added to automatically subscribe newly
46
+ # added methods. Since :render_bind and :sql are already defined,
47
+ # the net effect is that sql gets called twice. Therefore, we
48
+ # temporarily switch to protected mode and change it back later to
49
+ # public.
50
+
51
+ unless instance_methods.include?(:render_bind)
52
+ protected
53
+ def render_bind(column, value)
54
+ if column
55
+ if column.type == :binary
56
+ value = "<#{value.bytesize} bytes of binary data>"
57
+ end
58
+ [column.name, value]
59
+ else
60
+ [nil, value]
49
61
  end
50
-
51
- [column.name, value]
52
- else
53
- [nil, value]
54
62
  end
55
- end unless instance_methods.include?(:render_bind)
63
+ public :render_bind
64
+ public
65
+ end
56
66
 
67
+ protected
57
68
  def sql(event)
58
69
  self.class.runtime += event.duration
59
70
  self.class.call_count += 1
@@ -85,6 +96,8 @@ module ActiveRecord
85
96
  debug " #{name} #{sql}#{binds}"
86
97
  end
87
98
  end
99
+ public :sql
100
+ public
88
101
 
89
102
  module Railties
90
103
  module ControllerRuntime
@@ -99,4 +112,3 @@ module ActiveRecord
99
112
  end
100
113
  end
101
114
  end
102
-
@@ -16,7 +16,7 @@ module TimeBandits
16
16
  def request(event)
17
17
  i = Redis.instance
18
18
  i.time += event.duration
19
- i.calls += event.payload[:commands].size
19
+ i.calls += 1 #count redis round trips, not calls
20
20
 
21
21
  return unless logger.debug?
22
22
 
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  end
@@ -37,7 +37,28 @@ class RedisTest < Test::Unit::TestCase
37
37
  assert_equal 0, m[:redis_time]
38
38
  end
39
39
 
40
+ test "counts pipelined calls as single call" do
41
+ pipelined_work
42
+ m = TimeBandits.metrics
43
+ assert_equal 1, m[:redis_calls]
44
+ end
45
+
46
+ test "counts multi calls as single call" do
47
+ pipelined_work(:multi)
48
+ m = TimeBandits.metrics
49
+ assert_equal 1, m[:redis_calls]
50
+ end
51
+
40
52
  private
53
+ def pipelined_work(type = :pipelined)
54
+ TimeBandits.reset
55
+ @redis.send(type) do
56
+ @redis.get("foo")
57
+ @redis.set("bar", 1)
58
+ @redis.hgetall("baz")
59
+ end
60
+ end
61
+
41
62
  def work
42
63
  TimeBandits.reset
43
64
  2.times do
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.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_variables