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_file ⇒ Object
readonly
Returns the value of attribute cmd_file.
-
#cmd_stat ⇒ Object
readonly
Returns the value of attribute cmd_stat.
-
#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
- #find_single_file(pattern) ⇒ Object
- #format_comma(x) ⇒ Object
- #get_command(s) ⇒ Object
- #histogram_plot ⇒ Object
- #id_str ⇒ Object
-
#initialize(option, pattern) ⇒ Report
constructor
A new instance of Report.
- #make_cmd_stat ⇒ Object
- #read_elap_each_cmd ⇒ Object
- #report_html ⇒ Object
- #tr_count(x, y) ⇒ Object
Constructor Details
#initialize(option, 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 65 66 67 68 69 70 71 72 73 |
# File 'lib/pwrake/report/report.rb', line 33 def initialize(option,pattern) @dir = option['REPORT_DIR'] if !File.directory?(@dir) raise ArgumentError,"Could not find log directory: #{@dir}" end @pattern = pattern @@id = @@id.succ @id = @@id @base = @dir @cmd_file = File.join(@dir,option['COMMAND_CSV_FILE']) @task_file = File.join(@dir,option['TASK_CSV_FILE']) @html_file = File.join(@dir,'report.html') begin @sh_table = CSV.read(@cmd_file,:headers=>true,:skip_lines=>/\A#/) rescue $stderr.puts "error in reading "+@cmd_file $stderr.puts $!, $@ exit end h = {} @elap_sum = 0 @sh_table.each do |row| if host = row['host'] h[host] = true end @elap_sum += row['elap_time'].to_f 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 @stat = TaskStat.new(@task_file,@sh_table) @ncore = @stat.ncore end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
75 76 77 |
# File 'lib/pwrake/report/report.rb', line 75 def base @base end |
#cmd_elap ⇒ Object (readonly)
Returns the value of attribute cmd_elap.
77 78 79 |
# File 'lib/pwrake/report/report.rb', line 77 def cmd_elap @cmd_elap end |
#cmd_file ⇒ Object (readonly)
Returns the value of attribute cmd_file.
76 77 78 |
# File 'lib/pwrake/report/report.rb', line 76 def cmd_file @cmd_file end |
#cmd_stat ⇒ Object (readonly)
Returns the value of attribute cmd_stat.
77 78 79 |
# File 'lib/pwrake/report/report.rb', line 77 def cmd_stat @cmd_stat end |
#elap ⇒ Object (readonly)
Returns the value of attribute elap.
75 76 77 |
# File 'lib/pwrake/report/report.rb', line 75 def elap @elap end |
#html_file ⇒ Object (readonly)
Returns the value of attribute html_file.
76 77 78 |
# File 'lib/pwrake/report/report.rb', line 76 def html_file @html_file end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
79 80 81 |
# File 'lib/pwrake/report/report.rb', line 79 def id @id end |
#ncore ⇒ Object (readonly)
Returns the value of attribute ncore.
75 76 77 |
# File 'lib/pwrake/report/report.rb', line 75 def ncore @ncore end |
#sh_table ⇒ Object (readonly)
Returns the value of attribute sh_table.
78 79 80 |
# File 'lib/pwrake/report/report.rb', line 78 def sh_table @sh_table end |
#task_table ⇒ Object (readonly)
Returns the value of attribute task_table.
78 79 80 |
# File 'lib/pwrake/report/report.rb', line 78 def task_table @task_table end |
Instance Method Details
#find_single_file(pattern) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pwrake/report/report.rb', line 81 def find_single_file(pattern) g = Dir.glob(File.join(@dir,pattern)) case g.size when 0 raise ArgumentError, "Could not find any file with '#{pattern}' in #{@dir}" when 1 else raise ArgumentError, "Found multiple files '#{pattern}' in #{@dir}" end g[0] end |
#format_comma(x) ⇒ Object
158 159 160 |
# File 'lib/pwrake/report/report.rb', line 158 def format_comma(x) x.to_s.gsub(/(?<=\d)(?=(?:\d\d\d)+(?!\d))/, ',') end |
#get_command(s) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pwrake/report/report.rb', line 133 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
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 314 315 316 317 |
# File 'lib/pwrake/report/report.rb', line 279 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" if system("which gnuplot >/dev/null 2>&1") 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 end end hist_image end |
#id_str ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/pwrake/report/report.rb', line 93 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
148 149 150 151 152 153 154 155 156 |
# File 'lib/pwrake/report/report.rb', line 148 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
101 102 103 104 105 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 |
# File 'lib/pwrake/report/report.rb', line 101 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
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/pwrake/report/report.rb', line 178 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</th><td>%.3f sec</td><tr>\n"%[@elap] html << "<tr><th>cumulative process time</th><td>%.3f sec</td><tr>\n"%[@elap_sum] html << "<tr><th>occupancy</th><td>%.3f %%</td><tr>\n"%[@elap_sum/@elap/@ncore*100] 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(@sh_table,@base) html << "<img src='./#{File.basename(fimg)}' align='top'/></br>\n" html << "<h2>Parallelism by command</h2>\n" fimg3 = Parallelism.plot_parallelism_by_pattern(@sh_table,@base,@pattern) html << "<img src='./#{File.basename(fimg3)}' align='top'/></br>\n" html << "<h2>Parallelism by host</h2>\n" fimg2 = Parallelism.plot_parallelism_by_host(@sh_table,@base) html << "<img src='./#{File.basename(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='./#{File.basename(histogram_plot)}' align='top'/></br>\n" 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" @stat.exec_hosts.each do |h| if h.to_s!="" || @stat[h,nil,:elap]!=0 html << "<tr><td>#{h}</td>" html << "<td align='right'>%.3f</td>" % @stat[h,nil,:elap] html << "<td></td>" html << tr_count(@stat[h,true,:in_num],@stat[h,false,:in_num]) html << tr_count(@stat[h,true,:in_size],@stat[h,false,:in_size]) html << "<td></td>" html << tr_count(@stat[h,true,:out_num],@stat[h,false,:out_num]) html << tr_count(@stat[h,true,:out_size],@stat[h,false,:out_size]) html << "</tr>\n" end end html << "<tr><td>total</td>" html << "<td align='right'>%.3f</td>" % @stat.total(nil,:elap) html << "<td></td>" html << tr_count(@stat.total(true,:in_num),@stat.total(false,:in_num)) html << tr_count(@stat.total(true,:in_size),@stat.total(false,:in_size)) html << "<td></td>" html << tr_count(@stat.total(true,:out_num),@stat.total(false,:out_num)) html << tr_count(@stat.total(true,:out_size),@stat.total(false,:out_size)) 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 printf "%s,%d,%d,%d,%d\n",@html_file, @stat.total(true,:in_num),@stat.total(false,:in_num),@stat.total(true,:in_size),@stat.total(false,:in_size) end |
#tr_count(x, y) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/pwrake/report/report.rb', line 162 def tr_count(x,y) sum = x+y if sum==0 xp = "--%" yp = "--%" else xp = "%.2f%%"%(x*100.0/sum) yp = "%.2f%%"%(y*100.0/sum) end td = "<td align='right' valign='top'>" return \ td + '%s<br/>%s</td>' % [format_comma(x),xp] + td + '%s<br/>%s</td>' % [format_comma(y),yp] + td + "%s</td>" % format_comma(sum) end |