request_profiler 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +2 -3
- data/README.rdoc +56 -1
- data/lib/rack/request_profiler.rb +14 -5
- data/lib/request_profiler/version.rb +1 -1
- metadata +73 -87
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a87c32c91aecffaf54d91f56d16170a083452c5d
|
4
|
+
data.tar.gz: 636ef8a135fe4a2a18b84cde713581055213c609
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a89afe3801f9d175b08a19751293e2aa5f39630ff1bb9d36df59c1d5b7f3b8419443d9a5d08516739f57cbc6a850833041ccd144d910f958bc4be9962fc79ba3
|
7
|
+
data.tar.gz: 4626155ead14c5f1f66bc301ee57a38e11948ab89382cd457f160d5a919076d4969cfef906a158c5b0e7300443e15179bd8d758f517511fae38ee0113c66ee56
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
request_profiler (0.0.
|
4
|
+
request_profiler (0.0.3)
|
5
5
|
ruby-prof
|
6
6
|
|
7
7
|
GEM
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
rack-test (0.5.6)
|
14
14
|
rack (>= 1.0)
|
15
15
|
rake (0.8.7)
|
16
|
-
ruby-prof (0.
|
16
|
+
ruby-prof (0.13.0)
|
17
17
|
sinatra (1.1.0)
|
18
18
|
rack (~> 1.1)
|
19
19
|
tilt (~> 1.1)
|
@@ -26,5 +26,4 @@ DEPENDENCIES
|
|
26
26
|
mocha
|
27
27
|
rack-test
|
28
28
|
request_profiler!
|
29
|
-
ruby-prof
|
30
29
|
sinatra
|
data/README.rdoc
CHANGED
@@ -1,3 +1,58 @@
|
|
1
1
|
= Request Profiler
|
2
2
|
|
3
|
-
|
3
|
+
+request_profiler+ is a rack middleware that allows you to profile
|
4
|
+
rack requests using {ruby-prof}[https://github.com/rdp/ruby-prof]. It
|
5
|
+
sits out of the way until it's triggered using a specific request
|
6
|
+
parameter. Once triggered, it will profile the request and dump a log
|
7
|
+
file.
|
8
|
+
|
9
|
+
== Setup
|
10
|
+
|
11
|
+
After the gem is installed, it's used in the same way any rack
|
12
|
+
middleware is set up. In Rails, you'd probably want to do something
|
13
|
+
like this:
|
14
|
+
|
15
|
+
config.middleware.use "Rack::RequestProfiler"
|
16
|
+
|
17
|
+
+request_profiler+ takes a few optional parameters:
|
18
|
+
|
19
|
+
:printer:: the <tt>ruby-prof</tt> printer to use. Defaults to
|
20
|
+
<tt>RubyProf::GraphPrinter</tt>.
|
21
|
+
|
22
|
+
:exclude:: a list of regexes (like <tt>[/Integer#times]</tt>) that
|
23
|
+
will not appear in the profile log. This is most commonly
|
24
|
+
used for methods that take a block, where you don't care
|
25
|
+
how much time was spent in the method itself.
|
26
|
+
|
27
|
+
:path:: the path to write the log files to. If +request_profiler+ is
|
28
|
+
running under Rails, this defaults to
|
29
|
+
<tt>Rails.root/tmp/performance</tt>, otherwise it defaults to
|
30
|
+
<tt>$TMPDIR/performance</tt>.
|
31
|
+
|
32
|
+
== Using +request_profiler+
|
33
|
+
|
34
|
+
When you get to the point where you'd like to profile a request, you
|
35
|
+
just add <tt>profile_request=true</tt> to the end of your request's query
|
36
|
+
string. By default, this will use the <tt>RubyProf::PROCESS_TIME</tt>
|
37
|
+
profiler. If you'd like to use a different profiler, you can specify
|
38
|
+
the profiler class instead of +true+ in the query string. For example,
|
39
|
+
|
40
|
+
profile_request=memory
|
41
|
+
|
42
|
+
will use the <tt>RubyProf::MEMORY</tt> profiler. Note that the
|
43
|
+
profilers other than +PROCESS_TIME+ and +WALL_TIME+ require a patched
|
44
|
+
ruby interpreter, as mentioned in the ruby-prof documentation. REE
|
45
|
+
should work out of the box, but as far as I know, these patches don't
|
46
|
+
yet exist for ruby 1.9.
|
47
|
+
|
48
|
+
== Bugs Under Ruby 1.9.2
|
49
|
+
|
50
|
+
+ruby_prof+ uses a ruby method called +set_trace_func+, which tends to
|
51
|
+
crash under ruby 1.9.2. I have an experimental patch which backports
|
52
|
+
the fix in the 1.9.3 branch to 1.9.2, and adjusts the stack depth
|
53
|
+
threshhold ruby uses, which fixes some other interpreter crashes I was
|
54
|
+
seeing. If you run into similar issues, you should grab the patch
|
55
|
+
located under +patches/set_trace_func_fix192.patch+. With
|
56
|
+
{rvm}[http://rvm.beginrescueend.com/], it's as simple as
|
57
|
+
|
58
|
+
rvm install 1.9.2p0 --patch /path/to/set_trace_func_fix192.patch
|
@@ -9,14 +9,14 @@ module Rack
|
|
9
9
|
|
10
10
|
@path = options[:path]
|
11
11
|
@path ||= Rails.root + 'tmp/performance' if defined?(Rails)
|
12
|
-
@path ||= ::File.join(ENV["TMPDIR"]
|
12
|
+
@path ||= ::File.join((ENV["TMPDIR"] || "/tmp"), 'performance')
|
13
13
|
@path = Pathname(@path)
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
17
|
request = Rack::Request.new(env)
|
18
18
|
mode = profile_mode(request)
|
19
|
-
|
19
|
+
|
20
20
|
if mode
|
21
21
|
::RubyProf.measure_mode = mode
|
22
22
|
::RubyProf.start
|
@@ -27,14 +27,14 @@ module Rack
|
|
27
27
|
result = ::RubyProf.stop
|
28
28
|
write_result(result, request)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
[status, headers, body]
|
32
32
|
end
|
33
33
|
|
34
34
|
def profile_mode(request)
|
35
35
|
mode_string = request.params["profile_request"]
|
36
36
|
if mode_string
|
37
|
-
if mode_string.downcase == "true"
|
37
|
+
if mode_string.downcase == "true" or mode_string == "1"
|
38
38
|
::RubyProf::PROCESS_TIME
|
39
39
|
else
|
40
40
|
::RubyProf.const_get(mode_string.upcase)
|
@@ -63,12 +63,21 @@ module Rack
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
def prefix(printer)
|
67
|
+
case printer
|
68
|
+
when ::RubyProf::CallTreePrinter
|
69
|
+
"callgrind."
|
70
|
+
else
|
71
|
+
""
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
66
75
|
def write_result(result, request)
|
67
76
|
result.eliminate_methods!(@exclusions) if @exclusions
|
68
77
|
printer = @printer.new(result)
|
69
78
|
Dir.mkdir(@path) unless ::File.exists?(@path)
|
70
79
|
url = request.fullpath.gsub(/[?\/]/, '-')
|
71
|
-
filename = "#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}-#{url}.#{format(printer)}"
|
80
|
+
filename = "#{prefix(printer)}#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}-#{url.slice(0, 50)}.#{format(printer)}"
|
72
81
|
::File.open(@path + filename, 'w+') do |f|
|
73
82
|
printer.print(f)
|
74
83
|
end
|
metadata
CHANGED
@@ -1,84 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_profiler
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Justin Weiss
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: ruby-prof
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
31
20
|
type: :runtime
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rack-test
|
35
21
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-test
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
44
34
|
type: :development
|
45
|
-
version_requirements: *id002
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: sinatra
|
48
35
|
prerelease: false
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sinatra
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
57
48
|
type: :development
|
58
|
-
version_requirements: *id003
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: mocha
|
61
49
|
prerelease: false
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
70
62
|
type: :development
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Request Profiler is a Rack middleware that allows optionally profiling
|
70
|
+
requests with ruby-prof.
|
71
|
+
email:
|
74
72
|
- justin@uberweiss.org
|
75
73
|
executables: []
|
76
|
-
|
77
74
|
extensions: []
|
78
|
-
|
79
75
|
extra_rdoc_files: []
|
80
|
-
|
81
|
-
files:
|
76
|
+
files:
|
82
77
|
- .gitignore
|
83
78
|
- Gemfile
|
84
79
|
- Gemfile.lock
|
@@ -92,39 +87,30 @@ files:
|
|
92
87
|
- test/fake_app.rb
|
93
88
|
- test/request_profiler_test.rb
|
94
89
|
- test/test_helper.rb
|
95
|
-
has_rdoc: true
|
96
90
|
homepage: https://github.com/justinweiss/request_profiler
|
97
91
|
licenses: []
|
98
|
-
|
92
|
+
metadata: {}
|
99
93
|
post_install_message:
|
100
94
|
rdoc_options: []
|
101
|
-
|
102
|
-
require_paths:
|
95
|
+
require_paths:
|
103
96
|
- lib
|
104
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
version: "0"
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
120
107
|
requirements: []
|
121
|
-
|
122
108
|
rubyforge_project: request_profiler
|
123
|
-
rubygems_version:
|
109
|
+
rubygems_version: 2.0.6
|
124
110
|
signing_key:
|
125
|
-
specification_version:
|
111
|
+
specification_version: 4
|
126
112
|
summary: Profile Rack requests with ruby-prof
|
127
|
-
test_files:
|
113
|
+
test_files:
|
128
114
|
- test/fake_app.rb
|
129
115
|
- test/request_profiler_test.rb
|
130
116
|
- test/test_helper.rb
|