rack_jruby_profiling 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,26 @@
1
1
  = rack_jruby_profiling
2
2
 
3
- Description goes here.
3
+ To use this in your application you need to have JRubyProf (http://github.com/danlucraft/jruby-prof) installed and available, and your application should be running on the JVM (of course).
4
+
5
+ This is used like any other Rack middleware:
6
+
7
+ require 'rack_jruby_profiling'
8
+ use Rack::JRubyProfiler
9
+
10
+ You can selectively turn off profiling on any request by adding "no_profile=<t,true,y,yes>" to the query parameter list.
11
+
12
+ The results of the profiling are streamed directly to your client. If you would like to download the file that is generated instead, add a "download=<t,true,y,yes>" parameter to your request.
13
+
14
+ JRubyProf supports 5 different profile outputs. You can add "profile=<flat,graph,call_tree,graph_html,tree_html>" to specify which you want to use. The default is "tree_html". See http://danlucraft.com/blog/2010/03/jruby-prof/ for more information on these outputs.
15
+
16
+ * flat => plain text
17
+ * graph => plain text
18
+ * call_tree => plain text
19
+ * graph_html => HTML
20
+ * tree_html => HTML
21
+
22
+ == Caveat
23
+ JRubyProf generates files for the profiling information. These files are generated in the current working directory. This middleware doesn't attempt to delete those files after they are generated. That's an exercise left to the user.
4
24
 
5
25
  == Note on Patches/Pull Requests
6
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 1.0.0
@@ -5,7 +5,11 @@ module Rack
5
5
  #
6
6
  # Set the profile=call_tree query parameter to view a calltree profile of the request.
7
7
  #
8
- # Set the download query parameter to download the result locally
8
+ # Set the download query parameter to download the result locally.
9
+ #
10
+ # Set the no_profile query parameter to selectively turn off profiling on certain requests.
11
+ #
12
+ # Both the no_profile and download parameters take a tru-ish value, one of [y, yes, t, true]
9
13
  #
10
14
  class JRubyProfiler
11
15
  DEFAULT_CONTENT_TYPE = 'text/html'
@@ -54,16 +58,20 @@ module Rack
54
58
  def profile(env)
55
59
  request = Rack::Request.new(env)
56
60
  @printer = parse_printer(request.params.delete('profile'))
57
- if JRubyProf.running?
61
+ if JRubyProf.running? || boolean(request['no_profile'])
58
62
  @app.call(env)
59
63
  else
60
- count = (request.params.delete('times') || @times).to_i
61
- result = JRubyProf.profile do
62
- count.times { @app.call(env) }
64
+ begin
65
+ count = (request.params.delete('times') || @times).to_i
66
+ result = JRubyProf.profile do
67
+ count.times { @app.call(env) }
68
+ end
69
+ @uniq_id = Java::java.lang.System.nano_time
70
+ @profile_file = ::File.expand_path( filename(@printer, env) )
71
+ [200, headers(@printer, request, env), print(@printer, request, env, result)]
72
+ ensure
73
+ JRubyProf.stop
63
74
  end
64
- @uniq_id = Java::java.lang.System.nano_time
65
- @profile_file = ::File.expand_path( filename(@printer, env) )
66
- [200, headers(@printer, request, env), print(@printer, request, env, result)]
67
75
  end
68
76
  end
69
77
 
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack_jruby_profiling}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Rogers"]
12
+ s.date = %q{2010-04-15}
13
+ s.description = %q{Rack middleware for running profiling JRuby applications}
14
+ s.email = %q{jacaetevha@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "VERSION",
23
+ "lib/rack_jruby_profiling.rb",
24
+ "rack_jruby_profiling.gemspec",
25
+ "spec/rack_jruby_profiling_spec.rb",
26
+ "spec/spec.opts",
27
+ "spec/spec_helper.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/jacaetevha/rack_jruby_profiling}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.6}
33
+ s.summary = %q{Rack middleware for running profiling JRuby applications}
34
+ s.test_files = [
35
+ "spec/rack_jruby_profiling_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
45
+ else
46
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
50
+ end
51
+ end
52
+
@@ -5,7 +5,7 @@ module TestHelpers
5
5
  Proc.new { |env|
6
6
  500.times {|t| "construct a string for #{t} just so that we have some work to do in this application"}
7
7
  500.times {|t| [t, t/4.0].max }
8
- [@code, {"Content-Type" => "text/plain", "Content-Length" => "3"}, [@code.to_s]]
8
+ [code, {"Content-Type" => "text/plain", "Content-Length" => "3"}, [code.to_s]]
9
9
  }
10
10
  end
11
11
 
@@ -37,11 +37,17 @@ describe Rack::JRubyProfiler do
37
37
  end
38
38
 
39
39
  after :each do
40
- if @profiler
40
+ if @profiler && @profiler.profile_file
41
41
  File.delete @profiler.profile_file
42
42
  end
43
43
  end
44
44
 
45
+ it "shouldn't profile is the no_profile query parameter is set" do
46
+ @request = Rack::MockRequest.env_for("/profile_test?no_profile=true")
47
+ response = response_for( basic_application(200), @request )
48
+ response.should == basic_application(200).call(nil)
49
+ end
50
+
45
51
  [200, 301, 404, 500].each do | code |
46
52
  it "should successfully respond with 200 if down-stream app returns #{code}" do
47
53
  response = response_for( basic_application(code), @request )
@@ -56,8 +62,8 @@ describe Rack::JRubyProfiler do
56
62
  end
57
63
 
58
64
  it "should NOT mask when a down-stream app throws an error" do
59
- @request = Rack::MockRequest.env_for("/profile_test")
60
- lambda{ response_for( error_application('ka-boom!'), request ) }.should raise_error
65
+ request = Rack::MockRequest.env_for("/profile_test")
66
+ lambda{ response_for( error_application('ka-boom!'), request ) }.should raise_error('ka-boom!')
61
67
  end
62
68
 
63
69
  class Tuple
metadata CHANGED
@@ -3,10 +3,10 @@ name: rack_jruby_profiling
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 0
7
6
  - 1
8
7
  - 0
9
- version: 0.1.0
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jason Rogers
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-13 00:00:00 -04:00
17
+ date: 2010-04-15 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,7 @@ files:
45
45
  - README.rdoc
46
46
  - VERSION
47
47
  - lib/rack_jruby_profiling.rb
48
+ - rack_jruby_profiling.gemspec
48
49
  - spec/rack_jruby_profiling_spec.rb
49
50
  - spec/spec.opts
50
51
  - spec/spec_helper.rb