Class: Pwrake::Report
- Inherits:
-
Object
- Object
- Pwrake::Report
- Defined in:
- lib/pwrake/report/report.rb
Constant Summary collapse
- HTML_HEAD =
"<html><head><style>\n<!--\nh2 {\n background-color:#eee;\n}\nh1 {\n background-color:#0ff;\n}\ntable {\n margin:0px;\n border-style:solid;\n border-width:1px;\n}\ntd {\n margin:0px;\n border-style:solid;\n border-width:1px;\n}\n-->\n</style>\n</head>\n<body>\n"- @@id =
0- @@id_fmt =
nil
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#cmd_elap ⇒ Object
readonly
Returns the value of attribute cmd_elap.
-
#cmd_stat ⇒ Object
readonly
Returns the value of attribute cmd_stat.
-
#csv_file ⇒ Object
readonly
Returns the value of attribute csv_file.
-
#elap ⇒ Object
readonly
Returns the value of attribute elap.
-
#html_file ⇒ Object
readonly
Returns the value of attribute html_file.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ncore ⇒ Object
readonly
Returns the value of attribute ncore.
-
#sh_table ⇒ Object
readonly
Returns the value of attribute sh_table.
-
#task_table ⇒ Object
readonly
Returns the value of attribute task_table.
Instance Method Summary collapse
- #format_comma(x) ⇒ Object
- #get_command(s) ⇒ Object
- #histogram_plot ⇒ Object
- #id_str ⇒ Object
-
#initialize(base, pattern) ⇒ Report
constructor
A new instance of Report.
- #make_cmd_stat ⇒ Object
- #read_elap_each_cmd ⇒ Object
- #report_html ⇒ Object
- #task_locality ⇒ Object
- #tr_count(x, y) ⇒ Object
Constructor Details
#initialize(base, pattern) ⇒ Report
Returns a new instance of Report.
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 58 59 60 61 62 63 64 |
# File 'lib/pwrake/report/report.rb', line 33 def initialize(base,pattern) @base = base @pattern = pattern @@id = @@id.succ @id = @@id @csv_file = base+'.csv' @task_file = base+'.task' @html_file = base+'.html' open(@base+".log","r").each do |s| if /num_cores=(\d+)/ =~ s @ncore = $1.to_i break end end @sh_table = CSV.read(@csv_file,:headers=>true) h = {} @sh_table.each do |row| if host = row['host'] h[host] = true end end @hosts = h.keys.sort @start_time = Time.parse(@sh_table[0]["start_time"]) @end_time = Time.parse(@sh_table[-1]["start_time"]) @elap = @end_time - @start_time read_elap_each_cmd make_cmd_stat end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
66 67 68 |
# File 'lib/pwrake/report/report.rb', line 66 def base @base end |
#cmd_elap ⇒ Object (readonly)
Returns the value of attribute cmd_elap.
68 69 70 |
# File 'lib/pwrake/report/report.rb', line 68 def cmd_elap @cmd_elap end |
#cmd_stat ⇒ Object (readonly)
Returns the value of attribute cmd_stat.
68 69 70 |
# File 'lib/pwrake/report/report.rb', line 68 def cmd_stat @cmd_stat end |
#csv_file ⇒ Object (readonly)
Returns the value of attribute csv_file.
67 68 69 |
# File 'lib/pwrake/report/report.rb', line 67 def csv_file @csv_file end |
#elap ⇒ Object (readonly)
Returns the value of attribute elap.
66 67 68 |
# File 'lib/pwrake/report/report.rb', line 66 def elap @elap end |
#html_file ⇒ Object (readonly)
Returns the value of attribute html_file.
67 68 69 |
# File 'lib/pwrake/report/report.rb', line 67 def html_file @html_file end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
70 71 72 |
# File 'lib/pwrake/report/report.rb', line 70 def id @id end |
#ncore ⇒ Object (readonly)
Returns the value of attribute ncore.
66 67 68 |
# File 'lib/pwrake/report/report.rb', line 66 def ncore @ncore end |
#sh_table ⇒ Object (readonly)
Returns the value of attribute sh_table.
69 70 71 |
# File 'lib/pwrake/report/report.rb', line 69 def sh_table @sh_table end |
#task_table ⇒ Object (readonly)
Returns the value of attribute task_table.
69 70 71 |
# File 'lib/pwrake/report/report.rb', line 69 def task_table @task_table end |
Instance Method Details
#format_comma(x) ⇒ Object
137 138 139 |
# File 'lib/pwrake/report/report.rb', line 137 def format_comma(x) x.to_s.gsub(/(?<=\d)(?=(?:\d\d\d)+(?!\d))/, ',') end |
#get_command(s) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/pwrake/report/report.rb', line 112 def get_command(s) if /\(([^()]+)\)/ =~ s s = $1 end a = s.split(/;/) a.each do |x| if /^\s*(\S+)/ =~ x k = $1 next if k=='cd' return k end end nil end |
#histogram_plot ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/pwrake/report/report.rb', line 315 def histogram_plot command_list = [] @cmd_stat.each do |cmd,stat| if stat.n > 2 command_list << cmd end end hist_image = @base+"_hist.png" IO.popen("gnuplot","r+") do |f| f.puts " set terminal png # size 480,360 set output '#{hist_image}' set ylabel 'histogram' set xlabel 'Execution time (sec)' set logscale x set title 'histogram of elapsed time'" a = [] command_list.each_with_index do |n,i| a << "'-' w histeps ls #{i+1} title ''" a << "'-' w lines ls #{i+1} title '#{n}'" end f.puts "plot "+ a.join(',') command_list.each do |cmd| stat = @cmd_stat[cmd] 2.times do stat.hist_each do |x1,x2,y| x = Math.sqrt(x1*x2) f.printf "%f %d\n", x, y end f.puts "e" end end hist_image end end |
#id_str ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/pwrake/report/report.rb', line 72 def id_str if @@id_fmt.nil? id_len = Math.log10(@@id).floor + 1 @@id_fmt = "#%0#{id_len}d" end @@id_fmt % @id end |
#make_cmd_stat ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/pwrake/report/report.rb', line 127 def make_cmd_stat @cmd_stat = {} @cmd_elap.each do |cmd,elap| @cmd_stat[cmd] = s = Stat.new(elap) if elap.size > 1 s.make_logx_histogram(1.0/8) end end end |
#read_elap_each_cmd ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/pwrake/report/report.rb', line 80 def read_elap_each_cmd @cmd_elap = {} @sh_table.each do |row| command = row['command'] elap = row['elap_time'] if command && elap elap = elap.to_f found = nil @pattern.each do |cmd,regex| if regex =~ command if a = @cmd_elap[cmd] a << elap else @cmd_elap[cmd] = [elap] end found = true end end if !found if cmd = get_command( command ) if a = @cmd_elap[cmd] a << elap else @cmd_elap[cmd] = [elap] end end end end end @cmd_elap end |
#report_html ⇒ Object
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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/pwrake/report/report.rb', line 150 def report_html html = HTML_HEAD + "<body><h1>Pwrake Statistics</h1>\n" html << "<h2>Workflow</h2>\n" html << "<table>\n" html << "<tr><th>log file</th><td>#{@base}</td><tr>\n" html << "<tr><th>ncore</th><td>#{@ncore}</td><tr>\n" html << "<tr><th>elapsed time(sec)</th><td>#{@elap}</td><tr>\n" html << "<tr><th>start time</th><td>#{@start_time}</td><tr>\n" html << "<tr><th>end time</th><td>#{@end_time}</td><tr>\n" html << "</table>\n" html << "<table>\n" html << "<tr><th>hosts</th><tr>\n" @hosts.each do |h| html << "<tr><td>#{h}</td><tr>\n" end html << "</table>\n" html << "<h2>Parallelism</h2>\n" fimg = Parallelism.plot_parallelism2(@csv_file) html << "<img src='#{fimg}' align='top'/></br>\n" html << "<h2>Parallelism by host</h2>\n" fimg2 = Parallelism.plot_parallelizm_by_host(@sh_table,@base) html << "<img src='#{fimg2}' align='top'/></br>\n" html << "<h2>Command statistics</h2>\n" html << "<table>\n" html << "<tr><th>command</th>" html << Stat.html_th html << "</tr>\n" @cmd_stat.each do |cmd,stat| html << "<tr><td>#{cmd}</td>" html << stat.html_td html << "</tr>\n" end html << "<table>\n" html << "<img src='#{histogram_plot}' align='top'/></br>\n" task_locality html << "<h2>Locality statistics</h2>\n" html << "<table>\n" html << "<tr><th></th><th rowspan=3>gross elapsed time (sec)</th><th></th>" html << "<th colspan=6>read</th>" html << "<th></th>" html << "<th colspan=6>write</th>" html << "</tr>\n" html << "<tr><th></th><th></th>" html << "<th colspan=3>count</th><th colspan=3>file size (bytes)</th>" html << "<th></th>" html << "<th colspan=3>count</th><th colspan=3>file size (bytes)</th>" html << "</tr>\n" html << "<tr><th>host</th><th></th>" html << "<th>local</th><th>remote</th><th>total</th>" html << "<th>local</th><th>remote</th><th>total</th>" html << "<th></th>" html << "<th>local</th><th>remote</th><th>total</th>" html << "<th>local</th><th>remote</th><th>total</th>" html << "</tr>\n" n_same_input = 0 size_same_input = 0 n_diff_input = 0 size_diff_input = 0 n_same_output = 0 size_same_output = 0 n_diff_output = 0 size_diff_output = 0 elap_host = 0 @exec_hosts.each do |h| html << "<tr><td>#{h}</td>" html << "<td align='right'>%.3f</td>" % @elap_host[h] html << "<td></td>" html << tr_count(@n_same_input[h],@n_diff_input[h]) html << tr_count(@size_same_input[h],@size_diff_input[h]) html << "<td></td>" html << tr_count(@n_same_output[h],@n_diff_output[h]) html << tr_count(@size_same_output[h],@size_diff_output[h]) html << "</tr>\n" n_same_input += @n_same_input[h] size_same_input += @size_same_input[h] n_diff_input += @n_diff_input[h] size_diff_input += @size_diff_input[h] n_same_output += @n_same_output[h] size_same_output += @size_same_output[h] n_diff_output += @n_diff_output[h] size_diff_output += @size_diff_output[h] elap_host += @elap_host[h] end html << "<tr><td>total</td>" html << "<td align='right'>%.3f</td>" % elap_host html << "<td></td>" html << tr_count(n_same_input,n_diff_input) html << tr_count(size_same_input,size_diff_input) html << "<td></td>" html << tr_count(n_same_output,n_diff_output) html << tr_count(size_same_output,size_diff_output) html << "</tr>\n" html << "<table>\n" html << "</body></html>\n" File.open(@html_file,"w") do |f| f.puts html end puts "generate "+@html_file end |
#task_locality ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/pwrake/report/report.rb', line 260 def task_locality @task_table = CSV.read(@task_file,:headers=>true) file_size = {} file_host = {} @task_table.each do |row| name = row['task_name'] file_size[name] = row['file_size'].to_i file_host[name] = (row['file_host']||'').split('|') end @n_same_output = Hash.new(0) @size_same_output= Hash.new(0) @n_diff_output = Hash.new(0) @size_diff_output= Hash.new(0) @n_same_input = Hash.new(0) @size_same_input = Hash.new(0) @n_diff_input = Hash.new(0) @size_diff_input = Hash.new(0) h = {} @task_table.each do |row| if row['executed']=='1' name = row['task_name'] exec_host = row['exec_host'] h[exec_host] = true if file_host[name].include?(exec_host) @n_same_output[exec_host] += 1 @size_same_output[exec_host] += file_size[name] else @n_diff_output[exec_host] += 1 @size_diff_output[exec_host] += file_size[name] end preq_files = (row['preq']||'').split('|') preq_files.each do |preq| if (sz=file_size[preq]) && sz > 0 if file_host[preq].include?(exec_host) @n_same_input[exec_host] += 1 @size_same_input[exec_host] += sz else @n_diff_input[exec_host] += 1 @size_diff_input[exec_host] += sz end end end end end @exec_hosts = h.keys.sort @elap_host = Hash.new(0) @sh_table.each do |row| if (h = row['host']) && (t = row['elap_time']) @elap_host[h] += t.to_f end end end |
#tr_count(x, y) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/pwrake/report/report.rb', line 141 def tr_count(x,y) sum = x+y td = "<td align='right' valign='top'>" m = td + "%s<br/>%.2f%%</td>" % [format_comma(x),x*100.0/sum] m << td + "%s<br/>%.2f%%</td>" % [format_comma(y),y*100.0/sum] m << td + "%s</td>" % format_comma(sum) m end |