Blame view

utils/pp_perfs.rb 1.06 KB
1b1e928cc   glaville   initial import of...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  #!/usr/bin/env ruby
  # encoding: UTF-8
  
  class String
      def / other
          File.join(self, other)
      end
  end
  
  def mean(values)
      values.inject(:+) / values.size.to_f
  end
  
  def parse_output(file)
      values = Hash.new { |h, k| h[k] = [] }
      range = 0
      
      IO.foreach(file) do |line|
          case line
          when /range: (\d+)/
              range = $1
          when /pp_step/
              time = line.scan(/time\[(\d+)\]/).first.first.to_i
              values[range] << time
          end
      end
      
      p values
      
      results = Hash.new
      
      values.each do |k, v|
          p k, mean(v)
          results[k] = mean(v)
      end
      
      results
  end
  
  unless ARGV.size == 1
      $stderr.puts "Usage: #$0 <pp result dir>"
      exit 1
  end
  
  DEST_DIR = ARGV.first
  
  cpu = parse_output(DEST_DIR / "perf_preypredator_cpu.txt")
  gpu = parse_output(DEST_DIR / "perf_preypredator_gpu.txt")
  
  output = DEST_DIR / "perfs.txt"
  
  File.open(output, "w") do |out|
      cpu.each_key do |key|
          puts [key, cpu[key], gpu[key]].join(" ")
          out.puts [key, cpu[key], gpu[key]].join(" ")
      end
  end