peek-rblineprof 0.0.1 → 0.1.0
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.
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Or install it yourself as:
|
|
34
34
|
Add the following to your `config/initializers/peek.rb`:
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
Peek.into Peek::Views::
|
37
|
+
Peek.into Peek::Views::Rblineprof
|
38
38
|
```
|
39
39
|
|
40
40
|
You'll then need to add the following CSS and CoffeeScript:
|
@@ -53,10 +53,31 @@ CoffeeScript:
|
|
53
53
|
#= require peek/views/rblineprof
|
54
54
|
```
|
55
55
|
|
56
|
+
## Integration with pygments.rb
|
57
|
+
|
58
|
+
By default peek-rblineprof renders the code of each file in plain text with no
|
59
|
+
syntax highlighting for performance reasons. If you'd like to have your code
|
60
|
+
highlighted as it does on GitHub.com, just include the [pygments.rb](https://github.com/tmm1/pygments.rb) gem:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
gem 'pygments.rb', :require => false
|
64
|
+
```
|
65
|
+
|
66
|
+
peek-rblineprof will now highlight each file for you, but there's one more thing...
|
67
|
+
|
68
|
+
To use the default theme that peek-rblineprof provides just add the following
|
69
|
+
to your peek specific or application stylesheet:
|
70
|
+
|
71
|
+
```scss
|
72
|
+
//= require peek/views/rblineprof/pygments
|
73
|
+
```
|
74
|
+
|
75
|
+
That's it! Now your code will look :sparkles:
|
76
|
+
|
56
77
|
## Contributors
|
57
78
|
|
58
|
-
- [@tmm1](https://github.com/tmm1)
|
59
|
-
- [@dewski](https://github.com/dewski)
|
79
|
+
- [@tmm1](https://github.com/tmm1) wrote rblineprof
|
80
|
+
- [@dewski](https://github.com/dewski) wrote peek-rblineprof
|
60
81
|
|
61
82
|
## Contributing
|
62
83
|
|
@@ -5,7 +5,8 @@
|
|
5
5
|
left: 50%;
|
6
6
|
margin-left: -450px;
|
7
7
|
|
8
|
-
pre
|
8
|
+
pre,
|
9
|
+
pre span {
|
9
10
|
font: 12px/18px monospace;
|
10
11
|
}
|
11
12
|
}
|
@@ -53,7 +54,21 @@
|
|
53
54
|
}
|
54
55
|
}
|
55
56
|
|
57
|
+
.data {
|
58
|
+
overflow: hidden;
|
59
|
+
}
|
60
|
+
|
61
|
+
.code {
|
62
|
+
overflow-x: scroll;
|
63
|
+
border-left: 1px solid #ccc;
|
64
|
+
}
|
65
|
+
|
56
66
|
pre {
|
57
67
|
padding: 15px;
|
68
|
+
|
69
|
+
&.duration {
|
70
|
+
float: left;
|
71
|
+
width: 230px;
|
72
|
+
}
|
58
73
|
}
|
59
74
|
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
.highlight { background: #ffffff; }
|
2
|
+
.highlight .c { color: #999988; font-style: italic } /* Comment */
|
3
|
+
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
4
|
+
.highlight .k { font-weight: bold } /* Keyword */
|
5
|
+
.highlight .o { font-weight: bold } /* Operator */
|
6
|
+
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
|
7
|
+
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
|
8
|
+
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
|
9
|
+
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
|
10
|
+
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
11
|
+
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
|
12
|
+
.highlight .ge { font-style: italic } /* Generic.Emph */
|
13
|
+
.highlight .gr { color: #aa0000 } /* Generic.Error */
|
14
|
+
.highlight .gh { color: #999999 } /* Generic.Heading */
|
15
|
+
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
16
|
+
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
|
17
|
+
.highlight .go { color: #888888 } /* Generic.Output */
|
18
|
+
.highlight .gp { color: #555555 } /* Generic.Prompt */
|
19
|
+
.highlight .gs { font-weight: bold } /* Generic.Strong */
|
20
|
+
.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
|
21
|
+
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
|
22
|
+
.highlight .kc { font-weight: bold } /* Keyword.Constant */
|
23
|
+
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
|
24
|
+
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
|
25
|
+
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
|
26
|
+
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
|
27
|
+
.highlight .m { color: #009999 } /* Literal.Number */
|
28
|
+
.highlight .s { color: #d14 } /* Literal.String */
|
29
|
+
.highlight .na { color: #008080 } /* Name.Attribute */
|
30
|
+
.highlight .nb { color: #0086B3 } /* Name.Builtin */
|
31
|
+
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
|
32
|
+
.highlight .no { color: #008080 } /* Name.Constant */
|
33
|
+
.highlight .ni { color: #800080 } /* Name.Entity */
|
34
|
+
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
|
35
|
+
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
|
36
|
+
.highlight .nn { color: #555555 } /* Name.Namespace */
|
37
|
+
.highlight .nt { color: #000080 } /* Name.Tag */
|
38
|
+
.highlight .nv { color: #008080 } /* Name.Variable */
|
39
|
+
.highlight .ow { font-weight: bold } /* Operator.Word */
|
40
|
+
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
|
41
|
+
.highlight .mf { color: #009999 } /* Literal.Number.Float */
|
42
|
+
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
|
43
|
+
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
|
44
|
+
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
|
45
|
+
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
|
46
|
+
.highlight .sc { color: #d14 } /* Literal.String.Char */
|
47
|
+
.highlight .sd { color: #d14 } /* Literal.String.Doc */
|
48
|
+
.highlight .s2 { color: #d14 } /* Literal.String.Double */
|
49
|
+
.highlight .se { color: #d14 } /* Literal.String.Escape */
|
50
|
+
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
|
51
|
+
.highlight .si { color: #d14 } /* Literal.String.Interpol */
|
52
|
+
.highlight .sx { color: #d14 } /* Literal.String.Other */
|
53
|
+
.highlight .sr { color: #009926 } /* Literal.String.Regex */
|
54
|
+
.highlight .s1 { color: #d14 } /* Literal.String.Single */
|
55
|
+
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
|
56
|
+
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
|
57
|
+
.highlight .vc { color: #008080 } /* Name.Variable.Class */
|
58
|
+
.highlight .vg { color: #008080 } /* Name.Variable.Global */
|
59
|
+
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
|
60
|
+
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
|
@@ -1,3 +1,9 @@
|
|
1
|
+
begin
|
2
|
+
require 'pygments.rb'
|
3
|
+
rescue LoadError
|
4
|
+
# Doesn't have pygments.rb installed
|
5
|
+
end
|
6
|
+
|
1
7
|
module Peek
|
2
8
|
module Rblineprof
|
3
9
|
module ControllerHelpers
|
@@ -9,13 +15,32 @@ module Peek
|
|
9
15
|
|
10
16
|
protected
|
11
17
|
|
18
|
+
def pygmentize?
|
19
|
+
defined?(Pygments)
|
20
|
+
end
|
21
|
+
|
22
|
+
def pygmentize(file_name, code, lexer = nil)
|
23
|
+
if pygmentize? && lexer.present?
|
24
|
+
Pygments.highlight(code, :lexer => lexer_for_filename(file_name))
|
25
|
+
else
|
26
|
+
code
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
12
30
|
def rblineprof_enabled?
|
13
31
|
params[:lineprofiler].present?
|
14
32
|
end
|
15
33
|
|
16
|
-
def
|
34
|
+
def lexer_for_filename(file_name)
|
35
|
+
case file_name
|
36
|
+
when /\.rb$/ then 'ruby'
|
37
|
+
when /\.erb$/ then 'erb'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def rblineprof_profiler_regex
|
17
42
|
escaped_rails_root = Regexp.escape(Rails.root.to_s)
|
18
|
-
|
43
|
+
case params[:lineprofiler]
|
19
44
|
when 'app'
|
20
45
|
%r{^#{escaped_rails_root}/(app|lib)}
|
21
46
|
when 'views'
|
@@ -29,9 +54,11 @@ module Peek
|
|
29
54
|
else
|
30
55
|
%r{^#{escaped_rails_root}/(app|config|lib|vendor/plugin)}
|
31
56
|
end
|
57
|
+
end
|
32
58
|
|
59
|
+
def inject_rblineprof
|
33
60
|
ret = nil
|
34
|
-
profile = lineprof(
|
61
|
+
profile = lineprof(rblineprof_profiler_regex) do
|
35
62
|
ret = yield
|
36
63
|
end
|
37
64
|
|
@@ -41,12 +68,13 @@ module Peek
|
|
41
68
|
min = (params[:lineprofiler_min] || 5).to_i * 1000
|
42
69
|
summary = params[:lineprofiler_summary]
|
43
70
|
|
71
|
+
# Sort each file by the longest calculated time
|
44
72
|
per_file = profile.map do |file, lines|
|
45
73
|
total, child, excl, total_cpu, child_cpu, excl_cpu = lines[0]
|
46
74
|
|
47
75
|
wall = summary == 'exclusive' ? excl : total
|
48
76
|
cpu = summary == 'exclusive' ? excl_cpu : total_cpu
|
49
|
-
idle = summary == 'exclusive' ? (excl-excl_cpu) : (total-total_cpu)
|
77
|
+
idle = summary == 'exclusive' ? (excl - excl_cpu) : (total - total_cpu)
|
50
78
|
|
51
79
|
[
|
52
80
|
file, lines,
|
@@ -57,41 +85,43 @@ module Peek
|
|
57
85
|
|
58
86
|
output = ''
|
59
87
|
per_file.each do |file_name, lines, file_wall, file_cpu, file_idle, file_sort|
|
88
|
+
|
60
89
|
output << "<div class='peek-rblineprof-file'><div class='heading'>"
|
61
90
|
|
62
91
|
show_src = file_sort > min
|
63
92
|
tmpl = show_src ? "<a href='#' class='js-lineprof-file'>%s</a>" : "%s"
|
64
93
|
|
65
94
|
if mode == 'cpu'
|
66
|
-
output << sprintf("<span class='duration'>% 8.1fms + % 8.1fms</span> #{tmpl}
|
95
|
+
output << sprintf("<span class='duration'>% 8.1fms + % 8.1fms</span> #{tmpl}", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', ''))
|
67
96
|
else
|
68
|
-
output << sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}
|
97
|
+
output << sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}", file_wall/1000.0, file_name.sub(Rails.root.to_s + '/', ''))
|
69
98
|
end
|
70
99
|
|
71
|
-
output << "</div>"
|
100
|
+
output << "</div>" # .heading
|
72
101
|
|
73
102
|
next unless show_src
|
74
103
|
|
75
|
-
output << "<
|
104
|
+
output << "<div class='data'>"
|
105
|
+
code = []
|
106
|
+
times = []
|
76
107
|
File.readlines(file_name).each_with_index do |line, i|
|
108
|
+
code << line
|
77
109
|
wall, cpu, calls = lines[i + 1]
|
78
110
|
|
79
111
|
if calls && calls > 0
|
80
112
|
if mode == 'cpu'
|
81
113
|
idle = wall - cpu
|
82
|
-
|
114
|
+
times << sprintf("% 8.1fms + % 8.1fms (% 5d)", cpu / 1000.0, idle / 1000.0, calls)
|
83
115
|
else
|
84
|
-
|
116
|
+
times << sprintf("% 8.1fms (% 5d)", wall / 1000.0, calls)
|
85
117
|
end
|
86
118
|
else
|
87
|
-
|
88
|
-
output << sprintf(" | %s", Rack::Utils.escape_html(line))
|
89
|
-
else
|
90
|
-
output << sprintf(" | %s", Rack::Utils.escape_html(line))
|
91
|
-
end
|
119
|
+
times << ' '
|
92
120
|
end
|
93
121
|
end
|
94
|
-
output << "</pre
|
122
|
+
output << "<pre class='duration'>#{times.join("\n")}</pre>"
|
123
|
+
output << "<div class='code'>#{pygmentize(file_name, code.join, 'ruby')}</div>"
|
124
|
+
output << "</div></div>" # .data then .peek-rblineprof-file
|
95
125
|
end
|
96
126
|
|
97
127
|
response.body += "<div class='peek-rblineprof-modal' id='line-profile'>#{output}</div>".html_safe
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peek-rblineprof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- Rakefile
|
92
92
|
- app/assets/javascripts/peek/views/rblineprof.coffee
|
93
93
|
- app/assets/stylesheets/peek/views/rblineprof.scss
|
94
|
+
- app/assets/stylesheets/peek/views/rblineprof/pygments.scss
|
94
95
|
- app/views/peek/views/_rblineprof.html.erb
|
95
96
|
- lib/peek-rblineprof.rb
|
96
97
|
- lib/peek-rblineprof/railtie.rb
|