miniprofiler 0.1.7.1
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/.gitignore +4 -0
- data/CHANGELOG +32 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +64 -0
- data/README.md +110 -0
- data/Rakefile +40 -0
- data/autotest/discover.rb +2 -0
- data/lib/mini_profiler/body_add_proxy.rb +45 -0
- data/lib/mini_profiler/client_timer_struct.rb +76 -0
- data/lib/mini_profiler/config.rb +52 -0
- data/lib/mini_profiler/context.rb +10 -0
- data/lib/mini_profiler/page_timer_struct.rb +53 -0
- data/lib/mini_profiler/profiler.rb +405 -0
- data/lib/mini_profiler/profiling_methods.rb +73 -0
- data/lib/mini_profiler/request_timer_struct.rb +96 -0
- data/lib/mini_profiler/sql_timer_struct.rb +48 -0
- data/lib/mini_profiler/storage/abstract_store.rb +27 -0
- data/lib/mini_profiler/storage/file_store.rb +108 -0
- data/lib/mini_profiler/storage/memory_store.rb +68 -0
- data/lib/mini_profiler/storage/redis_store.rb +44 -0
- data/lib/mini_profiler/timer_struct.rb +31 -0
- data/lib/mini_profiler_rails/railtie.rb +84 -0
- data/lib/patches/sql_patches.rb +185 -0
- data/lib/rack-mini-profiler.rb +6 -0
- data/rack-mini-profiler.gemspec +23 -0
- data/spec/components/body_add_proxy_spec.rb +90 -0
- data/spec/components/client_timer_struct_spec.rb +165 -0
- data/spec/components/file_store_spec.rb +47 -0
- data/spec/components/memory_store_spec.rb +40 -0
- data/spec/components/page_timer_struct_spec.rb +33 -0
- data/spec/components/profiler_spec.rb +126 -0
- data/spec/components/redis_store_spec.rb +44 -0
- data/spec/components/request_timer_struct_spec.rb +148 -0
- data/spec/components/sql_timer_struct_spec.rb +63 -0
- data/spec/components/timer_struct_spec.rb +47 -0
- data/spec/fixtures/simple_client_request.yml +17 -0
- data/spec/fixtures/weird_client_request.yml +13 -0
- data/spec/integration/mini_profiler_spec.rb +142 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/expand_each_to_matcher.rb +8 -0
- data/test_old/config.ru +41 -0
- metadata +155 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mini_profiler/timer_struct'
|
3
|
+
|
4
|
+
describe Rack::MiniProfiler::TimerStruct do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@timer = Rack::MiniProfiler::TimerStruct.new('Mini' => 'Profiler')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'has the the Mini attribute' do
|
11
|
+
@timer['Mini'].should == 'Profiler'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'allows us to set any attribute we want' do
|
15
|
+
@timer['Hello'] = 'World'
|
16
|
+
@timer['Hello'].should == 'World'
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'to_json' do
|
20
|
+
|
21
|
+
before do
|
22
|
+
@timer['IceIce'] = 'Baby'
|
23
|
+
@json = @timer.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has a JSON value' do
|
27
|
+
@json.should_not be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'deserialized' do
|
31
|
+
|
32
|
+
before do
|
33
|
+
@deserialized = ::JSON.parse(@json)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'produces a hash' do
|
37
|
+
@deserialized.is_a?(Hash).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has the element we added' do
|
41
|
+
@deserialized['IceIce'].should == 'Baby'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
rack.request.form_hash:
|
3
|
+
clientPerformance:
|
4
|
+
navigation:
|
5
|
+
redirectCount: 1
|
6
|
+
timing:
|
7
|
+
navigationStart: 1334245954
|
8
|
+
navigationEnd: 1334245970
|
9
|
+
simpleStart: 1334245955
|
10
|
+
simpleEnd: 1334245965
|
11
|
+
clientProbes:
|
12
|
+
0:
|
13
|
+
d: 1334245970
|
14
|
+
n: bob.js
|
15
|
+
1:
|
16
|
+
d: 1334245976
|
17
|
+
n: bob.js
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
rack.request.form_hash:
|
3
|
+
clientPerformance:
|
4
|
+
navigation:
|
5
|
+
redirectCount: 99
|
6
|
+
timing:
|
7
|
+
navigationStart: 1334245954
|
8
|
+
navigationEnd: 1334245970
|
9
|
+
weirdStart: 1334245965
|
10
|
+
weirdEnd: 1334245955
|
11
|
+
previousStart: 1334245950
|
12
|
+
previousEnd: 1334245952
|
13
|
+
differentFormat: 1334245955
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack-mini-profiler'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
describe Rack::MiniProfiler do
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
@app ||= Rack::Builder.new {
|
10
|
+
use Rack::MiniProfiler
|
11
|
+
map '/path2/a' do
|
12
|
+
run lambda { |env| [200, {'Content-Type' => 'text/html'}, '<h1>path1</h1>'] }
|
13
|
+
end
|
14
|
+
map '/path1/a' do
|
15
|
+
run lambda { |env| [200, {'Content-Type' => 'text/html'}, '<h1>path2</h1>'] }
|
16
|
+
end
|
17
|
+
map '/post' do
|
18
|
+
run lambda { |env| [302, {'Content-Type' => 'text/html'}, '<h1>POST</h1>'] }
|
19
|
+
end
|
20
|
+
map '/html' do
|
21
|
+
run lambda { |env| [200, {'Content-Type' => 'text/html'}, '<h1>Hi</h1>'] }
|
22
|
+
end
|
23
|
+
map '/db' do
|
24
|
+
run lambda { |env|
|
25
|
+
::Rack::MiniProfiler.record_sql("I want to be, in a db", 10)
|
26
|
+
[200, {'Content-Type' => 'text/html'}, '<h1>Hi+db</h1>']
|
27
|
+
}
|
28
|
+
end
|
29
|
+
map '/3ms' do
|
30
|
+
run lambda { |env|
|
31
|
+
sleep(0.003)
|
32
|
+
[200, {'Content-Type' => 'text/html'}, '<h1>Hi</h1>']
|
33
|
+
}
|
34
|
+
end
|
35
|
+
map '/whitelisted' do
|
36
|
+
run lambda { |env|
|
37
|
+
Rack::MiniProfiler.authorize_request
|
38
|
+
[200, {'Content-Type' => 'text/html'}, '<h1>path1</h1>']
|
39
|
+
}
|
40
|
+
end
|
41
|
+
}.to_app
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
Rack::MiniProfiler.reset_config
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'with a valid request' do
|
49
|
+
|
50
|
+
before do
|
51
|
+
get '/html'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns 200' do
|
55
|
+
last_response.should be_ok
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'has the X-MiniProfiler-Ids header' do
|
59
|
+
last_response.headers.has_key?('X-MiniProfiler-Ids').should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'has only one X-MiniProfiler-Ids header' do
|
63
|
+
h = last_response.headers['X-MiniProfiler-Ids']
|
64
|
+
ids = ::JSON.parse(h)
|
65
|
+
ids.count.should == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'has the JS in the body' do
|
69
|
+
last_response.body.include?('MiniProfiler.init').should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'configuration' do
|
75
|
+
it "doesn't add MiniProfiler if the callback fails" do
|
76
|
+
Rack::MiniProfiler.config.pre_authorize_cb = lambda {|env| false }
|
77
|
+
get '/html'
|
78
|
+
last_response.headers.has_key?('X-MiniProfiler-Ids').should be_false
|
79
|
+
end
|
80
|
+
|
81
|
+
it "skips paths listed" do
|
82
|
+
Rack::MiniProfiler.config.skip_paths = ['/path/', '/path2/']
|
83
|
+
get '/path2/a'
|
84
|
+
last_response.headers.has_key?('X-MiniProfiler-Ids').should be_false
|
85
|
+
get '/path1/a'
|
86
|
+
last_response.headers.has_key?('X-MiniProfiler-Ids').should be_true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def load_prof(response)
|
91
|
+
id = response.headers['X-MiniProfiler-Ids']
|
92
|
+
id = ::JSON.parse(id)[0]
|
93
|
+
Rack::MiniProfiler.config.storage_instance.load(id)
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'special options' do
|
97
|
+
it "omits db backtrace if requested" do
|
98
|
+
get '/db?pp=no-backtrace'
|
99
|
+
prof = load_prof(last_response)
|
100
|
+
stack = prof["Root"]["SqlTimings"][0]["StackTraceSnippet"]
|
101
|
+
stack.should be_nil
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'POST followed by GET' do
|
107
|
+
it "should end up with 2 ids" do
|
108
|
+
post '/post'
|
109
|
+
get '/html'
|
110
|
+
|
111
|
+
ids = last_response.headers['X-MiniProfiler-Ids']
|
112
|
+
::JSON.parse(ids).length.should == 2
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'sampling mode' do
|
117
|
+
it "should sample stack traces if requested" do
|
118
|
+
get '/3ms?pp=sample'
|
119
|
+
last_response["Content-Type"].should == 'text/plain'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
describe 'authorization mode whitelist' do
|
125
|
+
before do
|
126
|
+
Rack::MiniProfiler.config.authorization_mode = :whitelist
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should ban requests that are not whitelisted" do
|
130
|
+
get '/html'
|
131
|
+
last_response.headers['X-MiniProfiler-Ids'].should be_nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should allow requests that are whitelisted" do
|
135
|
+
set_cookie("__profilin=stylin")
|
136
|
+
get '/whitelisted'
|
137
|
+
last_response.headers['X-MiniProfiler-Ids'].should_not be_nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.color_enabled = true
|
5
|
+
end
|
6
|
+
|
7
|
+
class Time
|
8
|
+
class << self
|
9
|
+
unless method_defined? :old_new
|
10
|
+
alias_method :old_new, :new
|
11
|
+
alias_method :old_now, :now
|
12
|
+
|
13
|
+
def new
|
14
|
+
@now || old_new
|
15
|
+
end
|
16
|
+
|
17
|
+
def now
|
18
|
+
@now || old_now
|
19
|
+
end
|
20
|
+
|
21
|
+
def now=(v)
|
22
|
+
@now = v
|
23
|
+
end
|
24
|
+
|
25
|
+
def back_to_normal
|
26
|
+
@now = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test_old/config.ru
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#! rackup -
|
2
|
+
#\ -w -p 8080
|
3
|
+
require 'active_support/inflector' # see https://code.google.com/p/ruby-sequel/issues/detail?id=329
|
4
|
+
require 'sequel'
|
5
|
+
require File.expand_path('../lib/rack-mini-profiler', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'logger'
|
8
|
+
use Rack::MiniProfiler
|
9
|
+
options = {}
|
10
|
+
options[:logger] = Logger.new(STDOUT)
|
11
|
+
DB = Sequel.connect("mysql2://sveg:svegsveg@localhost/sveg_development",
|
12
|
+
options)
|
13
|
+
|
14
|
+
app = proc do |env|
|
15
|
+
sleep(0.1)
|
16
|
+
env['profiler.mini'].benchmark(env, "sleep0.2") do
|
17
|
+
sleep(0.2)
|
18
|
+
end
|
19
|
+
env['profiler.mini'].benchmark(env, 'sleep0.1') do
|
20
|
+
sleep(0.1)
|
21
|
+
env['profiler.mini'].benchmark(env, 'sleep0.01') do
|
22
|
+
sleep(0.01)
|
23
|
+
env['profiler.mini'].benchmark(env, 'sleep0.001') do
|
24
|
+
sleep(0.001)
|
25
|
+
DB.fetch('SHOW TABLES') do |row|
|
26
|
+
puts row
|
27
|
+
end
|
28
|
+
end
|
29
|
+
env['profiler.mini'].benchmark(env, 'litl sql') do
|
30
|
+
DB.fetch('select * from auth_logins') do |row|
|
31
|
+
puts row
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
[ 200, {'Content-Type' => 'text/html'}, ["<h1>This is Rack::MiniProfiler test"] ]
|
37
|
+
end
|
38
|
+
|
39
|
+
puts "Rack::MiniProfiler test"
|
40
|
+
puts "http://localhost:8080/mini-profiler"
|
41
|
+
run app
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: miniprofiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aleks Totic
|
9
|
+
- Sam Saffron
|
10
|
+
- Robin Ward
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-07-20 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rack
|
18
|
+
requirement: &2152846940 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.1.3
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2152846940
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: &2152846480 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2152846480
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rack-test
|
40
|
+
requirement: &2152845720 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *2152845720
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: activerecord
|
51
|
+
requirement: &2152845140 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.0'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *2152845140
|
60
|
+
description: Page loading speed displayed on every page. Optimize while you develop,
|
61
|
+
performance is a feature.
|
62
|
+
email: sam.saffron@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files:
|
66
|
+
- README.md
|
67
|
+
- CHANGELOG
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- CHANGELOG
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- autotest/discover.rb
|
76
|
+
- lib/mini_profiler/body_add_proxy.rb
|
77
|
+
- lib/mini_profiler/client_timer_struct.rb
|
78
|
+
- lib/mini_profiler/config.rb
|
79
|
+
- lib/mini_profiler/context.rb
|
80
|
+
- lib/mini_profiler/page_timer_struct.rb
|
81
|
+
- lib/mini_profiler/profiler.rb
|
82
|
+
- lib/mini_profiler/profiling_methods.rb
|
83
|
+
- lib/mini_profiler/request_timer_struct.rb
|
84
|
+
- lib/mini_profiler/sql_timer_struct.rb
|
85
|
+
- lib/mini_profiler/storage/abstract_store.rb
|
86
|
+
- lib/mini_profiler/storage/file_store.rb
|
87
|
+
- lib/mini_profiler/storage/memory_store.rb
|
88
|
+
- lib/mini_profiler/storage/redis_store.rb
|
89
|
+
- lib/mini_profiler/timer_struct.rb
|
90
|
+
- lib/mini_profiler_rails/railtie.rb
|
91
|
+
- lib/patches/sql_patches.rb
|
92
|
+
- lib/rack-mini-profiler.rb
|
93
|
+
- rack-mini-profiler.gemspec
|
94
|
+
- spec/components/body_add_proxy_spec.rb
|
95
|
+
- spec/components/client_timer_struct_spec.rb
|
96
|
+
- spec/components/file_store_spec.rb
|
97
|
+
- spec/components/memory_store_spec.rb
|
98
|
+
- spec/components/page_timer_struct_spec.rb
|
99
|
+
- spec/components/profiler_spec.rb
|
100
|
+
- spec/components/redis_store_spec.rb
|
101
|
+
- spec/components/request_timer_struct_spec.rb
|
102
|
+
- spec/components/sql_timer_struct_spec.rb
|
103
|
+
- spec/components/timer_struct_spec.rb
|
104
|
+
- spec/fixtures/simple_client_request.yml
|
105
|
+
- spec/fixtures/weird_client_request.yml
|
106
|
+
- spec/integration/mini_profiler_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/support/expand_each_to_matcher.rb
|
109
|
+
- test_old/config.ru
|
110
|
+
homepage: http://miniprofiler.com
|
111
|
+
licenses: []
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: 2154905342144575442
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
hash: 2154905342144575442
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.17
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Profiles loading speed for rack applications.
|
140
|
+
test_files:
|
141
|
+
- spec/components/body_add_proxy_spec.rb
|
142
|
+
- spec/components/client_timer_struct_spec.rb
|
143
|
+
- spec/components/file_store_spec.rb
|
144
|
+
- spec/components/memory_store_spec.rb
|
145
|
+
- spec/components/page_timer_struct_spec.rb
|
146
|
+
- spec/components/profiler_spec.rb
|
147
|
+
- spec/components/redis_store_spec.rb
|
148
|
+
- spec/components/request_timer_struct_spec.rb
|
149
|
+
- spec/components/sql_timer_struct_spec.rb
|
150
|
+
- spec/components/timer_struct_spec.rb
|
151
|
+
- spec/fixtures/simple_client_request.yml
|
152
|
+
- spec/fixtures/weird_client_request.yml
|
153
|
+
- spec/integration/mini_profiler_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- spec/support/expand_each_to_matcher.rb
|