rack-lineprof 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/rack/lineprof.rb +3 -6
- data/lib/rack/lineprof/sample.rb +3 -3
- data/lib/rack/lineprof/source.rb +6 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ad9c752240b1e88b98668f40ae787054efc1a2d
|
4
|
+
data.tar.gz: 410e88432c20acaf0ee7a1dfc2acd874286ead2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1fdeecc6a26e26ed2334f526d1d8f20ff9450295b7155f996cc485c1b3ef7b10f6e3059a2d5aabccc3bf1c4423546312a6e0248e769e713b7f1dacd1e8c81f1
|
7
|
+
data.tar.gz: ecbdbd6b97797def5853af8ee37b1ef02296de2634f85c36a2196dd999be4762d6ad3babc625fd04db1d434c799d38bcf6c518ad93313aff77f7bf3974ee59a8
|
data/lib/rack/lineprof.rb
CHANGED
@@ -19,7 +19,7 @@ module Rack
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def call env
|
22
|
-
request = Rack::Request.new
|
22
|
+
request = Rack::Request.new env
|
23
23
|
matcher = request.params['lineprof']
|
24
24
|
|
25
25
|
return @app.call env unless matcher
|
@@ -27,11 +27,8 @@ module Rack
|
|
27
27
|
response = nil
|
28
28
|
profile = lineprof(%r{#{matcher}}) { response = @app.call env }
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
puts Term::ANSIColor.blue("\n[Rack::Lineprof] #{'=' * 63}") + "\n\n" +
|
33
|
-
format_profile(profile) + "\n"
|
34
|
-
end
|
30
|
+
puts Term::ANSIColor.blue("\n[Rack::Lineprof] #{'=' * 63}") + "\n\n" +
|
31
|
+
format_profile(profile) + "\n"
|
35
32
|
|
36
33
|
response
|
37
34
|
end
|
data/lib/rack/lineprof/sample.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rack
|
2
2
|
class Lineprof
|
3
|
-
class Sample < Struct.new :
|
3
|
+
class Sample < Struct.new :ms, :calls, :line, :code, :level
|
4
4
|
|
5
5
|
def format colorize = true
|
6
6
|
formatted = if level == CONTEXT
|
7
|
-
sprintf "
|
7
|
+
sprintf " | % 3i %s", line, code
|
8
8
|
else
|
9
|
-
sprintf "%
|
9
|
+
sprintf "% 6.1fms %5i | % 3i %s", ms, calls, line, code
|
10
10
|
end
|
11
11
|
|
12
12
|
return formatted unless colorize
|
data/lib/rack/lineprof/source.rb
CHANGED
@@ -16,7 +16,7 @@ module Rack
|
|
16
16
|
prev_line = samples.first.line - 1
|
17
17
|
samples.each do |sample|
|
18
18
|
if sample.line != prev_line + 1
|
19
|
-
formatted << color.intense_black(' ' *
|
19
|
+
formatted << color.intense_black(' ' * 14 + '.' * 7) + "\n"
|
20
20
|
end
|
21
21
|
prev_line = sample.line
|
22
22
|
|
@@ -34,6 +34,7 @@ module Rack
|
|
34
34
|
next if line == 0 # drop file info
|
35
35
|
|
36
36
|
ms = sample[0] / 1000.0
|
37
|
+
calls = sample[2]
|
37
38
|
|
38
39
|
clocked = ms >= 0.2 # info
|
39
40
|
near_clocked = (line-context..line+context).any? do |near|
|
@@ -47,16 +48,16 @@ module Rack
|
|
47
48
|
threshold = thresholds.detect { |boundary, _| ms > boundary }
|
48
49
|
level = threshold ? threshold.last : CONTEXT
|
49
50
|
|
50
|
-
next unless code =
|
51
|
-
parsed << Sample.new(
|
51
|
+
next unless code = source_lines[line - 1]
|
52
|
+
parsed << Sample.new(ms, calls, line, code, level)
|
52
53
|
end
|
53
54
|
|
54
55
|
parsed
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
def
|
59
|
-
@
|
59
|
+
def source_lines
|
60
|
+
@source_lines ||= ::File.open(file_name, 'r').to_a
|
60
61
|
end
|
61
62
|
|
62
63
|
private
|