stackprofiler-middleware 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d729919c27abc83b5acf27ddd4e04ad31ab2133c
4
+ data.tar.gz: 1e281ffd39424e6a64978fc41a5c31e429faa4dd
5
+ SHA512:
6
+ metadata.gz: b63e0670829efb526d09c7f5f2af6880ae2a368144102b4be63057ca17087b88975272c152f76fca5faa5ae2121f8c7ef40f7bda2f5140cfc76015e1ba552059
7
+ data.tar.gz: 17c75a289a50b7fdcf8411efbe8364dd7041e896a22cc0dbe04998bf3f9efd14b8aa08574879abac7e234ba5fece8b6eb290af992e396e819454b71528ba1c42
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stackprofiler-middleware.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Aidan Steele
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Stackprofiler::Middleware
2
+
3
+ Please read the [`stackprofiler`][1] gem README for background on Stackprofiler
4
+ in general.
5
+
6
+ This is a [Rack][2] middleware that makes benchmarking of Rack apps a breeze.
7
+ It utilises the brilliant [`stackprof`][3] to enable low-overhead sampling of
8
+ Ruby processes.
9
+
10
+ much more fluid experience and provide a quicker turn-around time. It does
11
+ this by passing along Pry's linebuffer to the Stackprofiler server so that
12
+ code needn't be stored in the file system for Stackprofiler to annotate.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'stackprofiler-middleware'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install stackprofiler-middleware
29
+
30
+ You should have also already installed the main Stackprofiler gem as well. If
31
+ you haven't done that yet, head over to that gem's repo and come back here
32
+ once you're done.
33
+
34
+ ## Usage
35
+
36
+ First, boot up Stackprofiler's server in the background:
37
+
38
+ $ stackprofiler
39
+
40
+ Using Stackprofiler at this stage is pretty simple on account of there
41
+ not yet being much flexibility in the way of configuration. This will be
42
+ fixed later - hopefully the simplicity can remain.
43
+
44
+ Once installed, add Stackprofiler's middleware somewhere in your Rack
45
+ chain, e.g.:
46
+
47
+ ```ruby
48
+ config.middleware.use Stackprofiler::Middleware
49
+ ```
50
+
51
+ Now start your server like normal. If you wish to profile a request,
52
+ append `profile=true` to the query string. This will inform Stackprofiler
53
+ that it should do its thing. Take note that the response will remain
54
+ unchanged - Stackprofiler will record its statistics for your later perusal
55
+ elsewhere. This is to make it easier to profile requests that don't return
56
+ visible results, e.g. XHR.
57
+
58
+ Once you have profiled a request or two, you can head over to Stackprofiler's
59
+ GUI. This is probably at [http://localhost:9292/][4]. Read
60
+ Stackprofiler's README to see how this web UI works.
61
+
62
+ ### Data collection configuration
63
+
64
+ Stackprofiler's operation can be configured by passing in parameters to the
65
+ middleware specified above. While the defaults should suit most applications,
66
+ changing them is easy enough:
67
+
68
+ ```ruby
69
+ config.middleware.use Stackprofiler::Middleware {
70
+ predicate: /profile=true/, # regex form for urls to be profiled
71
+ predicate: proc {|env| true }, # callable form for greater flexibility than regex
72
+ stackprof: { # options to be passed directly through to stackprof, e.g.:
73
+ interval: 1000 # sample every n micro-seconds
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it ( https://github.com/glassechidna/stackprofiler-middleware/fork )
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create a new Pull Request
85
+
86
+ [1]: https://github.com/glassechidna/stackprofiler
87
+ [2]: http://rack.github.io/
88
+ [3]: https://github.com/tmm1/stackprof
89
+ [4]: http://localhost:9292/
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,49 @@
1
+ require 'stackprof'
2
+ require 'rack'
3
+
4
+ module Stackprofiler
5
+ class Middleware
6
+ attr_accessor :ui_url
7
+
8
+ def initialize(app, options={})
9
+ @app = app
10
+
11
+ pred = options[:predicate] || /profile=true/
12
+ if pred.respond_to? :call
13
+ @predicate = pred
14
+ else
15
+ regex = Regexp.new pred
16
+
17
+ @predicate = proc do |env|
18
+ req = Rack::Request.new env
19
+ req.fullpath =~ regex
20
+ end
21
+ end
22
+
23
+ @ui_url = options[:ui_url] || ENV['PRY_STACKPROFILER_UI_URL']
24
+ @stackprof_opts = {mode: :wall, interval: 1000, raw: true}.merge(options[:stackprof] || {})
25
+ end
26
+
27
+ def call(env)
28
+ if @predicate.call(env)
29
+ out = nil
30
+ profile = StackProf.run(@stackprof_opts) { out = @app.call env }
31
+
32
+ Thread.new do
33
+ profile[:name] = Rack::Request.new(env).fullpath
34
+
35
+ url = URI::parse ui_url
36
+ headers = {'Content-Type' => 'application/x-ruby-marshal'}
37
+ req = Net::HTTP::Post.new(url.to_s, headers)
38
+ req.body = Marshal.dump profile
39
+
40
+ response = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
41
+ end
42
+
43
+ out
44
+ else
45
+ @app.call env
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'stackprofiler-middleware'
5
+ spec.version = '0.0.1'
6
+ spec.authors = ['Aidan Steele']
7
+ spec.email = ['aidan.steele@glassechidna.com.au']
8
+ spec.summary = %q{Rack middleware for the Stackprofiler profiling gem.}
9
+ spec.homepage = ''
10
+ spec.license = 'MIT'
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_dependency 'stackprof', '~> 0.2'
18
+ spec.add_dependency 'rack'
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stackprofiler-middleware
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aidan Steele
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stackprof
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - aidan.steele@glassechidna.com.au
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/stackprofiler/middleware.rb
82
+ - stackprofiler-middleware.gemspec
83
+ homepage: ''
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Rack middleware for the Stackprofiler profiling gem.
107
+ test_files: []
108
+ has_rdoc: