Skip to content
Browse files

Improved duration value display.

  • Loading branch information...
1 parent f9cf629 commit 06405bbc69a06a707e22880a21cb390ea6e0df50 @wvanbergen wvanbergen committed Sep 25, 2009
Showing with 23 additions and 1 deletion.
  1. +6 −1 lib/request_log_analyzer/tracker/duration.rb
  2. +17 −0 spec/unit/tracker/duration_tracker_spec.rb
View
7 lib/request_log_analyzer/tracker/duration.rb
@@ -71,7 +71,12 @@ def report_table(output, sort, options = {}, &block)
# Display a duration
def display_value(time)
- time.nil? ? '-' : "%0.02fs" % time
+ case time
+ when nil then '-'
+ when 0...60 then "%0.02fs" % time
+ when 60...3600 then "%dm%02ds" % [time / 60, (time % 60).round]
+ else "%dh%02dm%02ds" % [time / 3600, (time % 3600) / 60, (time % 60).round]
+ end
end
# Generate a request duration report to the given output object
View
17 spec/unit/tracker/duration_tracker_spec.rb
@@ -110,4 +110,21 @@
@tracker.to_yaml_object.should == {"a"=>{:hits=>1, :min=>0.2, :mean=>0.2, :max=>0.2, :sum_of_squares=>0.0, :sum=>0.2}, "b"=>{:hits=>1, :min=>0.2, :mean=>0.2, :max=>0.2, :sum_of_squares=>0.0, :sum=>0.2}}
end
end
+
+ describe '#display_value' do
+ before(:each) { @tracker = RequestLogAnalyzer::Tracker::Duration.new(:category => :category, :duration => :duration) }
+
+ it "should only display seconds when time < 60" do
+ @tracker.display_value(33.12).should == '33.12s'
+ end
+
+ it "should display minutes and wholeseconds when time > 60" do
+ @tracker.display_value(63.12).should == '1m03s'
+ end
+
+ it "should display minutes and wholeseconds when time > 60" do
+ @tracker.display_value(3601.12).should == '1h00m01s'
+ end
+
+ end
end

0 comments on commit 06405bb

Please sign in to comment.
Something went wrong with that request. Please try again.