peek-rblineprof-0.2.0/ 0000755 0001750 0001750 00000000000 13155221144 013617 5 ustar pravi pravi peek-rblineprof-0.2.0/CHANGELOG.md 0000644 0001750 0001750 00000001533 13155221144 015432 0 ustar pravi pravi # 0.0.1
- Initial release.
# 0.1.1
- Fix CSS for modal where it would be anchored to the bottom of the page.
# 0.1.2
- Fixed an issue where non pygmentized code blocks would not be formatted properly. #1
# 0.2.0
- Convert CoffeeScript to JavaScript - [@dewski](https://github.com/dewski)
- Fix JavaScript collapsing of files - [#7](https://github.com/peek/peek-rblineprof/pull/7) [@fedesoria](https://github.com/fedesoria)
- Use around_action instead of around_filter - [#15](https://github.com/peek/peek-rblineprof/pull/15) [@8398a7](https://github.com/8398a7)
- Use `url_for` for generating request parameters - [#11](https://github.com/peek/peek-rblineprof/pull/11) [@wa0x6e](https://github.com/wa0x6e)
- Require `peek` before loading `peek-rblineprof` - [#14](https://github.com/peek/peek-rblineprof/pull/14) [@bakunyo](https://github.com/bakunyo)
peek-rblineprof-0.2.0/README.md 0000644 0001750 0001750 00000004265 13155221144 015105 0 ustar pravi pravi # Peek::Rblineprof
Peek into how much time each line of your Rails application takes throughout a request.
Things this peek view provides:
- Total time it takes to render individual lines within your codebase
- Total network time spent waiting per line
You can also drill down to only certain parts of your codebase like:
- app, everything within `Rails.root/(app|lib)`
- views, everything within `Rails.root/app/view`
- gems, everything within `Rails.root/vendor/gems`
- all, everything within `Rails.root`
- stdlib

## Installation
Add this line to your application's Gemfile:
gem 'peek-rblineprof'
And then execute:
$ bundle
Or install it yourself as:
$ gem install peek-rblineprof
## Usage
Add the following to your `config/initializers/peek.rb`:
```ruby
Peek.into Peek::Views::Rblineprof
```
You'll then need to add the following CSS and CoffeeScript:
CSS:
```scss
//= require peek
//= require peek/views/rblineprof
```
CoffeeScript:
```coffeescript
#= require peek
#= require peek/views/rblineprof
```
## Integration with pygments.rb
By default peek-rblineprof renders the code of each file in plain text with no
syntax highlighting for performance reasons. If you'd like to have your code
highlighted as it does on GitHub.com, just include the [pygments.rb](https://github.com/tmm1/pygments.rb) gem:
```ruby
gem 'pygments.rb', :require => false
```
peek-rblineprof will now highlight each file for you, but there's one more thing...
To use the default theme that peek-rblineprof provides just add the following
to your peek specific or application stylesheet:
```scss
//= require peek/views/rblineprof/pygments
```
That's it! Now your code will look :sparkles:
## Contributors
- [@tmm1](https://github.com/tmm1) for [rblineprof](https://github.com/tmm1/rblineprof)
- [@dewski](https://github.com/dewski) for this
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
peek-rblineprof-0.2.0/peek-rblineprof.gemspec 0000644 0001750 0001750 00000002055 13155221144 020252 0 ustar pravi pravi # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'peek-rblineprof/version'
Gem::Specification.new do |spec|
spec.name = 'peek-rblineprof'
spec.version = Peek::Rblineprof::VERSION
spec.authors = ['Garrett Bjerkhoel']
spec.email = ['me@garrettbjerkhoel.com']
spec.description = %q{Peek into how much each line of your Rails application takes throughout a request.}
spec.summary = %q{Peek into how much each line of your Rails application takes throughout a request.}
spec.homepage = 'https://github.com/peek/peek-rblineprof'
spec.license = 'MIT'
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.add_dependency 'peek'
spec.add_dependency 'rblineprof'
spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'rake'
end
peek-rblineprof-0.2.0/lib/ 0000755 0001750 0001750 00000000000 13155221144 014365 5 ustar pravi pravi peek-rblineprof-0.2.0/lib/peek-rblineprof/ 0000755 0001750 0001750 00000000000 13155221144 017451 5 ustar pravi pravi peek-rblineprof-0.2.0/lib/peek-rblineprof/railtie.rb 0000644 0001750 0001750 00000000507 13155221144 021431 0 ustar pravi pravi require 'peek/rblineprof/controller_helpers'
module Peek
module Rblineprof
class Railtie < ::Rails::Engine
initializer 'peek.rblineprof.include_controller_helpers' do
ActiveSupport.on_load(:action_controller) do
include Peek::Rblineprof::ControllerHelpers
end
end
end
end
end
peek-rblineprof-0.2.0/lib/peek-rblineprof/version.rb 0000644 0001750 0001750 00000000100 13155221144 021452 0 ustar pravi pravi module Peek
module Rblineprof
VERSION = '0.2.0'
end
end
peek-rblineprof-0.2.0/lib/peek/ 0000755 0001750 0001750 00000000000 13155221144 015311 5 ustar pravi pravi peek-rblineprof-0.2.0/lib/peek/views/ 0000755 0001750 0001750 00000000000 13155221144 016446 5 ustar pravi pravi peek-rblineprof-0.2.0/lib/peek/views/rblineprof.rb 0000644 0001750 0001750 00000000171 13155221144 021134 0 ustar pravi pravi require 'peek/views/view'
require 'rblineprof'
module Peek
module Views
class Rblineprof < View
end
end
end
peek-rblineprof-0.2.0/lib/peek/rblineprof/ 0000755 0001750 0001750 00000000000 13155221144 017453 5 ustar pravi pravi peek-rblineprof-0.2.0/lib/peek/rblineprof/controller_helpers.rb 0000644 0001750 0001750 00000010263 13155221144 023707 0 ustar pravi pravi begin
require 'pygments.rb'
rescue LoadError
# Doesn't have pygments.rb installed
end
require 'rack/utils'
module Peek
module Rblineprof
module ControllerHelpers
extend ActiveSupport::Concern
included do
around_action :inject_rblineprof, :if => [:peek_enabled?, :rblineprof_enabled?]
end
protected
def pygmentize?
defined?(Pygments)
end
def pygmentize(file_name, code, lexer = nil)
if pygmentize? && lexer.present?
Pygments.highlight(code, :lexer => lexer_for_filename(file_name))
else
"
#{Rack::Utils.escape_html(code)}
"
end
end
def rblineprof_enabled?
params[:lineprofiler].present?
end
def lexer_for_filename(file_name)
case file_name
when /\.rb$/ then 'ruby'
when /\.erb$/ then 'erb'
end
end
def rblineprof_profiler_regex
escaped_rails_root = Regexp.escape(Rails.root.to_s)
case params[:lineprofiler]
when 'app'
%r{^#{escaped_rails_root}/(app|lib)}
when 'views'
%r{^#{escaped_rails_root}/app/view}
when 'gems'
%r|^#{escaped_rails_root}/vendor/gems|
when 'all'
%r|^#{escaped_rails_root}|
when 'stdlib'
%r|^#{Regexp.escape RbConfig::CONFIG['rubylibdir']}|
else
%r{^#{escaped_rails_root}/(app|config|lib|vendor/plugin)}
end
end
def inject_rblineprof
ret = nil
profile = lineprof(rblineprof_profiler_regex) do
ret = yield
end
if response.content_type =~ %r|text/html|
sort = params[:lineprofiler_sort]
mode = params[:lineprofiler_mode] || 'cpu'
min = (params[:lineprofiler_min] || 5).to_i * 1000
summary = params[:lineprofiler_summary]
# Sort each file by the longest calculated time
per_file = profile.map do |file, lines|
total, child, excl, total_cpu, child_cpu, excl_cpu = lines[0]
wall = summary == 'exclusive' ? excl : total
cpu = summary == 'exclusive' ? excl_cpu : total_cpu
idle = summary == 'exclusive' ? (excl - excl_cpu) : (total - total_cpu)
[
file, lines,
wall, cpu, idle,
sort == 'idle' ? idle : sort == 'cpu' ? cpu : wall
]
end.sort_by{ |a,b,c,d,e,f| -f }
output = ''
per_file.each do |file_name, lines, file_wall, file_cpu, file_idle, file_sort|
output << ""
show_src = file_sort > min
tmpl = show_src ? "
%s" : "%s"
if mode == 'cpu'
output << sprintf("
% 8.1fms + % 8.1fms #{tmpl}", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', ''))
else
output << sprintf("
% 8.1fms #{tmpl}", file_wall/1000.0, file_name.sub(Rails.root.to_s + '/', ''))
end
output << "
" # .heading
next unless show_src
output << "
"
code = []
times = []
File.readlines(file_name).each_with_index do |line, i|
code << line
wall, cpu, calls = lines[i + 1]
if calls && calls > 0
if mode == 'cpu'
idle = wall - cpu
times << sprintf("% 8.1fms + % 8.1fms (% 5d)", cpu / 1000.0, idle / 1000.0, calls)
else
times << sprintf("% 8.1fms (% 5d)", wall / 1000.0, calls)
end
else
times << ' '
end
end
output << "
#{times.join("\n")}
"
output << "
#{pygmentize(file_name, code.join, 'ruby')}
"
output << "
" # .data then .peek-rblineprof-file
end
response.body += "#{output}
".html_safe
end
ret
end
end
end
end
peek-rblineprof-0.2.0/lib/peek-rblineprof.rb 0000644 0001750 0001750 00000000163 13155221144 017776 0 ustar pravi pravi require 'peek'
require 'peek/views/rblineprof'
require 'peek-rblineprof/version'
require 'peek-rblineprof/railtie'
peek-rblineprof-0.2.0/LICENSE.txt 0000644 0001750 0001750 00000002047 13155221144 015445 0 ustar pravi pravi Copyright (c) 2013 dewski
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
peek-rblineprof-0.2.0/.gitignore 0000644 0001750 0001750 00000000232 13155221144 015604 0 ustar pravi pravi *.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
peek-rblineprof-0.2.0/Rakefile 0000644 0001750 0001750 00000000034 13155221144 015261 0 ustar pravi pravi require "bundler/gem_tasks"
peek-rblineprof-0.2.0/app/ 0000755 0001750 0001750 00000000000 13155221144 014377 5 ustar pravi pravi peek-rblineprof-0.2.0/app/views/ 0000755 0001750 0001750 00000000000 13155221144 015534 5 ustar pravi pravi peek-rblineprof-0.2.0/app/views/peek/ 0000755 0001750 0001750 00000000000 13155221144 016460 5 ustar pravi pravi peek-rblineprof-0.2.0/app/views/peek/views/ 0000755 0001750 0001750 00000000000 13155221144 017615 5 ustar pravi pravi peek-rblineprof-0.2.0/app/views/peek/views/_rblineprof.html.erb 0000644 0001750 0001750 00000000675 13155221144 023563 0 ustar pravi pravi <%= link_to 'Profile', :lineprofiler => true %>
- <%= link_to 'app', url_for(:lineprofiler => 'app') %>
- <%= link_to 'views', url_for(:lineprofiler => 'views') %>
- <%= link_to 'gems', url_for(:lineprofiler => 'gems') %>
- <%= link_to 'all', url_for(:lineprofiler => 'all') %>
- <%= link_to 'stdlib', url_for(:lineprofiler => 'stdlib') %>
peek-rblineprof-0.2.0/app/assets/ 0000755 0001750 0001750 00000000000 13155221144 015701 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/javascripts/ 0000755 0001750 0001750 00000000000 13155221144 020232 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/javascripts/peek/ 0000755 0001750 0001750 00000000000 13155221144 021156 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/javascripts/peek/views/ 0000755 0001750 0001750 00000000000 13155221144 022313 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/javascripts/peek/views/rblineprof.js 0000644 0001750 0001750 00000000231 13155221144 025007 0 ustar pravi pravi $(document).on('click', '.js-lineprof-file', function(e) {
$(this).parents('.heading').next('div').toggle();
e.preventDefault();
return false;
});
peek-rblineprof-0.2.0/app/assets/stylesheets/ 0000755 0001750 0001750 00000000000 13155221144 020255 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/stylesheets/peek/ 0000755 0001750 0001750 00000000000 13155221144 021201 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/stylesheets/peek/views/ 0000755 0001750 0001750 00000000000 13155221144 022336 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/stylesheets/peek/views/rblineprof.scss 0000644 0001750 0001750 00000002024 13155221144 025373 0 ustar pravi pravi .peek-rblineprof-modal {
width: 900px;
position: absolute;
z-index: 10000;
left: 50%;
top: 50px;
margin-left: -450px;
pre,
pre span {
font: 12px/18px monospace;
}
}
.peek-dropdown {
background: #fff;
position: absolute;
display: none;
z-index: 10001;
border-radius: 5px;
line-height: 18px;
min-width: 150px;
padding: 5px;
color: #333;
text-shadow: none;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
a {
color: #333;
}
}
#peek .view:hover .peek-dropdown {
display: block;
}
.peek-rblineprof-file {
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
margin-bottom: 10px;
.heading {
background: #333;
color: #aaa;
padding: 10px 15px;
text-shadow: 0 1px 0 #000;
.duration {
margin: 0 65px 0 40px;
}
a {
color: #fff;
}
}
.data {
overflow: hidden;
}
.code {
overflow-x: scroll;
border-left: 1px solid #ccc;
}
pre {
padding: 15px;
&.duration {
float: left;
width: 230px;
}
}
} peek-rblineprof-0.2.0/app/assets/stylesheets/peek/views/rblineprof/ 0000755 0001750 0001750 00000000000 13155221144 024500 5 ustar pravi pravi peek-rblineprof-0.2.0/app/assets/stylesheets/peek/views/rblineprof/pygments.scss 0000644 0001750 0001750 00000007256 13155221144 027255 0 ustar pravi pravi .highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { font-weight: bold } /* Keyword.Constant */
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #009999 } /* Literal.Number */
.highlight .s { color: #d14 } /* Literal.String */
.highlight .na { color: #008080 } /* Name.Attribute */
.highlight .nb { color: #0086B3 } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
.highlight .no { color: #008080 } /* Name.Constant */
.highlight .ni { color: #800080 } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
.highlight .nn { color: #555555 } /* Name.Namespace */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #008080 } /* Name.Variable */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #009999 } /* Literal.Number.Float */
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
.highlight .sc { color: #d14 } /* Literal.String.Char */
.highlight .sd { color: #d14 } /* Literal.String.Doc */
.highlight .s2 { color: #d14 } /* Literal.String.Double */
.highlight .se { color: #d14 } /* Literal.String.Escape */
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
.highlight .si { color: #d14 } /* Literal.String.Interpol */
.highlight .sx { color: #d14 } /* Literal.String.Other */
.highlight .sr { color: #009926 } /* Literal.String.Regex */
.highlight .s1 { color: #d14 } /* Literal.String.Single */
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #008080 } /* Name.Variable.Class */
.highlight .vg { color: #008080 } /* Name.Variable.Global */
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
peek-rblineprof-0.2.0/Gemfile 0000644 0001750 0001750 00000000144 13155221144 015111 0 ustar pravi pravi source 'https://rubygems.org'
# Specify your gem's dependencies in peek-rblineprof.gemspec
gemspec