rawk_log 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rawk_log/stat.rb +4 -2
- data/lib/rawk_log/stat_hash.rb +3 -1
- data/lib/rawk_log/version.rb +1 -1
- metadata +1 -1
data/lib/rawk_log/stat.rb
CHANGED
@@ -2,6 +2,8 @@ module RawkLog
|
|
2
2
|
|
3
3
|
class Stat
|
4
4
|
|
5
|
+
DEFAULT_LABEL_SIZE = 30
|
6
|
+
|
5
7
|
HEADER = "Count Sum Max Median Avg Min Std"
|
6
8
|
HEADER_NEW_LOG_FORMAT = "Count Sum(s) Max Median Avg Min Std"
|
7
9
|
|
@@ -28,7 +30,7 @@ module RawkLog
|
|
28
30
|
@values << value
|
29
31
|
end
|
30
32
|
|
31
|
-
def header(label_size =
|
33
|
+
def header(label_size = DEFAULT_LABEL_SIZE)
|
32
34
|
header = @new_log_format ? HEADER_NEW_LOG_FORMAT : HEADER
|
33
35
|
sprintf "%*s %s" % [-label_size, "Request", header]
|
34
36
|
end
|
@@ -71,7 +73,7 @@ module RawkLog
|
|
71
73
|
Math.sqrt((@sum_squares - (@sum*@sum/@count))/ (@count) )
|
72
74
|
end
|
73
75
|
|
74
|
-
def to_s(label_size =
|
76
|
+
def to_s(label_size = DEFAULT_LABEL_SIZE)
|
75
77
|
if count > 0
|
76
78
|
if @new_log_format
|
77
79
|
sprintf("%*s %6d %7.2f %7d %7d %7d %7d %7d",-label_size, key,count,(sum.to_f/1000),max,median,average,min,standard_deviation)
|
data/lib/rawk_log/stat_hash.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rawk_log/stat'
|
|
2
2
|
|
3
3
|
module RawkLog
|
4
4
|
class StatHash
|
5
|
+
|
5
6
|
def initialize
|
6
7
|
@stats = Hash.new
|
7
8
|
end
|
@@ -17,7 +18,7 @@ module RawkLog
|
|
17
18
|
|
18
19
|
def print(args={:sort_by=>'key',:ascending=>true,:limit=>nil})
|
19
20
|
values = @stats.values
|
20
|
-
return
|
21
|
+
return Stat::DEFAULT_LABEL_SIZE if values.empty?
|
21
22
|
order = (args[:ascending] || args[:ascending].nil?) ? 1 : -1
|
22
23
|
values.sort! {|a,b|
|
23
24
|
as = a.send(args[:sort_by])
|
@@ -30,6 +31,7 @@ module RawkLog
|
|
30
31
|
values = values[0,limit]
|
31
32
|
end
|
32
33
|
@label_size = values.collect{|v| v.key.size }.max
|
34
|
+
@label_size = Stat::DEFAULT_LABEL_SIZE if @label_size < Stat::DEFAULT_LABEL_SIZE
|
33
35
|
puts values[0].header(@label_size)
|
34
36
|
for stat in values
|
35
37
|
puts stat.to_s(@label_size)
|
data/lib/rawk_log/version.rb
CHANGED