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 CHANGED
@@ -10,7 +10,7 @@ Gemfile:
10
10
 
11
11
  gem 'rack-perftools_profiler', :require => 'rack/perftools_profiler'
12
12
 
13
- config/environment.rb:
13
+ config/application.rb:
14
14
 
15
15
  config.middleware.use ::Rack::PerftoolsProfiler, :default_printer => 'gif', :bundler => true
16
16
 
@@ -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
- args = ["--#{printer}"]
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module PerftoolsProfiler
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
@@ -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.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
- _, _, body = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'text').call(@profiled_request_env)
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
- _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'text').call(@profiled_request_env)
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
- _, headers, _ = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'text').call(@profiled_request_env)
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
 
@@ -20,7 +20,7 @@ end
20
20
  ITERATIONS = case RUBY_VERSION
21
21
  # Ruby 1.9.x is so fast that we need to add extra iterations
22
22
  # to get profiling data
23
- when /1\.9\../
23
+ when /1\.9\../, /2\.0\../
24
24
  350_000
25
25
  else
26
26
  35_000
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
- hash: 7
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
- date: 2012-03-26 00:00:00 +01:00
19
- default_executable:
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
- prerelease: false
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
- hash: 15
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
- requirement: &id002 !ruby/object:Gem::Requirement
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
- hash: 15
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
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
56
41
  none: false
57
- requirements:
42
+ requirements:
58
43
  - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 15
61
- segments:
62
- - 1
63
- - 0
64
- version: "1.0"
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
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
71
57
  none: false
72
- requirements:
58
+ requirements:
73
59
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 13
76
- segments:
77
- - 1
78
- - 1
79
- version: "1.1"
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
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
86
73
  none: false
87
- requirements:
74
+ requirements:
88
75
  - - ~>
89
- - !ruby/object:Gem::Version
90
- hash: 23
91
- segments:
92
- - 2
93
- - 10
94
- version: "2.10"
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
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
101
89
  none: false
102
- requirements:
90
+ requirements:
103
91
  - - ~>
104
- - !ruby/object:Gem::Version
105
- hash: 25
106
- segments:
107
- - 0
108
- - 9
109
- version: "0.9"
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
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
116
105
  none: false
117
- requirements:
106
+ requirements:
118
107
  - - ~>
119
- - !ruby/object:Gem::Version
120
- hash: 63
121
- segments:
122
- - 0
123
- - 9
124
- - 2
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
- version_requirements: *id007
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
- hash: 3
179
- segments:
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
- hash: 3
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.6.2
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