ngauthier-slow-actions 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +48 -4
- data/VERSION.yml +1 -1
- data/bin/slow-actions +18 -4
- data/lib/slow_actions.rb +18 -6
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -5,10 +5,54 @@ Nick Gauthier (nick@smartlogicsolutions.com)
|
|
5
5
|
Reads a rails app's log file for slow actions
|
6
6
|
|
7
7
|
== Usage
|
8
|
-
./bin/slow-actions.rb path/to/log/file
|
9
8
|
|
10
|
-
|
9
|
+
=== Command line
|
11
10
|
|
11
|
+
slow-actions (--actions | --controllers | --sessions) log_file [log_file ...]
|
12
|
+
You may also specify:
|
13
|
+
--min-cost=FLOAT
|
14
|
+
--min-avg=FLOAT
|
15
|
+
--min-max=FLOAT
|
16
|
+
|
17
|
+
=== Ruby Code
|
18
|
+
|
19
|
+
require 'rubygems'
|
12
20
|
require 'slow_actions'
|
13
|
-
|
14
|
-
|
21
|
+
@sa = SlowActions.new
|
22
|
+
@sa.parse_file(file_path)
|
23
|
+
puts @sa.print_actions
|
24
|
+
|
25
|
+
== Sample output:
|
26
|
+
$> slow-actions --controller my_log_file
|
27
|
+
Cost Average Max
|
28
|
+
+ UsersController (7 entries)
|
29
|
+
| Total: 1.88300 0.96000 6.62000
|
30
|
+
| Render: 1.75600 0.89600 6.24000
|
31
|
+
| DB: 0.29500 0.15000 0.36400
|
32
|
+
|-+ index (3 entries)
|
33
|
+
| | Total: 2.49600 2.20600 6.62000
|
34
|
+
| | Render: 2.35300 2.08000 6.24000
|
35
|
+
| | DB: 0.25700 0.22800 0.36400
|
36
|
+
|-+ winning_history (2 entries)
|
37
|
+
| | Total: 0.03800 0.05200 0.10400
|
38
|
+
| | Render: 0.01100 0.01600 0.03200
|
39
|
+
| | DB: 0.13800 0.18600 0.34800
|
40
|
+
|
41
|
+
+ StaticPagesController (3 entries)
|
42
|
+
| Total: 0.04500 0.04000 0.06000
|
43
|
+
| Render: 0.03100 0.02700 0.04400
|
44
|
+
| DB: 0.08200 0.07300 0.21600
|
45
|
+
|-+ static_hunters_lodge (3 entries)
|
46
|
+
| | Total: 0.04500 0.04000 0.06000
|
47
|
+
| | Render: 0.03100 0.02700 0.04400
|
48
|
+
| | DB: 0.08200 0.07300 0.21600
|
49
|
+
|
50
|
+
+ SessionsController (5 entries)
|
51
|
+
| Total: 0.03300 0.02000 0.06400
|
52
|
+
| Render: 0.00700 0.00400 0.01600
|
53
|
+
| DB: 0.01500 0.00900 0.04800
|
54
|
+
|-+ create (2 entries)
|
55
|
+
| | Total: 0.03400 0.04600 0.06400
|
56
|
+
| | Render: 0.00100 0.00200 0.00400
|
57
|
+
| | DB: 0.02600 0.03600 0.04800
|
58
|
+
|
data/VERSION.yml
CHANGED
data/bin/slow-actions
CHANGED
@@ -6,20 +6,34 @@ ARGV.select{|arg| arg[0,2] != "--"}.each do |file|
|
|
6
6
|
@sa.parse_file(file)
|
7
7
|
end
|
8
8
|
|
9
|
+
opts = {}
|
10
|
+
mincost = ARGV.detect{|arg| arg =~ /--min-cost=(\S+)/ }
|
11
|
+
opts[:mincost] = $1.to_f if mincost
|
12
|
+
|
13
|
+
minavg = ARGV.detect{|arg| arg =~ /--min-avg=(\S+)/ }
|
14
|
+
opts[:minavg] = $1.to_f if minavg
|
15
|
+
|
16
|
+
minmax = ARGV.detect{|arg| arg =~ /--min-max=(\S+)/ }
|
17
|
+
opts[:minmax] = $1.to_f if minmax
|
18
|
+
|
9
19
|
output = []
|
10
20
|
if (ARGV.include? "--actions")
|
11
|
-
output << @sa.print_actions
|
21
|
+
output << @sa.print_actions(opts)
|
12
22
|
end
|
13
23
|
if (ARGV.include? "--controllers")
|
14
|
-
output << @sa.print_controller_tree
|
24
|
+
output << @sa.print_controller_tree(opts)
|
15
25
|
end
|
16
26
|
if (ARGV.include? "--sessions")
|
17
|
-
output << @sa.print_sessions
|
27
|
+
output << @sa.print_sessions(opts)
|
18
28
|
end
|
19
29
|
|
20
30
|
|
21
31
|
if output.size == 0
|
22
|
-
puts "Usage: slow-actions (--actions | --controllers | --sessions) log_file"
|
32
|
+
puts "Usage: slow-actions (--actions | --controllers | --sessions) log_file [log_file ...]"
|
33
|
+
puts "You may also specify:"
|
34
|
+
puts "\t--min-cost=FLOAT"
|
35
|
+
puts "\t--min-avg=FLOAT"
|
36
|
+
puts "\t--min-max=FLOAT"
|
23
37
|
else
|
24
38
|
puts output.join("\n\n")
|
25
39
|
end
|
data/lib/slow_actions.rb
CHANGED
@@ -18,10 +18,13 @@ class SlowActions
|
|
18
18
|
return @log_entries
|
19
19
|
end
|
20
20
|
|
21
|
-
def print_actions
|
21
|
+
def print_actions(opts = {})
|
22
22
|
str = ""
|
23
|
-
str += "
|
23
|
+
str += " Cost Average Max\n"
|
24
24
|
actions.sort{|x,y| y.total_cost <=> x.total_cost}.each do |a|
|
25
|
+
next if opts[:mincost] and a.total_cost < opts[:mincost]
|
26
|
+
next if opts[:minavg] and a.total_avg < opts[:minavg]
|
27
|
+
next if opts[:minmax] and a.total_max < opts[:minmax]
|
25
28
|
str += "- #{a.controller.name} : #{a.name} (#{a.log_entries.size} entries)\n"
|
26
29
|
str += " Total: #{ftos a.total_cost}#{ftos a.total_avg}#{ftos a.total_max}\n"
|
27
30
|
str += " Render: #{ftos a.render_cost}#{ftos a.render_avg}#{ftos a.render_max}\n"
|
@@ -31,15 +34,21 @@ class SlowActions
|
|
31
34
|
return str
|
32
35
|
end
|
33
36
|
|
34
|
-
def print_controller_tree
|
37
|
+
def print_controller_tree(opts = {})
|
35
38
|
str = ""
|
36
|
-
str += "
|
39
|
+
str += " Cost Average Max\n"
|
37
40
|
controllers.sort{|x,y| y.total_cost <=> x.total_cost}.each do |c|
|
41
|
+
next if opts[:mincost] and c.total_cost < opts[:mincost]
|
42
|
+
next if opts[:minavg] and c.total_avg < opts[:minavg]
|
43
|
+
next if opts[:minmax] and c.total_max < opts[:minmax]
|
38
44
|
str += "+ #{c.name} (#{c.log_entries.size} entries)\n"
|
39
45
|
str += "| Total: #{ftos c.total_cost}#{ftos c.total_avg}#{ftos c.total_max}\n"
|
40
46
|
str += "| Render: #{ftos c.render_cost}#{ftos c.render_avg}#{ftos c.render_max}\n"
|
41
47
|
str += "| DB: #{ftos c.db_cost}#{ftos c.db_avg}#{ftos c.db_max}\n"
|
42
48
|
c.actions.sort{|x,y| y.total_cost <=> x.total_cost}.each do |a|
|
49
|
+
next if opts[:mincost] and a.total_cost < opts[:mincost]
|
50
|
+
next if opts[:minavg] and a.total_avg < opts[:minavg]
|
51
|
+
next if opts[:minmax] and a.total_max < opts[:minmax]
|
43
52
|
str += "|-+ #{a.name} (#{a.log_entries.size} entries)\n"
|
44
53
|
str += "| | Total: #{ftos a.total_cost}#{ftos a.total_avg}#{ftos a.total_max}\n"
|
45
54
|
str += "| | Render: #{ftos a.render_cost}#{ftos a.render_avg}#{ftos a.render_max}\n"
|
@@ -50,10 +59,13 @@ class SlowActions
|
|
50
59
|
return str
|
51
60
|
end
|
52
61
|
|
53
|
-
def print_sessions
|
62
|
+
def print_sessions(opts = {})
|
54
63
|
str = ""
|
55
|
-
str += "
|
64
|
+
str += " Cost Average Max\n"
|
56
65
|
sessions.sort{|x,y| y.total_cost <=> x.total_cost}.each do |s|
|
66
|
+
next if opts[:mincost] and s.total_cost < opts[:mincost]
|
67
|
+
next if opts[:minavg] and s.total_avg < opts[:minavg]
|
68
|
+
next if opts[:minmax] and s.total_max < opts[:minmax]
|
57
69
|
str += "+ #{s.name} (#{s.log_entries.size} entries)\n"
|
58
70
|
str += "| Total: #{ftos s.total_cost}#{ftos s.total_avg}#{ftos s.total_max}\n"
|
59
71
|
str += "| Render: #{ftos s.render_cost}#{ftos s.render_avg}#{ftos s.render_max}\n"
|