rack-perftools_profiler 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/rack/perftools_profiler/profiler.rb +34 -22
- data/lib/rack/perftools_profiler/version.rb +1 -1
- data/rack-perftools_profiler.gemspec +1 -1
- data/test/single_request_profiling_test.rb +6 -3
- data/test/test_helper.rb +1 -1
- metadata +104 -119
data/README.md
CHANGED
@@ -98,29 +98,8 @@ module Rack::PerftoolsProfiler
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def data(options = {})
|
101
|
-
printer = (options.fetch('printer') {@printer}).to_sym
|
102
|
-
ignore = options.fetch('ignore') { nil }
|
103
|
-
focus = options.fetch('focus') { nil }
|
104
|
-
nodecount = options.fetch('nodecount') { nil }
|
105
|
-
nodefraction = options.fetch('nodefraction') { nil }
|
106
101
|
if ::File.exists?(PROFILING_DATA_FILE)
|
107
|
-
|
108
|
-
args << "--ignore=#{ignore}" if ignore
|
109
|
-
args << "--focus=#{focus}" if focus
|
110
|
-
args << "--nodecount=#{nodecount}" if nodecount
|
111
|
-
args << "--nodefraction=#{nodefraction}" if nodefraction
|
112
|
-
args << PROFILING_DATA_FILE
|
113
|
-
cmd = ["pprof.rb"] + args
|
114
|
-
cmd = ["bundle", "exec"] + cmd if @bundler
|
115
|
-
|
116
|
-
stdout, stderr, status = Dir.chdir(@gemfile_dir) { run(*cmd) }
|
117
|
-
if status!=0
|
118
|
-
raise ProfilingError.new("Running the command '#{cmd.join(" ")}' exited with status #{status}", stderr)
|
119
|
-
elsif stdout.length == 0 && stderr.length > 0
|
120
|
-
raise ProfilingError.new("Running the command '#{cmd.join(" ")}' failed to generate a file", stderr)
|
121
|
-
else
|
122
|
-
[printer, stdout]
|
123
|
-
end
|
102
|
+
data_from_file(options)
|
124
103
|
else
|
125
104
|
[:none, nil]
|
126
105
|
end
|
@@ -128,6 +107,39 @@ module Rack::PerftoolsProfiler
|
|
128
107
|
|
129
108
|
private
|
130
109
|
|
110
|
+
def data_from_file(options)
|
111
|
+
printer = options.fetch('printer') {@printer}.to_sym
|
112
|
+
|
113
|
+
command_array = build_command(printer, options)
|
114
|
+
stdout, stderr, status = Dir.chdir(@gemfile_dir) { run(*command_array) }
|
115
|
+
|
116
|
+
full_command = command_array.join(" ")
|
117
|
+
if status!=0
|
118
|
+
raise ProfilingError.new("Running the command '#{full_command}' exited with status #{status}", stderr)
|
119
|
+
elsif stdout.length == 0 && stderr.length > 0
|
120
|
+
raise ProfilingError.new("Running the command '#{full_command}' failed to generate a file", stderr)
|
121
|
+
else
|
122
|
+
[printer, stdout]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def build_command(printer, options)
|
127
|
+
ignore = options.fetch('ignore') { nil }
|
128
|
+
focus = options.fetch('focus') { nil }
|
129
|
+
nodecount = options.fetch('nodecount') { nil }
|
130
|
+
nodefraction = options.fetch('nodefraction') { nil }
|
131
|
+
|
132
|
+
args = ["--#{printer}"]
|
133
|
+
args << "--ignore=#{ignore}" if ignore
|
134
|
+
args << "--focus=#{focus}" if focus
|
135
|
+
args << "--nodecount=#{nodecount}" if nodecount
|
136
|
+
args << "--nodefraction=#{nodefraction}" if nodefraction
|
137
|
+
args << PROFILING_DATA_FILE
|
138
|
+
cmd = ["pprof.rb"] + args
|
139
|
+
cmd = ["bundle", "exec"] + cmd if @bundler
|
140
|
+
cmd
|
141
|
+
end
|
142
|
+
|
131
143
|
def run(*command)
|
132
144
|
out = err = ""
|
133
145
|
pid = nil
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_dependency 'perftools.rb', '~> 2.0.
|
20
|
+
s.add_dependency 'perftools.rb', '~> 2.0.1'
|
21
21
|
s.add_dependency 'rack', '~> 1.0'
|
22
22
|
s.add_dependency 'open4', '~> 1.0'
|
23
23
|
s.add_development_dependency 'rack', '~> 1.1'
|
@@ -224,17 +224,20 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
|
|
224
224
|
context 'when using the text printer' do
|
225
225
|
|
226
226
|
should 'return profiling data' do
|
227
|
-
|
227
|
+
status, _, body = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'text').call(@profiled_request_env)
|
228
|
+
assert_ok status, body
|
228
229
|
assert_match(/Total: \d+ samples/, RackResponseBody.new(body).to_s)
|
229
230
|
end
|
230
231
|
|
231
232
|
should 'have Content-Type text/plain' do
|
232
|
-
|
233
|
+
status, headers, body = Rack::PerftoolsProfiler.new(@app, :default_printer => 'text').call(@profiled_request_env)
|
234
|
+
assert_ok status, body
|
233
235
|
assert_equal "text/plain", headers['Content-Type']
|
234
236
|
end
|
235
237
|
|
236
238
|
should 'have Content-Length' do
|
237
|
-
|
239
|
+
status, headers, body = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'text').call(@profiled_request_env)
|
240
|
+
assert_ok status, body
|
238
241
|
assert (headers.fetch('Content-Length').to_i > 500)
|
239
242
|
end
|
240
243
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,140 +1,135 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-perftools_profiler
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 0
|
10
|
-
version: 0.6.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ben Brinckerhoff
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: perftools.rb
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
- 0
|
34
|
-
version: 2.0.0
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.1
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rack
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
41
33
|
none: false
|
42
|
-
requirements:
|
34
|
+
requirements:
|
43
35
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 1
|
48
|
-
- 0
|
49
|
-
version: "1.0"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.0'
|
50
38
|
type: :runtime
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: open4
|
54
39
|
prerelease: false
|
55
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
41
|
none: false
|
57
|
-
requirements:
|
42
|
+
requirements:
|
58
43
|
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: open4
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
65
54
|
type: :runtime
|
66
|
-
version_requirements: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: rack
|
69
55
|
prerelease: false
|
70
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
57
|
none: false
|
72
|
-
requirements:
|
58
|
+
requirements:
|
73
59
|
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.1'
|
80
70
|
type: :development
|
81
|
-
version_requirements: *id004
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: shoulda
|
84
71
|
prerelease: false
|
85
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
73
|
none: false
|
87
|
-
requirements:
|
74
|
+
requirements:
|
88
75
|
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.1'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: shoulda
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.10'
|
95
86
|
type: :development
|
96
|
-
version_requirements: *id005
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: mocha
|
99
87
|
prerelease: false
|
100
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
89
|
none: false
|
102
|
-
requirements:
|
90
|
+
requirements:
|
103
91
|
- - ~>
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.10'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: mocha
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.9'
|
110
102
|
type: :development
|
111
|
-
version_requirements: *id006
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: rake
|
114
103
|
prerelease: false
|
115
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
116
105
|
none: false
|
117
|
-
requirements:
|
106
|
+
requirements:
|
118
107
|
- - ~>
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.9'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
125
117
|
version: 0.9.2
|
126
118
|
type: :development
|
127
|
-
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.9.2
|
128
126
|
description: Middleware for profiling Rack-compatible apps using perftools.rb
|
129
|
-
email:
|
127
|
+
email:
|
130
128
|
- ben@bbrinck.com
|
131
129
|
executables: []
|
132
|
-
|
133
130
|
extensions: []
|
134
|
-
|
135
131
|
extra_rdoc_files: []
|
136
|
-
|
137
|
-
files:
|
132
|
+
files:
|
138
133
|
- .document
|
139
134
|
- .gitignore
|
140
135
|
- Gemfile
|
@@ -161,41 +156,31 @@ files:
|
|
161
156
|
- test/rack-perftools-profiler_test.rb
|
162
157
|
- test/single_request_profiling_test.rb
|
163
158
|
- test/test_helper.rb
|
164
|
-
has_rdoc: true
|
165
159
|
homepage: http://github.com/bhb/rack-perftools_profiler
|
166
160
|
licenses: []
|
167
|
-
|
168
161
|
post_install_message:
|
169
162
|
rdoc_options: []
|
170
|
-
|
171
|
-
require_paths:
|
163
|
+
require_paths:
|
172
164
|
- lib
|
173
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
166
|
none: false
|
175
|
-
requirements:
|
176
|
-
- -
|
177
|
-
- !ruby/object:Gem::Version
|
178
|
-
|
179
|
-
|
180
|
-
- 0
|
181
|
-
version: "0"
|
182
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
172
|
none: false
|
184
|
-
requirements:
|
185
|
-
- -
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
|
188
|
-
segments:
|
189
|
-
- 0
|
190
|
-
version: "0"
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
191
177
|
requirements: []
|
192
|
-
|
193
178
|
rubyforge_project: rack-perftools_profiler
|
194
|
-
rubygems_version: 1.
|
179
|
+
rubygems_version: 1.8.23
|
195
180
|
signing_key:
|
196
181
|
specification_version: 3
|
197
182
|
summary: Middleware for profiling Rack-compatible apps using perftools.rb
|
198
|
-
test_files:
|
183
|
+
test_files:
|
199
184
|
- test/multiple_request_profiling_test.rb
|
200
185
|
- test/rack-perftools-profiler_test.rb
|
201
186
|
- test/single_request_profiling_test.rb
|