Class: Pwrake::ReportMulti

Inherits:
Object
  • Object
show all
Defined in:
lib/pwrake/report/report_multi.rb

Instance Method Summary collapse

Constructor Details

#initialize(list, pattern, options = {}) ⇒ ReportMulti

Returns a new instance of ReportMulti.



5
6
7
8
9
10
11
12
13
14
# File 'lib/pwrake/report/report_multi.rb', line 5

def initialize(list,pattern,options={})
  @reports = list.map do |base|
    r = Report.new(base,pattern)
    puts r.base+" elap=#{r.elap}"
    r
  end
  @pattern = pattern
  @img_fmt = options['REPORT_IMAGE'] || 'png'
  @elap_img = 'elap.#{@img_fmt}'
end

Instance Method Details

#histogram_htmlObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/pwrake/report/report_multi.rb', line 91

def histogram_html
  html = ""
  @cmd_rep.each do |cmd,cmd_rep|
    html << "<p>Statistics of Elapsed time of #{cmd}</p>\n<table>\n"
    html << "<th>id</th><th>ncore</th>"+Stat.html_th
    cmd_rep.each do |id,r|
      s = r.cmd_stat[cmd]
      html << "<tr><td>#{id}</td><td>#{r.ncore}</td>" + s.html_td + "</tr>\n"
    end
    html << "</table>\n"
    html << "<img src='./#{File.basename(@images[cmd])}'/>\n"
  end
  html
end

#histogram_plotObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/pwrake/report/report_multi.rb', line 106

def histogram_plot
  @cmd_rep.each do |cmd,cmd_rep|
    IO.popen("gnuplot","r+") do |f|
      f.puts "
set terminal #{@img_fmt} # size 480,360
set output '#{@images[cmd]}'
set ylabel 'histogram'
set xlabel 'Execution time (sec)'
set logscale x
set title '#{cmd}'"
      a = []
      ncores = cmd_rep.keys
      ncores.each_with_index{|n,i|
        a << "'-' w histeps ls #{i+1} title ''"
        a << "'-' w lines ls #{i+1} title '#{n}'"
      }
      f.puts "plot "+ a.join(',')

      cmd_rep.each do |ncore,r|
        s = r.cmd_stat[cmd]
        2.times do
          s.hist_each do |x1,x2,y|
            x = Math.sqrt(x1*x2)
            f.printf "%f %d\n", x, y
          end
          f.puts "e"
        end
      end
    end
    puts "Histogram plot: #{@images[cmd]}"
  end
end

#histogram_plot2Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/pwrake/report/report_multi.rb', line 139

def histogram_plot2
  @cmd_rep.each do |cmd,cmd_rep|
    IO.popen("gnuplot","r+") do |f|
      f.puts "
set terminal #{@img_fmt} # size 480,360
set output '#{@images[cmd]}'
set nohidden3d
set palette rgb 33,13,10
set pm3d
set ticslevel 0
unset colorbox
set yrange [#{cmd_rep.size}:0]
set logscale x
set title '#{cmd}'"
      a = []
      ncores = cmd_rep.keys.sort
      ncores.each_with_index{|n,i|
        a << "'-' w lines ls #{i+1} title '#{n} cores'"
      }
      f.puts "splot "+ a.join(',')

      ncores.each_with_index do |ncore,i|
        s = cmd_rep[ncore]
        y = i
        s.hist_each do |x1,x2,z|
          f.printf "%g %g 0\n", x1,y
          f.printf "%g %g 0\n", x2,y
          f.printf "%g %g 0\n", x2,y
        end
        f.puts ""
        s.hist_each do |x1,x2,z|
          f.printf "%g %g %g\n", x1,y,z
          f.printf "%g %g %g\n", x2,y,z
          f.printf "%g %g 0\n", x2,y,z
        end
        f.puts ""
        y = i+1
        s.hist_each do |x1,x2,z|
          f.printf "%g %g %g\n", x1,y,z
          f.printf "%g %g %g\n", x2,y,z
          f.printf "%g %g 0\n", x2,y,z
        end
        f.puts ""
        s.hist_each do |x1,x2,z|
          f.printf "%g %g 0\n", x1,y
          f.printf "%g %g 0\n", x2,y
          f.printf "%g %g 0\n", x2,y
        end
        f.puts "e"
        i = i+1
      end
    end
    puts "Histogram plot: #{@images[cmd]}"
  end
end

#plot_elapObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/pwrake/report/report_multi.rb', line 44

def plot_elap
  a = @reports.map{|r| r.ncore * r.elap}.min
  elaps = @reports.map{|r| r.elap}
  logmin = Math.log10(elaps.min)
  logmax = Math.log10(elaps.max)
  mid = (logmin+logmax)/2
  wid = (logmax-logmin).ceil*0.5
  ymin = 10**(mid-wid)
  ymax = 10**(mid+wid)
  IO.popen("gnuplot","r+") do |f|
    f.puts "
set terminal #{@img_fmt} size 640,480
set output '#{@elap_img}'
set xlabel 'ncore'
set ylabel 'time (sec)'
set yrange [#{ymin}:#{ymax}]
set logscale xy
plot #{a}/x,'-' w lp lw 2 ps 2 title 'elapsed time'
"
    @reports.sort_by{|r| r.ncore}.each do |r|
      f.puts "#{r.ncore} #{r.elap}"
    end
    f.puts "e"
  end
  puts "Ncore-time plot: "+@elap_img
end

#report(stat_html) ⇒ Object



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
# File 'lib/pwrake/report/report_multi.rb', line 16

def report(stat_html)
  if true
    @reports.each do |r|
      r.report_html
    end
    plot_elap
  end
  html = Report::HTML_HEAD + "<body><h1>Pwrake Statistics</h1>\n"
  html << "<h2>Log files</h2>\n"
  html << "<table>\n"
  html << "<tr><th>log file</th><th>id</th><th>ncore</th><th>elapsed time(sec)</th><tr>\n"
  @reports.each do |r|
    html << "<tr><td><a href='#{r.html_file}'>#{r.base}</a></td>"
    html << "<td>#{r.id_str}</td><td>#{r.ncore}</td><td>#{r.elap}</td><tr>\n"
  end
  html << "</table>\n"
  html << "<h2>Elapsed time</h2>\n"
  html << "<img src='./#{File.basename(@elap_img)}'  align='top'/></br>\n"

  html << "<h2>Histogram of Execution time</h2>\n"
  html << report_histogram()
  html << "</body></html>\n"

  File.open(stat_html,"w") do |f|
    f.puts html
  end
end

#report_histogramObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pwrake/report/report_multi.rb', line 71

def report_histogram
  @images = {}
  @cmd_rep = {}

  @reports.each do |r|
    r.cmd_stat.each do |cmd,stat|
      if stat.n > 2
        @cmd_rep[cmd] ||= {}
        @cmd_rep[cmd][r.id_str] = r # stat
      end
    end
  end

  @cmd_rep.each_key do |cmd|
    @images[cmd] = 'hist_'+cmd.gsub(/[\/.]/,'_')+'.'+@img_fmt
  end
  histogram_plot
  histogram_html
end