Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Created RailsAnalyzer class to wrap top-level logic.
Browse files Browse the repository at this point in the history
Output to console has been reduced to top-level status info
  • Loading branch information
Narnach committed Sep 15, 2008
1 parent ea478ff commit db8e8ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
24 changes: 2 additions & 22 deletions bin/rails_analyzer
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
#!/usr/bin/env ruby
require 'uri'
require 'rubygems'
require 'activesupport'
require 'rails_analyzer'
require 'time_stats'
require 'hit_stats'

puts
puts "Rails log analyzer"
puts "Analyzes a number of rails log files and compiles an overview list."
puts
logs=[]
if $*.size==0
logs=["log/production.log"]
else
logs=$*
end
logs.each {|l| puts "Using log: #{l}"}
puts

TimeStats.generate(logs)
puts 'Wrote time-based logs'

HitStats.generate(logs)
ra = RailsAnalyzer.new(ARGV)
ra.generate_reports
3 changes: 0 additions & 3 deletions lib/hit_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ def parse_logs
end

def save_reports
puts "------\nResults\n-----"
puts
File.open("log_hits.txt","wb") {|file| file.puts PrettyLog.to_s(:size) }
File.open("log_avg.txt","wb") {|file| file.puts PrettyLog.to_s(:avg) }
File.open("log_sum.txt","wb") {|file| file.puts PrettyLog.to_s(:sum) }
File.open("log_median.txt","wb") {|file| file.puts PrettyLog.to_s(:median) }
File.open("log_stddev.txt","wb") {|file| file.puts PrettyLog.to_s(:stddev) }
File.open('log_sum_with_params.txt', 'wb') {|file| file.puts ParamLog.to_s(:sum)}
puts "Pretty log can be found in log_*.txt"
end

protected
Expand Down
26 changes: 26 additions & 0 deletions lib/rails_analyzer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
require 'rubygems'
require 'activesupport'
require 'uri'
require 'float_ext'
require 'array_ext'
require 'pretty_log'
require 'param_log'
require 'time_stats'
require 'hit_stats'

class RailsAnalyzer
attr_accessor :logs

def initialize(logs=[])
@logs = logs
@logs = %w[log/production.log] if logs.size==0
end

def generate_reports
puts "RailsAnalyzer"
puts "Analyzes the following Rails log files:"
puts logs.map{|l| ' %s' % l}.join("\n")

puts 'Generating time-based reports'
TimeStats.generate(logs)

puts 'Generating hit-based reports'
HitStats.generate(logs)
end
end

0 comments on commit db8e8ed

Please sign in to comment.