#!/usr/bin/env ruby require 'rbbt-util' require 'rbbt/util/simpleopt' require 'rbbt/hpc' #$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands options = SOPT.setup < Open.read(fcmd)).read.strip when 'lsf' text = CMD.cmd('grep "^#BSUB" ', :in => Open.read(fcmd)).read.strip else text = "" end lines = text.split("\n").collect{|line| header, _sep, value = line.partition(/\s+/); Log.color(:yellow, header + ": ") + value} puts Log.color :yellow, lines * "\n" end fprocpath = File.join(dir, 'procpath.sqlite3') if options[:batch_procpath] && Open.exists?(fprocpath) puts Log.color(:magenta, "Procpath summary: ") require 'rbbt/tsv/csv' meta = TSV.csv(CMD.cmd("sqlite3 -header -csv #{fprocpath} 'select * from meta;' ")) perf = TSV.csv(CMD.cmd("sqlite3 -header -csv #{fprocpath} 'select * from record;' ")) page_size = meta["page_size"].first.to_f clock_ticks = meta["clock_ticks"].first.to_f cpu_average = {} rss_average = {} perf.through :key, ["ts", 'stat_pid', "stat_utime", "stat_stime", "stat_cutime", "stat_cstime", "stat_rss"] do |k, values| time, stat_pid, ucpu, scpu, ccpu, cscpu, rss = values time = time.to_f cpu = Misc.sum([ucpu, scpu].collect{|v| v.to_f}) cpu_average[stat_pid] ||= {} cpu_average[stat_pid][time] ||= [] cpu_average[stat_pid][time] << cpu.to_f rss_average[time] ||= [] rss_average[time] << rss.to_f * page_size end ticks = 0 cpu_average.each do |stat_pid, cpu_average_pid| start = cpu_average_pid.keys.sort.first eend = cpu_average_pid.keys.sort.last ticks += Misc.sum(cpu_average_pid[eend]) - Misc.sum(cpu_average_pid[start]) end start = rss_average.keys.sort.first eend = rss_average.keys.sort.last time_elapsed = eend - start ticks = 1 if ticks == 0 time_elapsed = 1 if time_elapsed == 0 puts Log.color(:yellow, "CPU average: ") + "%.2f" % ( ticks / clock_ticks / time_elapsed * 100).to_s puts Log.color(:yellow, "RSS average: ") + "%.2f GB" % Misc.mean(rss_average.collect{|t,l| Misc.sum(l) / (1024 * 1024 * 1024)}).to_s puts Log.color(:yellow, "Time: ") + Misc.format_seconds((eend - start)) end if options[:sacct_peformance] begin raise "sacct not supported for LSF" unless batch_system == 'slurm' tsv = TSV.open(CMD.cmd("sacct -j #{id} -o 'jobid,AveRSS,MaxRSS,MaxDiskRead,MaxDiskWrite' -P|grep 'JobID\\|\.batch'"), :header_hash => '', :sep => "|", :type => :list) values = tsv[tsv.keys.first] if values.compact.any? puts Log.color(:magenta, "SACCT performance: ") puts values.zip(values.fields).collect{|v,t| Log.color(:yellow, t + ": ") + v.to_s } * "\n" end rescue Log.warn $!.message end end if tail && File.exist?(File.join(dir, 'std.err')) if exit_status && exit_status != 0 puts Log.color(:magenta, "First error or exception found: ") puts CMD.cmd("grep -i -w 'error\\|[a-z]*exception' #{File.join(dir, 'std.err')} -A #{tail.to_i} |head -n #{tail.to_i}", :no_fail => true).read elsif exit_status puts Log.color(:magenta, "Completed jobs: ") puts CMD.cmd("grep -i -w 'Completed step' #{File.join(dir, 'std.err')} | grep -v 'Retrying dep.' | tail -n #{tail.to_i}", :no_fail => true).read else puts Log.color(:magenta, "Log tail: ") puts CMD.cmd(" cat #{File.join(dir, 'std.err')} | grep -v '^[^\\s:]*\\[3.m' | grep -v -e '^[[:space:]]*$' | grep -v \"\\(STDOUT\\|STDERR\\):[[:space:]]*$\" | tail -n #{tail.to_i} ").read end end if options[:progress] step_line = Open.read(fcmd).split("\n").select{|line| line =~ /^#STEP_PATH:/}.first if step_line require 'rbbt/workflow' step_path = step_line.split(": ").last.strip step = Step.new step_path step.load_dependencies_from_info has_bar = false (step.rec_dependencies + [step]).reverse.each do |j| next if j.done? if j.file(:progress).exists? bar = Log::ProgressBar.new bar.load(j.file(:progress).yaml) puts Log.color(:magenta, "Progress: ") + bar.report_msg + " " + Log.color(:yellow, j.task_signature) has_bar = true end end step_status = step.status step_status = Log.color :red, step_status if step_status.to_s == 'cleaned' step_status = Log.color :green, step_status if step_status.to_s == 'done' puts Log.color(:magenta, "Progress: ") + Log.color(:yellow, step.task_signature) + " #{step_status}" unless has_bar end end end puts puts Log.color :clear, "Found #{count} jobs"