@@ -3,6 +3,8 @@ module Rblineprof
3
3
module CustomControllerHelpers
4
4
extend ActiveSupport ::Concern
5
5
6
+ # This will become useless once https://github.com/peek/peek-rblineprof/pull/5
7
+ # is merged
6
8
def pygmentize ( file_name , code , lexer = nil )
7
9
if lexer . present?
8
10
Gitlab ::Highlight . highlight ( file_name , code )
@@ -11,7 +13,7 @@ def pygmentize(file_name, code, lexer = nil)
11
13
end
12
14
end
13
15
14
- # rubocop:disable Metrics/AbcSize
16
+ # rubocop:disable all
15
17
def inject_rblineprof
16
18
ret = nil
17
19
profile = lineprof ( rblineprof_profiler_regex ) do
@@ -26,43 +28,32 @@ def inject_rblineprof
26
28
27
29
# Sort each file by the longest calculated time
28
30
per_file = profile . map do |file , lines |
29
- total , _child , excl , total_cpu , _child_cpu , excl_cpu = lines [ 0 ]
31
+ total , child , excl , total_cpu , child_cpu , excl_cpu = lines [ 0 ]
30
32
31
33
wall = summary == 'exclusive' ? excl : total
32
34
cpu = summary == 'exclusive' ? excl_cpu : total_cpu
33
35
idle = summary == 'exclusive' ? ( excl - excl_cpu ) : ( total - total_cpu )
34
36
35
- sort_method =
36
- case sort
37
- when 'idle'
38
- idle
39
- when 'cpu'
40
- cpu
41
- else
42
- wall
43
- end
44
-
45
37
[
46
38
file , lines ,
47
39
wall , cpu , idle ,
48
- sort_method
40
+ sort == 'idle' ? idle : sort == 'cpu' ? cpu : wall
49
41
]
50
- end
51
- per_file = per_file . sort_by { |_a , _b , _c , _d , _e , f | -f }
42
+ end . sort_by { |a , b , c , d , e , f | -f }
52
43
53
44
output = ''
54
45
per_file . each do |file_name , lines , file_wall , file_cpu , file_idle , file_sort |
46
+
55
47
output << "<div class='peek-rblineprof-file'><div class='heading'>"
56
48
57
49
show_src = file_sort > min
58
50
tmpl = show_src ? "<a href='#' class='js-lineprof-file'>%s</a>" : "%s"
59
51
60
- output <<
61
- if mode == 'cpu'
62
- 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 + '/' , '' ) )
63
- else
64
- sprintf ( "<span class='duration'>% 8.1fms</span> #{ tmpl } " , file_wall / 1000.0 , file_name . sub ( Rails . root . to_s + '/' , '' ) )
65
- end
52
+ if mode == 'cpu'
53
+ 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 + '/' , '' ) )
54
+ else
55
+ output << sprintf ( "<span class='duration'>% 8.1fms</span> #{ tmpl } " , file_wall /1000.0 , file_name . sub ( Rails . root . to_s + '/' , '' ) )
56
+ end
66
57
67
58
output << "</div>" # .heading
68
59
@@ -89,6 +80,8 @@ def inject_rblineprof
89
80
output << "<pre class='duration'>#{ times . join ( "\n " ) } </pre>"
90
81
# The following line was changed from
91
82
# https://github.com/peek/peek-rblineprof/blob/8d3b7a283a27de2f40abda45974516693d882258/lib/peek/rblineprof/controller_helpers.rb#L125
83
+ # This will become useless once https://github.com/peek/peek-rblineprof/pull/16
84
+ # is merged and is implemented.
92
85
output << "<pre class='code highlight white'>#{ pygmentize ( file_name , code . join , 'ruby' ) } </pre>"
93
86
output << "</div></div>" # .data then .peek-rblineprof-file
94
87
end
0 commit comments