Skip to content

Commit

Permalink
Highlight sort column in duration tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Feb 8, 2009
1 parent 1c5f430 commit 4f49a5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 6 additions & 2 deletions lib/request_log_analyzer/output/fixed_width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,18 @@ def table(*columns, &block)
bar << colorize(characters[:block] * (width.to_f * (row[index].to_f - column[:treshold])).round, :red)
row_values.push(bar)
else
# Create a bar by combining block characters
row_values.push(characters[:block] * (width.to_f * row[index].to_f).round)
end
else
# Too few characters for a ratio bar. Display nothing
row_values.push('')
end
else
alignment = (columns[index][:align] == :right ? '' : '-')
row_values.push("%#{alignment}#{width}s" % row[index].to_s[0...width])
alignment = (columns[index][:align] == :right ? '' : '-')
cell_value = "%#{alignment}#{width}s" % row[index].to_s[0...width]
cell_value = colorize(cell_value, :bold, :brown) if columns[index][:highlight]
row_values.push(cell_value)
end
end
puts row_values.join(style[:cell_separator] ? " #{characters[:vertical_line]} " : ' ')
Expand Down
16 changes: 9 additions & 7 deletions lib/request_log_analyzer/tracker/duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def max_duration(cat)
categories[cat][:max]
end


def average_duration(cat)
categories[cat][:cumulative] / categories[cat][:hits]
end
Expand Down Expand Up @@ -117,9 +116,12 @@ def report_table(output, amount = 10, options = {}, &block)
output.title(options[:title])

top_categories = @categories.sort { |a, b| yield(b[1]) <=> yield(a[1]) }.slice(0...amount)
output.table({:title => 'Category', :width => :rest}, {:title => 'Hits', :align => :right, :min_width => 4},
{:title => 'Cumulative', :align => :right, :min_width => 10}, {:title => 'Average', :align => :right, :min_width => 8},
{:title => 'Min', :align => :right}, {:title => 'Max', :align => :right}) do |rows|
output.table({:title => 'Category', :width => :rest},
{:title => 'Hits', :align => :right, :highlight => (options[:sort] == :hits), :min_width => 4},
{:title => 'Cumulative', :align => :right, :highlight => (options[:sort] == :cumulative), :min_width => 10},
{:title => 'Average', :align => :right, :highlight => (options[:sort] == :average), :min_width => 8},
{:title => 'Min', :align => :right, :highlight => (options[:sort] == :min)},
{:title => 'Max', :align => :right, :highlight => (options[:sort] == :max)}) do |rows|

top_categories.each do |(cat, info)|
rows << [cat, info[:hits], "%0.02fs" % info[:cumulative], "%0.02fs" % (info[:cumulative] / info[:hits]),
Expand All @@ -138,11 +140,11 @@ def report(output)
options[:report].each do |report|
case report
when :average
report_table(output, options[:top], :title => "#{options[:title]} - top #{options[:top]} by average time") { |cat| cat[:cumulative] / cat[:hits] }
report_table(output, options[:top], :title => "#{options[:title]} - top #{options[:top]} by average time", :sort => :average) { |cat| cat[:cumulative] / cat[:hits] }
when :cumulative
report_table(output, options[:top], :title => "#{options[:title]} - top #{options[:top]} by cumulative time") { |cat| cat[:cumulative] }
report_table(output, options[:top], :title => "#{options[:title]} - top #{options[:top]} by cumulative time", :sort => :cumulative) { |cat| cat[:cumulative] }
when :hits
report_table(output, options[:top], :title => "#{options[:title]} - top #{options[:top]} by hits") { |cat| cat[:hits] }
report_table(output, options[:top], :title => "#{options[:title]} - top #{options[:top]} by hits", :sort => :hits) { |cat| cat[:hits] }
else
raise "Unknown duration report specified: #{report}!"
end
Expand Down

0 comments on commit 4f49a5c

Please sign in to comment.