glimpse-redis 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -5,3 +5,7 @@
5
5
  # 1.0.1
6
6
 
7
7
  - Fixed a bug where Redis::Client may have a block passed to some methods and if not passed would return 0 instead of true or false.
8
+
9
+ # 1.1.0
10
+
11
+ - Query count and Query time are now threadsafe.
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'glimpse'
21
21
  gem.add_dependency 'redis'
22
+ gem.add_dependency 'atomic', '>= 1.0.0'
22
23
  end
@@ -1,5 +1,5 @@
1
1
  module Glimpse
2
2
  module Redis
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -1,19 +1,21 @@
1
1
  require 'redis'
2
+ require 'atomic'
2
3
 
3
4
  # Instrument Redis time
4
5
  class Redis::Client
5
6
  class << self
6
7
  attr_accessor :query_time, :query_count
7
8
  end
8
- self.query_count = 0
9
- self.query_time = 0
9
+ self.query_count = Atomic.new(0)
10
+ self.query_time = Atomic.new(0)
10
11
 
11
12
  def call_with_timing(*args, &block)
12
13
  start = Time.now
13
14
  call_without_timing(*args, &block)
14
15
  ensure
15
- Redis::Client.query_time += (Time.now - start)
16
- Redis::Client.query_count += 1
16
+ duration = (Time.now - start)
17
+ Redis::Client.query_time.update { |value| value + duration }
18
+ Redis::Client.query_count.update { |value| value + 1 }
17
19
  end
18
20
  alias_method_chain :call, :timing
19
21
  end
@@ -22,7 +24,7 @@ module Glimpse
22
24
  module Views
23
25
  class Redis < View
24
26
  def duration
25
- ::Redis::Client.query_time
27
+ ::Redis::Client.query_time.value
26
28
  end
27
29
 
28
30
  def formatted_duration
@@ -35,7 +37,7 @@ module Glimpse
35
37
  end
36
38
 
37
39
  def calls
38
- ::Redis::Client.query_count
40
+ ::Redis::Client.query_count.value
39
41
  end
40
42
 
41
43
  def results
@@ -47,8 +49,8 @@ module Glimpse
47
49
  def setup_subscribers
48
50
  # Reset each counter when a new request starts
49
51
  subscribe 'start_processing.action_controller' do
50
- ::Redis::Client.query_time = 0
51
- ::Redis::Client.query_count = 0
52
+ ::Redis::Client.query_time.value = 0
53
+ ::Redis::Client.query_count.value = 0
52
54
  end
53
55
  end
54
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimpse-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: glimpse
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: atomic
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
46
62
  description: Provide a glimpse into the Redis calls made within your Rails application.
47
63
  email:
48
64
  - me@garrettbjerkhoel.com