logreport
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:2k
源码类别:

Ajax

开发平台:

Others

  1. #!/usr/bin/ruby
  2. latest=[]
  3. class CallNode
  4.   attr_accessor :name, :time, :children, :queries, :query_time
  5.   
  6.   def initialize(name)
  7.     @name = name
  8.     @children = Array.new
  9.     @queries = 0
  10.     @query_time = 0
  11.     @time = 0
  12.   end
  13.   
  14.   def to_s
  15.     name
  16.   end
  17.   
  18.   def print_tree(depth)
  19.     child_time=children.inject(0) {|total,c| c.time.to_f + total} || 0
  20.     printf "%s %-40s    %f  q=%-3d (%f) o=%fn",
  21.       " "*depth,
  22.       name,
  23.       time,
  24.       queries,
  25.       query_time,
  26.       time-child_time-query_time
  27.     
  28.     #" " "*depth+"** #{name}              #{time}   #{time-child_time}  #{queries} queries (#{query_time})"
  29.     children.each do |child|
  30.       child.print_tree(depth+1)
  31.     end
  32.   end
  33.   
  34.   def averages(average_hash = Hash.new)
  35.     average_hash[name] ||= Array.new
  36.     average_hash[name].push time
  37.     children.each { |child| child.averages(average_hash) }
  38.     average_hash
  39.   end
  40. end
  41. def putsi(depth,string)
  42.   puts " "*depth + string
  43. end
  44. root=CallNode.new('ROOT')
  45. latest=[root]
  46. ARGF.each_line do |line|
  47.   case line
  48.   when /^Processing ([a-zA-Z0-9_]+#[a-z_]+)/
  49. #    putsi latest.size, "Starting #{$1}"
  50.     node = CallNode.new($1)
  51.     latest.last.children << node
  52.     latest.push node
  53.   when /^End of component rendering/
  54.     nil
  55.   when /(([0-9.]+)).*SELECT/
  56.     latest.last.queries += 1
  57.     latest.last.query_time += $1.to_f
  58.   when /^Completed in ([0-9.]+)/
  59.     latest.last.time=$1.to_f
  60.     latest.pop
  61.   when /^BENCHMARK: (.*) ((.*))/
  62.     node = CallNode.new($1)
  63.     node.time = $2.to_f
  64.     latest.last.children << node
  65.   end
  66. end
  67. root.print_tree(0)
  68. puts "nAverages:"
  69. averages = root.averages
  70. averages.keys.sort.each do |name|
  71.   printf " %-40s  %8fn",name,(averages[name].inject(0) {|sum,time| sum+time})/averages[name].size
  72. end