#!/usr/bin/env ruby require 'rbbt-util' require 'rbbt/util/simpleopt' require 'rbbt/workflow' require 'rbbt/monitor' $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands options = SOPT.setup < -a--all Print all jobs, not only uncompleted -h--help Print this help EOF rbbt_usage and exit 0 if options[:help] workflow, task = ARGV workflow = workflow.split "," if workflow task = task.split "," if task all = options.delete :all def pid_msg(pid) color = if pid and Misc.pid_exists? pid :green else :red end if pid.nil? "" else Log.color(color, pid) end end def status_msg(status) color = case status.to_sym when :error, :aborted, :missing, :dead :red when :streaming, :started :yellow when :done :green else if status.to_s.index ">" :yellow else nil end end Log.color(color, status.to_s) end puts Log.color(:magenta, "# System report") puts sort_files = Proc.new do |a,b| fa,ia = a fb,ib = b dira = fa.split(/[:_][^\/>]*$/).first dirb = fb.split(/[:_][^\/>]*$/).first case dira <=> dirb when -1 -1 when 1 1 else ia[:ctime] <=> ib[:ctime] end end persists = Rbbt.persist_info if persists.any? puts Log.color(:magenta, "Persist:") persists.sort_by{|f,i| i[:ctime] }.each do |file,info| elapsed = info[:elapsed] puts " " << file + Log.color(:blue, " -- time: #{Misc.format_seconds elapsed}") end puts end sensiblewrites = Rbbt.sensiblewrite_info if sensiblewrites.any? puts Log.color(:magenta, "Writing:") sensiblewrites.sort_by{|f,i| i[:ctime] }.each do |file,info| elapsed = info[:elapsed] puts " " << file + Log.color(:blue, " -- time: #{Misc.format_seconds elapsed}") end puts end locks = Rbbt.lock_info if locks.any? puts Log.color(:magenta, "Locks:") locks.sort(&sort_files).each do |file,info| elapsed, pid, ppid = info.values_at :elapsed, :pid, :ppid puts " " << file + Log.color(:blue, " -- time: #{Misc.format_seconds elapsed}; ppid: #{ppid}; pid: #{pid_msg pid}") end puts end exit 0 if workflow.nil? workflow = nil if workflow == ["all"] puts Log.color(:magenta, "# Workflows") jobs = Rbbt.job_info workflow, task workflows = {} jobs.each do |file,info| next unless all or not info[:done] workflow = info[:workflow] task = info[:task] workflows[workflow] ||= {} workflows[workflow][task] ||= {} workflows[workflow][task][file] ||= info end workflows.sort.each do |workflow,tasks| tasks.sort.each do |task,jobs| puts "* " << Log.color(:magenta, workflow) << "#" << Log.color(:yellow, task) << ": " << Log.color(:blue, jobs.length.to_s) files_txt = jobs.collect do |file, i| info = begin Open.open(i[:info_file]) do |f| Marshal.load(f) end rescue {:status => :noinfo} end pid = info[:pid] status = info[:status] status = :missing if status == :done and not File.exists? file status = status.to_s status << Log.color(:red, " (dead)") if status != "done" and pid and not Misc.pid_exists?(pid) str = file.dup str << " #{ status_msg status }" str << "; #{pid_msg pid}" unless status == "done" str end files_txt.each do |f| puts " " << f end end end