Friday, April 15, 2011

Aggeragte Performance Profiling Data using Ruby

 require 'csv'  
 def perflogana(csvfile)  
  #initial an Two-dimensional array
   a = Array.new(1){ Array.new(4) }  
   a[0][0] = '';  # Transaction name 
   a[0][1] = 0;  # Total Response time
   a[0][2] = 0;  # Invocations
   a[0][3] = 0;  # Average Response Time
   i = 0;  
   t = 0;  
   n = 0;  
   flag = 'unfound'  
  # Read each line from CSV file  
  CSV.foreach(csvfile) do |row|  
   if (!row[1].nil?) 
      #Trim Oid for the URL using regex
      if row[1].gsub!(/\/([\d\D][^\/]+?-)+\S*/, "")
         row[1] << ")"
      end 
    b = 0;  
    # modify total response time and invocations if current line being found  
    while b <= i  
     if !a[b][0].eql?(row[1])  
       b= b+1;  
       next;  
     else  
       # modify total response time and invocations  
       a[b][1] = a[b][1] + row[2].to_s.to_i;  
       a[b][2] = a[b][2] + 1;  
       flag = 'find'  
       break;  
     end  
    end  
    #append a new line if new transaction being found  
    if flag.eql?('unfound')  
      a << [row[1],row[2].to_s.to_i,1]  
      i = i+1;  
    end  
    flag = 'unfound'  
   end  
  end  
  a.shift  
  j = a.size  
  #calculate average response time for each transaction  
  while t < j  
   a[t][3] = a[t][1]/a[t][2]  
   t = t+1;  
  end  
  # sort by avg time and print to console  
  while n < j  
   print a[n][0],",",a[n][1],",",a[n][2],",",a[n][3]  
   puts  
   n = n + 1  
  end  
 end  
 perflogana("D:\\GWT_automation\\perf\.csv");  

No comments:

Post a Comment