rails_instrument 0.0.2 → 0.0.3
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/lib/rails_instrument.rb +33 -4
- data/lib/rails_instrument/version.rb +1 -1
- data/readme.md +4 -4
- metadata +2 -2
data/lib/rails_instrument.rb
CHANGED
@@ -44,15 +44,44 @@ module RailsInstrument
|
|
44
44
|
RailsInstrument.reset!
|
45
45
|
status, headers, body = @app.call(env)
|
46
46
|
begin
|
47
|
-
headers["X-View-Runtime"] = (
|
48
|
-
headers["X-DB-Runtime"] = (
|
49
|
-
headers["X-DB-Query-Count"] =
|
47
|
+
headers["X-View-Runtime"] = (view_runtime / 1000).to_s
|
48
|
+
headers["X-DB-Runtime"] = (db_runtime / 1000).to_s
|
49
|
+
headers["X-DB-Query-Count"] = sql_count.to_s
|
50
|
+
|
51
|
+
if html_reponse?(headers)
|
52
|
+
new_body = Rack::Response.new([], status, headers)
|
53
|
+
body.each do |fragment|
|
54
|
+
new_body.write fragment.gsub("</body>", "#{sql_html_overlay}</body>")
|
55
|
+
end
|
56
|
+
body = new_body
|
57
|
+
end
|
50
58
|
rescue => e
|
51
|
-
|
59
|
+
headers["X-Rails-Instrument"] = "Error"
|
52
60
|
end
|
53
61
|
|
54
62
|
[status, headers, body]
|
55
63
|
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def html_reponse?(headers)
|
67
|
+
headers['Content-Type'] =~ /html/
|
68
|
+
end
|
69
|
+
|
70
|
+
def sql_html_overlay
|
71
|
+
%Q{<div style="position: fixed; bottom: 0pt; right: 0pt; cursor: pointer; border-style: solid; border-color: rgb(153, 153, 153); -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 0pt 0px 2px; padding: 5px; border-radius: 10pt 0pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8); color: rgb(119, 119, 119); font-size: 18px;" title="DB query counts / duration (For Development purpose only)">#{sql_count} / #{"%.3f" % db_runtime}</div>}
|
72
|
+
end
|
73
|
+
|
74
|
+
def db_runtime
|
75
|
+
RailsInstrument.data["process_action.action_controller"][:db_runtime]
|
76
|
+
end
|
77
|
+
|
78
|
+
def view_runtime
|
79
|
+
RailsInstrument.data["process_action.action_controller"][:view_runtime]
|
80
|
+
end
|
81
|
+
|
82
|
+
def sql_count
|
83
|
+
RailsInstrument.sql_count
|
84
|
+
end
|
56
85
|
end
|
57
86
|
|
58
87
|
class Engine < ::Rails::Engine #:nodoc:
|
data/readme.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Rails Instrument
|
2
2
|
|
3
3
|
This gem is a middleware which add some instrumentation details like db
|
4
|
-
runtime, view runtime,
|
4
|
+
runtime, view runtime, number of sqls fired on each request in the
|
5
5
|
response headers.
|
6
6
|
|
7
7
|
## Response headers added
|
@@ -20,12 +20,12 @@ Install the latest stable release:
|
|
20
20
|
In Rails >= 3, add it to your Gemfile:
|
21
21
|
|
22
22
|
``` ruby
|
23
|
-
gem '
|
23
|
+
gem 'rails_instrument'
|
24
24
|
```
|
25
25
|
|
26
26
|
|
27
27
|
## TODO
|
28
|
-
* Create chrome extension to show this information inline in the page
|
28
|
+
* <strike>Create chrome extension to show this information inline in the page</strike>. Implemented as html fragment added by the middleware to html response.
|
29
29
|
* Add helper methods for tests. Ex: The number of sqls fired can be
|
30
30
|
asserted. - wip
|
31
|
-
* Add
|
31
|
+
* Add test coverage.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_instrument
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2011-09
|
12
|
+
date: 2011-10-09 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Middleware to show instrumentation information in http headers
|
15
15
|
email:
|