rack-lineprof 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03560e926089c3bc3b5661cf3ddb7ae0c70db85e
4
- data.tar.gz: 0a89ee2f73f88de070f9d115285d62bde7d28409
3
+ metadata.gz: 7ad9c752240b1e88b98668f40ae787054efc1a2d
4
+ data.tar.gz: 410e88432c20acaf0ee7a1dfc2acd874286ead2c
5
5
  SHA512:
6
- metadata.gz: 7f3ad2c44b24253ef67769d1c964b38f3b5ad0d4bec7bd0ad779b323157dfdf2025d0830400bc33fb8a707cedfac398c24bc524b9cbccd16fe8bc8163a77e228
7
- data.tar.gz: 034f9ea9d291872f848f752523ab541570b84a138e8987c4811cc02d4b12575ca5c0c9749153c25a0e7da3ee97cf7d41af4edabbd798d0b085f47746549de9ac
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(env)
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
- Thread.new do
31
- sleep 0.01
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
@@ -1,12 +1,12 @@
1
1
  module Rack
2
2
  class Lineprof
3
- class Sample < Struct.new :line, :ms, :code, :level
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 " | % 3i %s", line, code
7
+ sprintf " | % 3i %s", line, code
8
8
  else
9
- sprintf "% 8.1fms | % 3i %s", ms, line, code
9
+ sprintf "% 6.1fms %5i | % 3i %s", ms, calls, line, code
10
10
  end
11
11
 
12
12
  return formatted unless colorize
@@ -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(' ' * 10 + '.' * 7) + "\n"
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 = source_code[line - 1]
51
- parsed << Sample.new(line, ms, code, level)
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 source_code
59
- @source_code ||= ::File.open(file_name, 'r').to_a
59
+ def source_lines
60
+ @source_lines ||= ::File.open(file_name, 'r').to_a
60
61
  end
61
62
 
62
63
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-lineprof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Owen