stopwatch 0.0.3 → 0.0.4
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/.travis.yml +17 -0
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +37 -16
- data/lib/load_speed.rb +15 -5
- data/lib/stopwatch.rb +22 -15
- data/lib/stopwatch/event.rb +21 -0
- data/lib/stopwatch/log.rb +39 -0
- data/lib/stopwatch/version.rb +1 -1
- data/spec/dummy/app/controllers/welcome_controller.rb +5 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/dummy/public/javascripts/test.js +1 -0
- data/spec/integration/stopwatch_spec.rb +6 -1
- metadata +9 -6
- data/lib/stopwatch_event.rb +0 -15
- data/lib/stopwatch_log.rb +0 -36
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
stopwatch (0.0.
|
|
4
|
+
stopwatch (0.0.3)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: http://rubygems.org/
|
|
@@ -33,34 +33,36 @@ GEM
|
|
|
33
33
|
activemodel (= 3.0.7)
|
|
34
34
|
activesupport (= 3.0.7)
|
|
35
35
|
activesupport (3.0.7)
|
|
36
|
+
archive-tar-minitar (0.5.2)
|
|
36
37
|
arel (2.0.10)
|
|
37
38
|
builder (2.1.2)
|
|
38
|
-
capybara (0.
|
|
39
|
-
celerity (>= 0.7.9)
|
|
40
|
-
culerity (>= 0.2.4)
|
|
39
|
+
capybara (1.0.0)
|
|
41
40
|
mime-types (>= 1.16)
|
|
42
41
|
nokogiri (>= 1.3.3)
|
|
43
42
|
rack (>= 1.0.0)
|
|
44
43
|
rack-test (>= 0.5.4)
|
|
45
|
-
selenium-webdriver (
|
|
46
|
-
xpath (~> 0.1.
|
|
47
|
-
celerity (0.8.9)
|
|
44
|
+
selenium-webdriver (~> 0.2.0)
|
|
45
|
+
xpath (~> 0.1.4)
|
|
48
46
|
childprocess (0.1.9)
|
|
49
47
|
ffi (~> 1.0.6)
|
|
50
|
-
|
|
48
|
+
columnize (0.3.4)
|
|
51
49
|
diff-lcs (1.1.2)
|
|
52
50
|
erubis (2.6.6)
|
|
53
51
|
abstract (>= 1.0.0)
|
|
54
52
|
ffi (1.0.9)
|
|
55
53
|
i18n (0.5.0)
|
|
56
|
-
json_pure (1.5.
|
|
54
|
+
json_pure (1.5.3)
|
|
55
|
+
linecache (0.46)
|
|
56
|
+
rbx-require-relative (> 0.0.4)
|
|
57
|
+
linecache19 (0.5.12)
|
|
58
|
+
ruby_core_source (>= 0.1.4)
|
|
57
59
|
mail (2.2.19)
|
|
58
60
|
activesupport (>= 2.3.6)
|
|
59
61
|
i18n (>= 0.4.0)
|
|
60
62
|
mime-types (~> 1.16)
|
|
61
63
|
treetop (~> 1.4.8)
|
|
62
64
|
mime-types (1.16)
|
|
63
|
-
nokogiri (1.
|
|
65
|
+
nokogiri (1.5.0)
|
|
64
66
|
polyglot (0.3.1)
|
|
65
67
|
rack (1.2.3)
|
|
66
68
|
rack-mount (0.6.14)
|
|
@@ -80,23 +82,39 @@ GEM
|
|
|
80
82
|
activesupport (= 3.0.7)
|
|
81
83
|
rake (>= 0.8.7)
|
|
82
84
|
thor (~> 0.14.4)
|
|
83
|
-
rake (0.
|
|
85
|
+
rake (0.9.2)
|
|
86
|
+
rbx-require-relative (0.0.5)
|
|
84
87
|
rspec (2.6.0)
|
|
85
88
|
rspec-core (~> 2.6.0)
|
|
86
89
|
rspec-expectations (~> 2.6.0)
|
|
87
90
|
rspec-mocks (~> 2.6.0)
|
|
88
|
-
rspec-core (2.6.
|
|
91
|
+
rspec-core (2.6.4)
|
|
89
92
|
rspec-expectations (2.6.0)
|
|
90
93
|
diff-lcs (~> 1.1.2)
|
|
91
94
|
rspec-mocks (2.6.0)
|
|
92
|
-
rspec-rails (2.6.
|
|
95
|
+
rspec-rails (2.6.1)
|
|
93
96
|
actionpack (~> 3.0)
|
|
94
97
|
activesupport (~> 3.0)
|
|
95
98
|
railties (~> 3.0)
|
|
96
99
|
rspec (~> 2.6.0)
|
|
100
|
+
ruby-debug (0.10.4)
|
|
101
|
+
columnize (>= 0.1)
|
|
102
|
+
ruby-debug-base (~> 0.10.4.0)
|
|
103
|
+
ruby-debug-base (0.10.4)
|
|
104
|
+
linecache (>= 0.3)
|
|
105
|
+
ruby-debug-base19 (0.11.25)
|
|
106
|
+
columnize (>= 0.3.1)
|
|
107
|
+
linecache19 (>= 0.5.11)
|
|
108
|
+
ruby_core_source (>= 0.1.4)
|
|
109
|
+
ruby-debug19 (0.11.6)
|
|
110
|
+
columnize (>= 0.3.1)
|
|
111
|
+
linecache19 (>= 0.5.11)
|
|
112
|
+
ruby-debug-base19 (>= 0.11.19)
|
|
113
|
+
ruby_core_source (0.1.5)
|
|
114
|
+
archive-tar-minitar (>= 0.5.2)
|
|
97
115
|
rubyzip (0.9.4)
|
|
98
|
-
selenium-webdriver (0.2.
|
|
99
|
-
childprocess (>= 0.1.
|
|
116
|
+
selenium-webdriver (0.2.2)
|
|
117
|
+
childprocess (>= 0.1.9)
|
|
100
118
|
ffi (>= 1.0.7)
|
|
101
119
|
json_pure
|
|
102
120
|
rubyzip
|
|
@@ -104,7 +122,7 @@ GEM
|
|
|
104
122
|
thor (0.14.6)
|
|
105
123
|
treetop (1.4.9)
|
|
106
124
|
polyglot (>= 0.3.1)
|
|
107
|
-
tzinfo (0.3.
|
|
125
|
+
tzinfo (0.3.29)
|
|
108
126
|
xpath (0.1.4)
|
|
109
127
|
nokogiri (~> 1.3)
|
|
110
128
|
|
|
@@ -114,7 +132,10 @@ PLATFORMS
|
|
|
114
132
|
DEPENDENCIES
|
|
115
133
|
capybara
|
|
116
134
|
ffi (= 1.0.9)
|
|
135
|
+
linecache19
|
|
117
136
|
rails (= 3.0.7)
|
|
118
137
|
rspec-rails (>= 2.0.0.beta)
|
|
138
|
+
ruby-debug
|
|
139
|
+
ruby-debug19
|
|
119
140
|
sqlite3
|
|
120
141
|
stopwatch!
|
data/lib/load_speed.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Rack
|
|
|
8
8
|
env.delete("HTTP_IF_NONE_MATCH")
|
|
9
9
|
status, headers, response = @app.call(env)
|
|
10
10
|
|
|
11
|
-
if status == 200
|
|
11
|
+
if status == 200 && headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
|
|
12
12
|
body = ""
|
|
13
13
|
response.each {|part| body << part}
|
|
14
14
|
index = body.rindex("</body>")
|
|
@@ -25,10 +25,12 @@ module Rack
|
|
|
25
25
|
protected
|
|
26
26
|
|
|
27
27
|
def performance_code
|
|
28
|
-
events = "<table><tr><td
|
|
29
|
-
|
|
28
|
+
events = "<table id='performance_table'><tr><td></td><td>duration (ms)</td><td>queries</td></tr>"
|
|
29
|
+
Stopwatch::Log.events.each do |event|
|
|
30
30
|
events << "<tr><td>#{event.template}</td><td>#{event.duration}</td><td>#{event.query_count}</td></tr>"
|
|
31
31
|
end
|
|
32
|
+
event = Stopwatch::Log.event
|
|
33
|
+
events << "<tr><td>#{event.payload[:path]}</td><td>#{event.duration}</td><td>#{Stopwatch::Log.query_count}</td></tr>"
|
|
32
34
|
events << "</table>"
|
|
33
35
|
|
|
34
36
|
html = <<-EOF
|
|
@@ -39,6 +41,7 @@ module Rack
|
|
|
39
41
|
top: 0;
|
|
40
42
|
right: 0;
|
|
41
43
|
height: 25px;
|
|
44
|
+
width: 140px;
|
|
42
45
|
overflow: hidden;
|
|
43
46
|
background-color: #DE7A93;
|
|
44
47
|
color: white;
|
|
@@ -54,10 +57,17 @@ module Rack
|
|
|
54
57
|
width: auto;
|
|
55
58
|
padding-bottom: 10px;
|
|
56
59
|
}
|
|
60
|
+
|
|
61
|
+
table#performance_table {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
table#performance_table td {
|
|
65
|
+
padding-right: 15px;
|
|
66
|
+
}
|
|
57
67
|
</style>
|
|
58
68
|
<div id="performance_code">
|
|
59
|
-
<strong>#{
|
|
60
|
-
<strong>#{
|
|
69
|
+
<strong>#{Stopwatch::Log.event.duration.to_i}</strong> ms
|
|
70
|
+
<strong>#{Stopwatch::Log.query_count}</strong> queries
|
|
61
71
|
#{events}
|
|
62
72
|
</div>
|
|
63
73
|
EOF
|
data/lib/stopwatch.rb
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
require 'load_speed'
|
|
2
|
-
require '
|
|
3
|
-
require '
|
|
2
|
+
require 'stopwatch/log'
|
|
3
|
+
require 'stopwatch/event'
|
|
4
4
|
|
|
5
5
|
module Stopwatch
|
|
6
6
|
class Railtie < Rails::Railtie
|
|
7
7
|
initializer "newplugin.initialize" do |app|
|
|
8
8
|
app.config.middleware.use "Rack::LoadSpeed"
|
|
9
9
|
|
|
10
|
+
# Start processing
|
|
10
11
|
ActiveSupport::Notifications.subscribe "start_processing.action_controller" do |*args|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
Stopwatch::Log.reset_query_count
|
|
13
|
+
Stopwatch::Log.reset_sub_query_count
|
|
14
|
+
Stopwatch::Log.reset_events
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
# Every query
|
|
18
|
+
ActiveSupport::Notifications.subscribe "sql.active_record" do |name, start, finish, id, payload|
|
|
19
|
+
if payload[:name] != "CACHE"
|
|
20
|
+
Stopwatch::Log.increment_query_count
|
|
21
|
+
Stopwatch::Log.increment_sub_query_count
|
|
22
|
+
end
|
|
17
23
|
end
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
# Every partial render
|
|
26
|
+
ActiveSupport::Notifications.subscribe(/render/) do |name, start, finish, id, payload|
|
|
27
|
+
event = ActiveSupport::Notifications::Event.new(name, start, finish, id, payload)
|
|
28
|
+
stopwatch_event = Stopwatch::Event.new(event)
|
|
29
|
+
stopwatch_event.query_count = Stopwatch::Log.sub_query_count
|
|
30
|
+
Stopwatch::Log.events << stopwatch_event
|
|
31
|
+
Stopwatch::Log.reset_sub_query_count
|
|
22
32
|
end
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
stopwatch_event.query_count = StopwatchLog.sub_query_count
|
|
28
|
-
StopwatchLog.events << stopwatch_event
|
|
29
|
-
StopwatchLog.reset_sub_query_count
|
|
34
|
+
# End of processing
|
|
35
|
+
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args|
|
|
36
|
+
Stopwatch::Log.event = ActiveSupport::Notifications::Event.new(*args)
|
|
30
37
|
end
|
|
31
38
|
end
|
|
32
39
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Stopwatch
|
|
2
|
+
class Event
|
|
3
|
+
attr_accessor :query_count
|
|
4
|
+
|
|
5
|
+
def initialize(event)
|
|
6
|
+
@event = event
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def template
|
|
10
|
+
if @event.payload[:virtual_path]
|
|
11
|
+
@event.payload[:virtual_path]
|
|
12
|
+
else
|
|
13
|
+
@event.payload[:identifier].gsub(/.*\/app\/views\//, "")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def duration
|
|
18
|
+
@event.duration.round(2)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Stopwatch
|
|
2
|
+
class Log
|
|
3
|
+
@@query_count = 0
|
|
4
|
+
@@sub_query_count = 0
|
|
5
|
+
@@events = []
|
|
6
|
+
|
|
7
|
+
cattr_accessor :event
|
|
8
|
+
cattr_accessor :events
|
|
9
|
+
cattr_accessor :query_count
|
|
10
|
+
|
|
11
|
+
def self.query_count
|
|
12
|
+
@@query_count
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.sub_query_count
|
|
16
|
+
@@sub_query_count
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.reset_query_count
|
|
20
|
+
@@query_count = 0
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.reset_sub_query_count
|
|
24
|
+
@@sub_query_count = 0
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.increment_query_count
|
|
28
|
+
@@query_count += 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.increment_sub_query_count
|
|
32
|
+
@@sub_query_count += 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.reset_events
|
|
36
|
+
@@events = []
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/stopwatch/version.rb
CHANGED
data/spec/dummy/config/routes.rb
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
str = "<body> this is a test</body>";
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Navigation" do
|
|
4
|
-
include Capybara
|
|
4
|
+
include Capybara::DSL
|
|
5
5
|
|
|
6
6
|
it "renders the stopwatch box" do
|
|
7
7
|
visit "/"
|
|
8
8
|
page.should have_css("#performance_code")
|
|
9
9
|
end
|
|
10
|
+
|
|
11
|
+
it "does not insert html" do
|
|
12
|
+
visit "/javascript_test"
|
|
13
|
+
page.should_not have_css("#performance_code")
|
|
14
|
+
end
|
|
10
15
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stopwatch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Mark Mulder
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-
|
|
18
|
+
date: 2011-11-14 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies: []
|
|
21
21
|
|
|
@@ -30,6 +30,7 @@ extra_rdoc_files: []
|
|
|
30
30
|
|
|
31
31
|
files:
|
|
32
32
|
- .gitignore
|
|
33
|
+
- .travis.yml
|
|
33
34
|
- CHANGELOG
|
|
34
35
|
- Gemfile
|
|
35
36
|
- Gemfile.lock
|
|
@@ -37,9 +38,9 @@ files:
|
|
|
37
38
|
- Rakefile
|
|
38
39
|
- lib/load_speed.rb
|
|
39
40
|
- lib/stopwatch.rb
|
|
41
|
+
- lib/stopwatch/event.rb
|
|
42
|
+
- lib/stopwatch/log.rb
|
|
40
43
|
- lib/stopwatch/version.rb
|
|
41
|
-
- lib/stopwatch_event.rb
|
|
42
|
-
- lib/stopwatch_log.rb
|
|
43
44
|
- spec/dummy/Rakefile
|
|
44
45
|
- spec/dummy/app/controllers/application_controller.rb
|
|
45
46
|
- spec/dummy/app/controllers/welcome_controller.rb
|
|
@@ -66,6 +67,7 @@ files:
|
|
|
66
67
|
- spec/dummy/public/422.html
|
|
67
68
|
- spec/dummy/public/500.html
|
|
68
69
|
- spec/dummy/public/favicon.ico
|
|
70
|
+
- spec/dummy/public/javascripts/test.js
|
|
69
71
|
- spec/dummy/public/stylesheets/.gitkeep
|
|
70
72
|
- spec/dummy/script/rails
|
|
71
73
|
- spec/integration/stopwatch_spec.rb
|
|
@@ -133,6 +135,7 @@ test_files:
|
|
|
133
135
|
- spec/dummy/public/422.html
|
|
134
136
|
- spec/dummy/public/500.html
|
|
135
137
|
- spec/dummy/public/favicon.ico
|
|
138
|
+
- spec/dummy/public/javascripts/test.js
|
|
136
139
|
- spec/dummy/public/stylesheets/.gitkeep
|
|
137
140
|
- spec/dummy/script/rails
|
|
138
141
|
- spec/integration/stopwatch_spec.rb
|
data/lib/stopwatch_event.rb
DELETED
data/lib/stopwatch_log.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
class StopwatchLog
|
|
2
|
-
@@query_count = 0
|
|
3
|
-
@@sub_query_count = 0
|
|
4
|
-
@@events = []
|
|
5
|
-
|
|
6
|
-
cattr_accessor :event
|
|
7
|
-
cattr_accessor :events
|
|
8
|
-
|
|
9
|
-
def self.query_count
|
|
10
|
-
@@query_count
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.sub_query_count
|
|
14
|
-
@@sub_query_count
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.reset_query_count
|
|
18
|
-
@@query_count = 0
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.reset_sub_query_count
|
|
22
|
-
@@sub_query_count = 0
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def self.increment_query_count
|
|
26
|
-
@@query_count += 1
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def self.increment_sub_query_count
|
|
30
|
-
@@sub_query_count += 1
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.reset_events
|
|
34
|
-
@@events = []
|
|
35
|
-
end
|
|
36
|
-
end
|