glimpse-pg 1.0.0 → 1.1.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.
- data/CHANGELOG.md +7 -0
- data/glimpse-pg.gemspec +2 -0
- data/lib/glimpse-pg/version.rb +1 -1
- data/lib/glimpse/views/pg.rb +19 -11
- metadata +35 -2
data/CHANGELOG.md
ADDED
data/glimpse-pg.gemspec
CHANGED
data/lib/glimpse-pg/version.rb
CHANGED
data/lib/glimpse/views/pg.rb
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
require 'pg'
|
|
2
|
+
require 'atomic'
|
|
2
3
|
|
|
3
4
|
# Instrument SQL time
|
|
4
5
|
class PG::Connection
|
|
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 exec_with_timing(*args)
|
|
12
13
|
start = Time.now
|
|
13
14
|
exec_without_timing(*args)
|
|
14
15
|
ensure
|
|
15
|
-
|
|
16
|
-
PG::Connection.
|
|
16
|
+
duration = (Time.now - start)
|
|
17
|
+
PG::Connection.query_time.update { |value| value + duration }
|
|
18
|
+
PG::Connection.query_count.update { |value| value + 1 }
|
|
17
19
|
end
|
|
18
20
|
alias_method_chain :exec, :timing
|
|
19
21
|
|
|
@@ -21,8 +23,9 @@ class PG::Connection
|
|
|
21
23
|
start = Time.now
|
|
22
24
|
async_exec_without_timing(*args)
|
|
23
25
|
ensure
|
|
24
|
-
|
|
25
|
-
PG::Connection.
|
|
26
|
+
duration = (Time.now - start)
|
|
27
|
+
PG::Connection.query_time.update { |value| value + duration }
|
|
28
|
+
PG::Connection.query_count.update { |value| value + 1 }
|
|
26
29
|
end
|
|
27
30
|
alias_method_chain :async_exec, :timing
|
|
28
31
|
end
|
|
@@ -31,15 +34,20 @@ module Glimpse
|
|
|
31
34
|
module Views
|
|
32
35
|
class PG < View
|
|
33
36
|
def duration
|
|
34
|
-
::PG::Connection.query_time
|
|
37
|
+
::PG::Connection.query_time.value
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
def formatted_duration
|
|
38
|
-
|
|
41
|
+
ms = duration * 1000
|
|
42
|
+
if ms >= 1000
|
|
43
|
+
"%.2fms" % ms
|
|
44
|
+
else
|
|
45
|
+
"%.0fms" % ms
|
|
46
|
+
end
|
|
39
47
|
end
|
|
40
48
|
|
|
41
49
|
def calls
|
|
42
|
-
::PG::Connection.query_count
|
|
50
|
+
::PG::Connection.query_count.value
|
|
43
51
|
end
|
|
44
52
|
|
|
45
53
|
def results
|
|
@@ -51,8 +59,8 @@ module Glimpse
|
|
|
51
59
|
def setup_subscribers
|
|
52
60
|
# Reset each counter when a new request starts
|
|
53
61
|
before_request do
|
|
54
|
-
::PG::Connection.query_time = 0
|
|
55
|
-
::PG::Connection.query_count = 0
|
|
62
|
+
::PG::Connection.query_time.value = 0
|
|
63
|
+
::PG::Connection.query_count.value = 0
|
|
56
64
|
end
|
|
57
65
|
end
|
|
58
66
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: glimpse-pg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,8 +9,24 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-03-
|
|
12
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: glimpse
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
14
30
|
- !ruby/object:Gem::Dependency
|
|
15
31
|
name: pg
|
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -27,6 +43,22 @@ dependencies:
|
|
|
27
43
|
- - ! '>='
|
|
28
44
|
- !ruby/object:Gem::Version
|
|
29
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
|
|
30
62
|
description: Provide a glimpse into the Postgres queries made during your application's
|
|
31
63
|
requests.
|
|
32
64
|
email:
|
|
@@ -36,6 +68,7 @@ extensions: []
|
|
|
36
68
|
extra_rdoc_files: []
|
|
37
69
|
files:
|
|
38
70
|
- .gitignore
|
|
71
|
+
- CHANGELOG.md
|
|
39
72
|
- Gemfile
|
|
40
73
|
- LICENSE.txt
|
|
41
74
|
- README.md
|