peek-pg 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4b8b39eb826148ef4db4087c6db736fc225b701
4
- data.tar.gz: 15093cd921a8b0974eda9f8c1a065b38bf471c02
3
+ metadata.gz: 400caa60986dcd6ca66b81ea15095c20bf31214d
4
+ data.tar.gz: 37ad94aa81f61f40992a5a28a2bedf416d58cfa9
5
5
  SHA512:
6
- metadata.gz: 1a55bd096a426a836610854bb4694bc57db67d9ca231f50202cb7f1a4f4a80b3b4cdab207aae9828bcfdb4a4ec354b06c013513c4100e30fe141a862fb1bcba0
7
- data.tar.gz: ef6c892b1f5d53613e51717fda662490de64203596b69abce225fd7b11f8def14da1135c472e1bd15ebd73f8a312d251499c1bbb18363484f75853b72f3db1f3
6
+ metadata.gz: 8142d546fae8e6cc5a7e97ad0069f4385e17d767874ad6b15620f8a7a84e4c0b11a52d5946004b3519a44fba6fd454f80044e329925e721c00d62631767c4ce8
7
+ data.tar.gz: 0bffa9c3be0ce34a0e2c2e6122a527a203a891157d8fa658061e7f1f772a720b81b43fd47f4fbb25f96583b3fc669658b1306fc9d2f79123c09bbebe15e4b0dc
@@ -10,3 +10,7 @@
10
10
 
11
11
  - Use concurrent-ruby gem in favor of deprecated atomic gem. - [#4](https://github.com/peek/peek-pg/pull/4) [@lucasmazza](https://github.com/lucasmazza)
12
12
  - Instrument prepared statements. - [#5](https://github.com/peek/peek-pg/pull/5) [@lucasmazza](https://github.com/lucasmazza)
13
+
14
+ # 1.3.0
15
+
16
+ - Use prepend to instrument Postgres queries `alias_method_chain` - [#8](https://github.com/peek/peek-pg/pull/5) [@8398a7](https://github.com/8398a7)
@@ -1,5 +1,5 @@
1
1
  module Peek
2
2
  module PG
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
@@ -1,43 +1,45 @@
1
1
  require 'pg'
2
2
  require 'concurrent/atomics'
3
3
 
4
+ module Peek
5
+ module PGInstrumented
6
+ def exec(*args)
7
+ start = Time.now
8
+ super(*args)
9
+ ensure
10
+ duration = (Time.now - start)
11
+ ::PG::Connection.query_time.update { |value| value + duration }
12
+ ::PG::Connection.query_count.update { |value| value + 1 }
13
+ end
14
+
15
+ def async_exec(*args)
16
+ start = Time.now
17
+ super(*args)
18
+ ensure
19
+ duration = (Time.now - start)
20
+ ::PG::Connection.query_time.update { |value| value + duration }
21
+ ::PG::Connection.query_count.update { |value| value + 1 }
22
+ end
23
+
24
+ def exec_prepared(*args)
25
+ start = Time.now
26
+ super(*args)
27
+ ensure
28
+ duration = (Time.now - start)
29
+ ::PG::Connection.query_time.update { |value| value + duration }
30
+ ::PG::Connection.query_count.update { |value| value + 1 }
31
+ end
32
+ end
33
+ end
34
+
4
35
  # Instrument SQL time
5
36
  class PG::Connection
37
+ prepend ::Peek::PGInstrumented
6
38
  class << self
7
39
  attr_accessor :query_time, :query_count
8
40
  end
9
41
  self.query_count = Concurrent::AtomicReference.new(0)
10
42
  self.query_time = Concurrent::AtomicReference.new(0)
11
-
12
- def exec_with_timing(*args)
13
- start = Time.now
14
- exec_without_timing(*args)
15
- ensure
16
- duration = (Time.now - start)
17
- PG::Connection.query_time.update { |value| value + duration }
18
- PG::Connection.query_count.update { |value| value + 1 }
19
- end
20
- alias_method_chain :exec, :timing
21
-
22
- def async_exec_with_timing(*args)
23
- start = Time.now
24
- async_exec_without_timing(*args)
25
- ensure
26
- duration = (Time.now - start)
27
- PG::Connection.query_time.update { |value| value + duration }
28
- PG::Connection.query_count.update { |value| value + 1 }
29
- end
30
- alias_method_chain :async_exec, :timing
31
-
32
- def exec_prepared_with_timing(*args)
33
- start = Time.now
34
- exec_prepared_without_timing(*args)
35
- ensure
36
- duration = (Time.now - start)
37
- PG::Connection.query_time.update { |value| value + duration }
38
- PG::Connection.query_count.update { |value| value + 1 }
39
- end
40
- alias_method_chain :exec_prepared, :timing
41
43
  end
42
44
 
43
45
  module Peek
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peek-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Bjerkhoel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: peek
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.5.1
108
+ rubygems_version: 2.5.2
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Take a peek into the Postgres queries made during your application's requests.