rack-perftools_profiler 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -8
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/rack/perftools_profiler.rb +0 -87
- data/lib/rack/perftools_profiler/profiler.rb +10 -5
- data/test/rack-perftools-profiler_test.rb +24 -0
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -26,12 +26,22 @@ Include the middleware
|
|
26
26
|
|
27
27
|
require 'rack/perftools_profiler'
|
28
28
|
|
29
|
-
For Rails, add the following to config/environment.rb
|
29
|
+
For Rails 2, add the following to config/environment.rb
|
30
30
|
|
31
|
-
config.gem 'rack-perftools_profiler', :version => '~> 0.
|
31
|
+
config.gem 'rack-perftools_profiler', :version => '~> 0.1', :lib => 'rack/perftools_profiler'
|
32
32
|
require 'rack/perftools_profiler'
|
33
33
|
config.middleware.use Rack::PerftoolsProfiler, :default_printer => 'gif'
|
34
34
|
|
35
|
+
For Rails 3 (or any app using Bundler), add the following to your Gemfile
|
36
|
+
|
37
|
+
gem 'rack-perftools_profiler', '~> 0.1', :require => 'rack/perftools_profiler'
|
38
|
+
|
39
|
+
and make sure you pass the option
|
40
|
+
|
41
|
+
:bundler => true
|
42
|
+
|
43
|
+
when configuring the middleware.
|
44
|
+
|
35
45
|
For Sinatra, call 'use' inside a configure block, like so:
|
36
46
|
|
37
47
|
configure :profiling do
|
@@ -49,6 +59,8 @@ For Rack::Builder, call 'use' inside the Builder constructor block
|
|
49
59
|
* :default_printer - can be set to 'text', 'gif', or 'pdf'. Default is :text
|
50
60
|
* :mode - can be set to 'cputime' or 'walltime'. Default is :cputime
|
51
61
|
* :frequency - in :cputime mode, the number of times per second the app will be sampled. Default is 100 (times/sec)
|
62
|
+
* :bundler - run the profiler binary using 'bundle' if set to true. Default is false
|
63
|
+
* :gemfile_dir - directory with Gemfile. Default is the current directory.
|
52
64
|
|
53
65
|
== Usage
|
54
66
|
|
@@ -59,7 +71,7 @@ add the 'profile' and (optionally) the 'times' GET params (which will rerun the
|
|
59
71
|
the specified number of times).
|
60
72
|
|
61
73
|
Example:
|
62
|
-
curl http://localhost:
|
74
|
+
curl http://localhost:3000/foobar?profile=true×=3
|
63
75
|
|
64
76
|
Note that this will change the status, body, and headers of the response (you'll get
|
65
77
|
back the profiling data, NOT the original response).
|
@@ -67,11 +79,11 @@ back the profiling data, NOT the original response).
|
|
67
79
|
The other mode is start/stop mode.
|
68
80
|
|
69
81
|
Example:
|
70
|
-
curl http://localhost:
|
71
|
-
curl http://localhost:
|
72
|
-
curl http://localhost:
|
73
|
-
curl http://localhost:
|
74
|
-
curl http://localhost:
|
82
|
+
curl http://localhost:3000/__start__
|
83
|
+
curl http://localhost:3000/foobar
|
84
|
+
curl http://localhost:3000/foobaz
|
85
|
+
curl http://localhost:3000/__stop__
|
86
|
+
curl http://localhost:3000/__data__
|
75
87
|
|
76
88
|
In this mode, all responses are normal. You must visit \_\_stop\_\_ to complete profiling and
|
77
89
|
then you can view the profiling data by visiting \_\_data\_\_
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = 'ben@bbrinck.com'
|
11
11
|
gem.homepage = 'http://github.com/bhb/rack-perftools_profiler'
|
12
12
|
gem.authors = ['Ben Brinckerhoff']
|
13
|
-
gem.add_dependency 'perftools.rb', '~> 0.
|
13
|
+
gem.add_dependency 'perftools.rb', '~> 0.5'
|
14
14
|
gem.add_dependency 'rack', '~> 1.0'
|
15
15
|
gem.add_dependency('open4', '~> 1.0')
|
16
16
|
gem.add_development_dependency 'rack', '~> 1.1'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,90 +1,3 @@
|
|
1
|
-
# REQUIREMENTS
|
2
|
-
#
|
3
|
-
# You'll need graphviz to generate call graphs using dot (for the GIF printer):
|
4
|
-
#
|
5
|
-
# sudo port install graphviz # osx
|
6
|
-
# sudo apt-get install graphviz # debian/ubuntu
|
7
|
-
|
8
|
-
# You'll need ps2pdf to generate PDFs
|
9
|
-
# On OS X, ps2pdf comes is installed as part of Ghostscript
|
10
|
-
#
|
11
|
-
# sudo port install ghostscript # osx
|
12
|
-
# brew install ghostscript # homebrew
|
13
|
-
# sudo apt-get install ps2pdf # debian/ubuntu
|
14
|
-
|
15
|
-
# CONFIGURATION
|
16
|
-
#
|
17
|
-
# Include the middleware
|
18
|
-
#
|
19
|
-
# require 'rack/perftools_profiler'
|
20
|
-
#
|
21
|
-
# For Rails, add the following to config/environment.rb
|
22
|
-
#
|
23
|
-
# config.middleware.use Rack::PerftoolsProfiler, :default_printer => 'gif'
|
24
|
-
#
|
25
|
-
# For Sinatra, call 'use' inside a configure block, like so:
|
26
|
-
#
|
27
|
-
# configure :profiling do
|
28
|
-
# use Rack::PerftoolsProfiler, :default_printer => 'gif'
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# For Rack::Builder, call 'use' inside the Builder constructor block
|
32
|
-
#
|
33
|
-
# Rack::Builder.new do
|
34
|
-
# use Rack::PerftoolsProfiler, :default_printer => 'gif'
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# OPTIONS
|
39
|
-
#
|
40
|
-
# :default_printer - can be set to 'text', 'gif', or 'pdf'. Default is :text
|
41
|
-
# :mode - can be set to 'cputime' or 'walltime'. Default is :cputime
|
42
|
-
# :frequency - in :cputime mode, the number of times per second the app will be sampled.
|
43
|
-
# Default is 100 (times/sec)
|
44
|
-
#
|
45
|
-
# USAGE
|
46
|
-
#
|
47
|
-
# There are two modes for the profiler
|
48
|
-
#
|
49
|
-
# First, you can run in 'simple' mode. Just visit the url you want to profile, but
|
50
|
-
# add the 'profile' and (optionally) the 'times' GET params
|
51
|
-
#
|
52
|
-
# example:
|
53
|
-
# curl http://localhost:8080/foobar?profile=true×=3
|
54
|
-
#
|
55
|
-
# Note that this will change the status, body, and headers of the response (you'll get
|
56
|
-
# back the profiling data, NOT the original response.
|
57
|
-
#
|
58
|
-
#
|
59
|
-
# The other mode is start/stop mode.
|
60
|
-
#
|
61
|
-
# example:
|
62
|
-
# curl http://localhost:8080/__start__
|
63
|
-
# curl http://localhost:8080/foobar
|
64
|
-
# curl http://localhost:8080/foobaz
|
65
|
-
# curl http://localhost:8080/__stop__
|
66
|
-
# curl http://localhost:8080/__data__
|
67
|
-
#
|
68
|
-
# In this mode, all responses are normal. You must visit __stop__ to complete profiling and
|
69
|
-
# then you can view the profiling data by visiting __data__
|
70
|
-
|
71
|
-
# PROFILING DATA OPTIONS
|
72
|
-
#
|
73
|
-
# In both simple and start/stop modes, you can add additional params to change how the data
|
74
|
-
# is displayed. In simple mode, these params are just added to the URL being profiled. In
|
75
|
-
# start/stop mode, they are added to the __data__ URL
|
76
|
-
|
77
|
-
# printer - overrides the default_printer option (see above)
|
78
|
-
# ignore - a regular expression of the area of code to ignore
|
79
|
-
# focus - a regular expression of the area of code to solely focus on.
|
80
|
-
|
81
|
-
# (for ignore and focus, please see http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html#pprof
|
82
|
-
# for more details)
|
83
|
-
#
|
84
|
-
# ACKNOWLEDGMENTS
|
85
|
-
#
|
86
|
-
# The basic idea and initial implementation was heavily influenced by Rack::Profiler from rack-contrib.
|
87
|
-
|
88
1
|
require 'rack'
|
89
2
|
require 'perftools'
|
90
3
|
require 'pstore'
|
@@ -24,12 +24,15 @@ module Rack::PerftoolsProfiler
|
|
24
24
|
DEFAULT_PRINTER = :text
|
25
25
|
DEFAULT_MODE = :cputime
|
26
26
|
UNSET_FREQUENCY = -1
|
27
|
+
DEFAULT_GEMFILE_DIR = '.'
|
27
28
|
|
28
29
|
def initialize(app, options)
|
29
|
-
@printer
|
30
|
+
@printer = (options.delete(:default_printer) { DEFAULT_PRINTER }).to_sym
|
31
|
+
@frequency = (options.delete(:frequency) { UNSET_FREQUENCY }).to_s
|
32
|
+
@mode = (options.delete(:mode) { DEFAULT_MODE }).to_sym
|
33
|
+
@bundler = (options.delete(:bundler) { false })
|
34
|
+
@gemfile_dir = (options.delete(:gemfile_dir) { DEFAULT_GEMFILE_DIR })
|
30
35
|
ProfileDataAction.check_printer(@printer)
|
31
|
-
@frequency = (options.delete(:frequency) { UNSET_FREQUENCY }).to_s
|
32
|
-
@mode = (options.delete(:mode) { DEFAULT_MODE }).to_sym
|
33
36
|
raise ProfilerArgumentError, "Invalid option(s): #{options.keys.join(' ')}" unless options.empty?
|
34
37
|
end
|
35
38
|
|
@@ -43,9 +46,10 @@ module Rack::PerftoolsProfiler
|
|
43
46
|
def self.clear_data
|
44
47
|
::File.delete(PROFILING_DATA_FILE) if ::File.exists?(PROFILING_DATA_FILE)
|
45
48
|
end
|
46
|
-
|
49
|
+
|
47
50
|
def start
|
48
51
|
set_env_vars
|
52
|
+
PerfTools::CpuProfiler.stop
|
49
53
|
PerfTools::CpuProfiler.start(PROFILING_DATA_FILE)
|
50
54
|
self.profiling = true
|
51
55
|
end
|
@@ -71,7 +75,8 @@ module Rack::PerftoolsProfiler
|
|
71
75
|
args += " --ignore=#{ignore}" if ignore
|
72
76
|
args += " --focus=#{focus}" if focus
|
73
77
|
cmd = "pprof.rb #{args} #{PROFILING_DATA_FILE}"
|
74
|
-
|
78
|
+
cmd = "bundle exec " + cmd if @bundler
|
79
|
+
stdout, stderr, status = Dir.chdir(@gemfile_dir) { run(cmd) }
|
75
80
|
if(status == 0)
|
76
81
|
[printer, stdout]
|
77
82
|
else
|
@@ -402,6 +402,30 @@ class RackPerftoolsProfilerTest < Test::Unit::TestCase
|
|
402
402
|
end
|
403
403
|
|
404
404
|
end
|
405
|
+
|
406
|
+
context "when in bundler mode" do
|
407
|
+
|
408
|
+
should "call pprof.rb using 'bundle' command if bunder is set" do
|
409
|
+
status = stub_everything(:exitstatus => 0)
|
410
|
+
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
|
411
|
+
Open4.expects(:popen4).with(regexp_matches(/^bundle exec pprof\.rb/)).returns(status)
|
412
|
+
profiled_app.call(@profiled_request_env)
|
413
|
+
end
|
414
|
+
|
415
|
+
should "change directory into the current directory if custom Gemfile dir is not provided" do
|
416
|
+
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true, :gemfile_dir => 'bundler')
|
417
|
+
Dir.expects(:chdir).with('bundler').returns(["","",0])
|
418
|
+
profiled_app.call(@profiled_request_env)
|
419
|
+
end
|
420
|
+
|
421
|
+
should "change directory into custom Gemfile dir if provided" do
|
422
|
+
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
|
423
|
+
Dir.expects(:chdir).with('.').returns(["","",0])
|
424
|
+
profiled_app.call(@profiled_request_env)
|
425
|
+
end
|
426
|
+
|
427
|
+
end
|
428
|
+
|
405
429
|
end
|
406
430
|
|
407
431
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.2
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ben Brinckerhoff
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-21 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,8 +26,8 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 0
|
29
|
-
-
|
30
|
-
version: "0.
|
29
|
+
- 5
|
30
|
+
version: "0.5"
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|