ngauthier-slow-actions 0.3.2 → 0.3.3

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.rdoc CHANGED
@@ -25,36 +25,56 @@ Reads a rails app's log file for slow actions
25
25
  puts @sa.print_actions
26
26
 
27
27
  == Sample output:
28
- $> slow-actions --controller my_log_file
28
+ $> slow-actions --actions --min-cost=2 test/data/development.log
29
+ Cost Average Max
30
+ - UsersController : game_history (22 entries, 0% Error)
31
+ Total: 11275.447 3642.437 12728.0
32
+ Render: 7.20300 2.32700 17.2450
33
+ DB: 10.5020 3.39200 10.0000
34
+
35
+ - QuestionsController : refresh_index_table (89 entries, 0% Error)
36
+ Total: 908.494 202.348 307.000
37
+ Render: 0.00000 0.00000 0.00000
38
+ DB: 32.5880 7.25800 10.0000
39
+
40
+ - UsersController : show (128 entries, 0% Error)
41
+ Total: 664.292 136.888 2680.00
42
+ Render: 0.33500 0.06900 3.41000
43
+ DB: 18.2330 3.75700 114.000
44
+
45
+ $> slow-actions --controllers --min-cost=2 test/data/development.log > ~/Desktop/sa-controllers.txt
29
46
  Cost Average Max
30
- + UsersController (7 entries)
31
- | Total: 1.88300 0.96000 6.62000
32
- | Render: 1.75600 0.89600 6.24000
33
- | DB: 0.29500 0.15000 0.36400
34
- |-+ index (3 entries)
35
- | | Total: 2.49600 2.20600 6.62000
36
- | | Render: 2.35300 2.08000 6.24000
37
- | | DB: 0.25700 0.22800 0.36400
38
- |-+ winning_history (2 entries)
39
- | | Total: 0.03800 0.05200 0.10400
40
- | | Render: 0.01100 0.01600 0.03200
41
- | | DB: 0.13800 0.18600 0.34800
42
-
43
- + StaticPagesController (3 entries)
44
- | Total: 0.04500 0.04000 0.06000
45
- | Render: 0.03100 0.02700 0.04400
46
- | DB: 0.08200 0.07300 0.21600
47
- |-+ static_hunters_lodge (3 entries)
48
- | | Total: 0.04500 0.04000 0.06000
49
- | | Render: 0.03100 0.02700 0.04400
50
- | | DB: 0.08200 0.07300 0.21600
51
-
52
- + SessionsController (5 entries)
53
- | Total: 0.03300 0.02000 0.06400
54
- | Render: 0.00700 0.00400 0.01600
55
- | DB: 0.01500 0.00900 0.04800
56
- |-+ create (2 entries)
57
- | | Total: 0.03400 0.04600 0.06400
58
- | | Render: 0.00100 0.00200 0.00400
59
- | | DB: 0.02600 0.03600 0.04800
47
+ + UsersController (236 entries, 0% Error)
48
+ | Total: 2165.375 396.279 12728.0
49
+ | Render: 1.63400 0.29900 17.2450
50
+ | DB: 7.03400 1.28700 114.000
51
+ |-+ game_history (22 entries, 0% Error)
52
+ | | Total: 11275.447 3642.437 12728.0
53
+ | | Render: 7.20300 2.32700 17.2450
54
+ | | DB: 10.5020 3.39200 10.0000
55
+ |-+ show (128 entries, 0% Error)
56
+ | | Total: 664.292 136.888 2680.00
57
+ | | Render: 0.33500 0.06900 3.41000
58
+ | | DB: 18.2330 3.75700 114.000
59
+ |-+ index (812 entries, 51% Error)
60
+ | | Total: 465.660 69.5050 1922.00
61
+ | | Render: 0.30100 0.04500 2.39600
62
+ | | DB: 40.9320 6.10900 1164.00
63
+
64
+ $> slow-actions --sessions --min-cost=2 test/data/development.log > ~/Desktop/sa-sessions.txt
65
+ Cost Average Max
66
+ + d2dac54dc3816195ed9ef083e2811c61 (89 entries, 60% Error)
67
+ | Total: 10923.296 2432.935 12603.0
68
+ | Render: 0.00000 0.00000 0.00000
69
+ | DB: 51.9520 11.5710 53.0000
70
+
71
+ + 3283ca1f8b1039f8c4403cbc7f9941c9 (18 entries, 5% Error)
72
+ | Total: 2179.158 752.494 12728.0
73
+ | Render: 9.70500 3.35100 17.2450
74
+ | DB: 2.93100 1.01200 10.0000
75
+
76
+ + 867bc340e6d65e673f29c57189feaf2b (133 entries, 0% Error)
77
+ | Total: 1083.138 221.450 386.000
78
+ | Render: 0.00000 0.00000 0.00000
79
+ | DB: 44.2030 9.03700 90.0000
60
80
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 3
data/lib/slow_actions.rb CHANGED
@@ -46,7 +46,8 @@ class SlowActions
46
46
  next if opts[:mincost] and a.total_cost < opts[:mincost]
47
47
  next if opts[:minavg] and a.total_avg < opts[:minavg]
48
48
  next if opts[:minmax] and a.total_max < opts[:minmax]
49
- str += "- #{a.controller.name} : #{a.name} (#{a.log_entries.size} entries)\n"
49
+ str += "- #{a.controller.name} : #{a.name} "
50
+ str += "(#{a.log_entries.size} entries, #{(a.error_avg*100).to_i}% Error)\n"
50
51
  str += " Total: #{ftos a.total_cost}#{ftos a.total_avg}#{ftos a.total_max}\n"
51
52
  str += " Render: #{ftos a.render_cost}#{ftos a.render_avg}#{ftos a.render_max}\n"
52
53
  str += " DB: #{ftos a.db_cost}#{ftos a.db_avg}#{ftos a.db_max}\n"
@@ -63,7 +64,7 @@ class SlowActions
63
64
  next if opts[:mincost] and c.total_cost < opts[:mincost]
64
65
  next if opts[:minavg] and c.total_avg < opts[:minavg]
65
66
  next if opts[:minmax] and c.total_max < opts[:minmax]
66
- str += "+ #{c.name} (#{c.log_entries.size} entries)\n"
67
+ str += "+ #{c.name} (#{c.log_entries.size} entries, #{(c.error_avg*100).to_i}% Error)\n"
67
68
  str += "| Total: #{ftos c.total_cost}#{ftos c.total_avg}#{ftos c.total_max}\n"
68
69
  str += "| Render: #{ftos c.render_cost}#{ftos c.render_avg}#{ftos c.render_max}\n"
69
70
  str += "| DB: #{ftos c.db_cost}#{ftos c.db_avg}#{ftos c.db_max}\n"
@@ -71,7 +72,7 @@ class SlowActions
71
72
  next if opts[:mincost] and a.total_cost < opts[:mincost]
72
73
  next if opts[:minavg] and a.total_avg < opts[:minavg]
73
74
  next if opts[:minmax] and a.total_max < opts[:minmax]
74
- str += "|-+ #{a.name} (#{a.log_entries.size} entries)\n"
75
+ str += "|-+ #{a.name} (#{a.log_entries.size} entries, #{(a.error_avg*100).to_i}% Error)\n"
75
76
  str += "| | Total: #{ftos a.total_cost}#{ftos a.total_avg}#{ftos a.total_max}\n"
76
77
  str += "| | Render: #{ftos a.render_cost}#{ftos a.render_avg}#{ftos a.render_max}\n"
77
78
  str += "| | DB: #{ftos a.db_cost}#{ftos a.db_avg}#{ftos a.db_max}\n"
@@ -89,7 +90,7 @@ class SlowActions
89
90
  next if opts[:mincost] and s.total_cost < opts[:mincost]
90
91
  next if opts[:minavg] and s.total_avg < opts[:minavg]
91
92
  next if opts[:minmax] and s.total_max < opts[:minmax]
92
- str += "+ #{s.name} (#{s.log_entries.size} entries)\n"
93
+ str += "+ #{s.name} (#{s.log_entries.size} entries, #{(s.error_avg*100).to_i}% Error)\n"
93
94
  str += "| Total: #{ftos s.total_cost}#{ftos s.total_avg}#{ftos s.total_max}\n"
94
95
  str += "| Render: #{ftos s.render_cost}#{ftos s.render_avg}#{ftos s.render_max}\n"
95
96
  str += "| DB: #{ftos s.db_cost}#{ftos s.db_avg}#{ftos s.db_max}\n"
@@ -160,6 +161,9 @@ class SlowActions
160
161
  @controllers.values.each{|c| c.compute_times}
161
162
  @actions.values.each{|a| a.compute_times}
162
163
  @sessions.values.each{|s| s.compute_times}
164
+
165
+ # return something simple. This helps irb not barf on itself trying to print everything
166
+ return true
163
167
  end
164
168
 
165
169
  # Convert a float to 7 places padded with zeros then one space
@@ -49,9 +49,9 @@ module Computable
49
49
  @total_max = la.duration if la.duration > @total_max
50
50
  end
51
51
 
52
- @render_avg /= @log_entries.size.to_f
53
- @db_avg /= @log_entries.size.to_f
54
- @total_avg /= @log_entries.size.to_f
52
+ @render_avg /= @log_entries.size.to_f - @error_avg + 0.0001
53
+ @db_avg /= @log_entries.size.to_f - @error_avg + 0.0001
54
+ @total_avg /= @log_entries.size.to_f - @error_avg + 0.0001
55
55
  @error_avg /= @log_entries.size.to_f
56
56
 
57
57
  # using math.log allows us to smooth out the score between
@@ -35,8 +35,7 @@ class SlowActions
35
35
 
36
36
  # Whether or not this #LogEntry was an error
37
37
  def error?
38
- return false if error_text.nil?
39
- return false if error_text.empty?
38
+ return false if error_text.nil? or error_text.empty?
40
39
  return true
41
40
  end
42
41
  end
@@ -89,12 +89,12 @@ class SlowActions
89
89
  while line == "\n"
90
90
  line = @file.readline
91
91
  end
92
- error_txt = ""
92
+ error_txt = []
93
93
  while line != "\n"
94
94
  line = @file.readline
95
- error_txt += line
95
+ error_txt.push line
96
96
  end
97
- return error_txt
97
+ return error_txt.join("")
98
98
  end
99
99
  end
100
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngauthier-slow-actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gauthier