peek-rblineprof 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,3 @@
1
+ # 0.0.1
2
+
3
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peek-rblineprof.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 dewski
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.
@@ -0,0 +1,67 @@
1
+ # Peek::Rblineprof
2
+
3
+ Peek into how much each line of your Rails application takes throughout a request.
4
+
5
+ Things this peek view provides:
6
+
7
+ - Total time it takes to render individual lines within your codebase
8
+ - Total network time spent waiting per line
9
+
10
+ You can also drill down to only certain parts of your codebase like:
11
+
12
+ - app, everything within `Rails.root/(app|lib)`
13
+ - views, everything within `Rails.root/app/view`
14
+ - gems, everything within `Rails.root/vendor/gems`
15
+ - all, everything within `Rails.root`
16
+ - stdlib
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'peek-rblineprof'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install peek-rblineprof
31
+
32
+ ## Usage
33
+
34
+ Add the following to your `config/initializers/peek.rb`:
35
+
36
+ ```ruby
37
+ Peek.into Peek::Views::Rblineconf
38
+ ```
39
+
40
+ You'll then need to add the following CSS and CoffeeScript:
41
+
42
+ CSS:
43
+
44
+ ```scss
45
+ //= require peek
46
+ //= require peek/views/rblineprof
47
+ ```
48
+
49
+ CoffeeScript:
50
+
51
+ ```coffeescript
52
+ #= require peek
53
+ #= require peek/views/rblineprof
54
+ ```
55
+
56
+ ## Contributors
57
+
58
+ - [@tmm1](https://github.com/tmm1) Wrote rblineprof
59
+ - [@dewski](https://github.com/dewski) Wrote peek-rblineprof
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ $(document).on 'click', '.js-lineprof-file', (e) ->
2
+ $(this).parents('.peek-rblineprof-file').next('div').toggle()
3
+ alert 'wtf'
4
+ e.preventDefault()
5
+ false
6
+
7
+ $ ->
@@ -0,0 +1,59 @@
1
+ .peek-rblineprof-modal {
2
+ width: 900px;
3
+ position: absolute;
4
+ z-index: 10000;
5
+ left: 50%;
6
+ margin-left: -450px;
7
+
8
+ pre {
9
+ font: 12px/18px monospace;
10
+ }
11
+ }
12
+
13
+
14
+ .peek-dropdown {
15
+ background: #fff;
16
+ position: absolute;
17
+ display: none;
18
+ z-index: 10001;
19
+ border-radius: 5px;
20
+ line-height: 18px;
21
+ min-width: 150px;
22
+ padding: 5px;
23
+ color: #333;
24
+ text-shadow: none;
25
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
26
+
27
+ a {
28
+ color: #333;
29
+ }
30
+ }
31
+
32
+ #peek .view:hover .peek-dropdown {
33
+ display: block;
34
+ }
35
+
36
+ .peek-rblineprof-file {
37
+ background: #fff;
38
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
39
+ margin-bottom: 10px;
40
+
41
+ .heading {
42
+ background: #333;
43
+ color: #aaa;
44
+ padding: 10px 15px;
45
+ text-shadow: 0 1px 0 #000;
46
+
47
+ .duration {
48
+ margin: 0 65px 0 40px;
49
+ }
50
+
51
+ a {
52
+ color: #fff;
53
+ }
54
+ }
55
+
56
+ pre {
57
+ padding: 15px;
58
+ }
59
+ }
@@ -0,0 +1,10 @@
1
+ <%= link_to 'Profile', :lineprofiler => true %>
2
+ <div class="peek-dropdown">
3
+ <ul>
4
+ <li><%= link_to 'app', :lineprofiler => 'app' %></li>
5
+ <li><%= link_to 'views', :lineprofiler => 'views' %></li>
6
+ <li><%= link_to 'gems', :lineprofiler => 'gems' %></li>
7
+ <li><%= link_to 'all', :lineprofiler => 'all' %></li>
8
+ <li><%= link_to 'stdlib', :lineprofiler => 'stdlib' %></li>
9
+ </ul>
10
+ </div>
@@ -0,0 +1,3 @@
1
+ require 'peek/views/rblineprof'
2
+ require 'peek-rblineprof/version'
3
+ require 'peek-rblineprof/railtie'
@@ -0,0 +1,13 @@
1
+ require 'peek/rblineprof/controller_helpers'
2
+
3
+ module Peek
4
+ module Rblineprof
5
+ class Railtie < ::Rails::Engine
6
+ initializer 'peek.rblineprof.include_controller_helpers' do
7
+ ActiveSupport.on_load(:action_controller) do
8
+ include Peek::Rblineprof::ControllerHelpers
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Peek
2
+ module Rblineprof
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,104 @@
1
+ module Peek
2
+ module Rblineprof
3
+ module ControllerHelpers
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ around_filter :inject_rblineprof, :if => [:peek_enabled?, :rblineprof_enabled?]
8
+ end
9
+
10
+ protected
11
+
12
+ def rblineprof_enabled?
13
+ params[:lineprofiler].present?
14
+ end
15
+
16
+ def inject_rblineprof
17
+ escaped_rails_root = Regexp.escape(Rails.root.to_s)
18
+ regex = case params[:lineprofiler]
19
+ when 'app'
20
+ %r{^#{escaped_rails_root}/(app|lib)}
21
+ when 'views'
22
+ %r{^#{escaped_rails_root}/app/view}
23
+ when 'gems'
24
+ %r|^#{escaped_rails_root}/vendor/gems|
25
+ when 'all'
26
+ %r|^#{escaped_rails_root}|
27
+ when 'stdlib'
28
+ %r|^#{Regexp.escape RbConfig::CONFIG['rubylibdir']}|
29
+ else
30
+ %r{^#{escaped_rails_root}/(app|config|lib|vendor/plugin)}
31
+ end
32
+
33
+ ret = nil
34
+ profile = lineprof(regex) do
35
+ ret = yield
36
+ end
37
+
38
+ if response.content_type =~ %r|text/html|
39
+ sort = params[:lineprofiler_sort]
40
+ mode = params[:lineprofiler_mode] || 'cpu'
41
+ min = (params[:lineprofiler_min] || 5).to_i * 1000
42
+ summary = params[:lineprofiler_summary]
43
+
44
+ per_file = profile.map do |file, lines|
45
+ total, child, excl, total_cpu, child_cpu, excl_cpu = lines[0]
46
+
47
+ wall = summary == 'exclusive' ? excl : total
48
+ cpu = summary == 'exclusive' ? excl_cpu : total_cpu
49
+ idle = summary == 'exclusive' ? (excl-excl_cpu) : (total-total_cpu)
50
+
51
+ [
52
+ file, lines,
53
+ wall, cpu, idle,
54
+ sort == 'idle' ? idle : sort == 'cpu' ? cpu : wall
55
+ ]
56
+ end.sort_by{ |a,b,c,d,e,f| -f }
57
+
58
+ output = ''
59
+ per_file.each do |file_name, lines, file_wall, file_cpu, file_idle, file_sort|
60
+ output << "<div class='peek-rblineprof-file'><div class='heading'>"
61
+
62
+ show_src = file_sort > min
63
+ tmpl = show_src ? "<a href='#' class='js-lineprof-file'>%s</a>" : "%s"
64
+
65
+ if mode == 'cpu'
66
+ output << sprintf("<span class='duration'>% 8.1fms + % 8.1fms</span> #{tmpl}\n", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', ''))
67
+ else
68
+ output << sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}\n", file_wall/1000.0, file_name.sub(Rails.root.to_s + '/', ''))
69
+ end
70
+
71
+ output << "</div>"
72
+
73
+ next unless show_src
74
+
75
+ output << "<pre style='overflow-x: scroll'>"
76
+ File.readlines(file_name).each_with_index do |line, i|
77
+ wall, cpu, calls = lines[i + 1]
78
+
79
+ if calls && calls > 0
80
+ if mode == 'cpu'
81
+ idle = wall - cpu
82
+ output << sprintf("% 8.1fms + % 8.1fms (% 5d) | %s", cpu / 1000.0, idle / 1000.0, calls, Rack::Utils.escape_html(line))
83
+ else
84
+ output << sprintf("% 8.1fms (% 5d) | %s", wall / 1000.0, calls, Rack::Utils.escape_html(line))
85
+ end
86
+ else
87
+ if mode == 'cpu'
88
+ output << sprintf(" | %s", Rack::Utils.escape_html(line))
89
+ else
90
+ output << sprintf(" | %s", Rack::Utils.escape_html(line))
91
+ end
92
+ end
93
+ end
94
+ output << "</pre></div>"
95
+ end
96
+
97
+ response.body += "<div class='peek-rblineprof-modal' id='line-profile'>#{output}</div>".html_safe
98
+ end
99
+
100
+ ret
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,8 @@
1
+ require 'rblineprof'
2
+
3
+ module Peek
4
+ module Views
5
+ class Rblineprof < View
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'peek-rblineprof/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'peek-rblineprof'
8
+ spec.version = Peek::Rblineprof::VERSION
9
+ spec.authors = ['Garrett Bjerkhoel']
10
+ spec.email = ['me@garrettbjerkhoel.com']
11
+ spec.description = %q{Peek into how much each line of your Rails application takes throughout a request.}
12
+ spec.summary = %q{Peek into how much each line of your Rails application takes throughout a request.}
13
+ spec.homepage = 'https://github.com/peek/peek-rblineprof'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'peek'
22
+ spec.add_dependency 'rblineprof'
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peek-rblineprof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Garrett Bjerkhoel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: peek
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rblineprof
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Peek into how much each line of your Rails application takes throughout
79
+ a request.
80
+ email:
81
+ - me@garrettbjerkhoel.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - CHANGELOG.md
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - app/assets/javascripts/peek/views/rblineprof.coffee
93
+ - app/assets/stylesheets/peek/views/rblineprof.scss
94
+ - app/views/peek/views/_rblineprof.html.erb
95
+ - lib/peek-rblineprof.rb
96
+ - lib/peek-rblineprof/railtie.rb
97
+ - lib/peek-rblineprof/version.rb
98
+ - lib/peek/rblineprof/controller_helpers.rb
99
+ - lib/peek/views/rblineprof.rb
100
+ - peek-rblineprof.gemspec
101
+ homepage: https://github.com/peek/peek-rblineprof
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.23
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Peek into how much each line of your Rails application takes throughout a
126
+ request.
127
+ test_files: []