diff --git a/bin/getRunInfo.py b/bin/getRunInfo.py index b6e0c02..b83ebc8 100755 --- a/bin/getRunInfo.py +++ b/bin/getRunInfo.py @@ -1,217 +1,216 @@ #!/usr/bin/env python import BlackDynamite as BD import os, sys, stat import subprocess import getopt import socket import datetime ################################################################ def printSummary(mybase, params): runSelector = BD.RunSelector(mybase) run_list = runSelector.selectRuns(params,params,quiet=True) print ("************************ run summary => study {0} *********************************".format(mybase.schema)) if (len(run_list) == 0): print ("no runs found") sys.exit(0) request = "SELECT run_name,state,count(state) from {0}.runs ".format(mybase.schema) if (len(run_list) > 0): request += "where id in (" + ",".join([str(r.id) for r,j in run_list ]) + ")" request += " group by state,run_name order by run_name,state" # print (request) curs = mybase.performRequest(request,[]) stats = {} for i in curs: if i[0] not in stats: stats[i[0]] = [] stats[i[0]].append([i[1] , int(i[2]) ]) for run_name,st in stats.iteritems(): tot = 0 for n,count in st: tot += count for n,count in st: print ("{:20} {:>20} => {:5} ({:>5.1f}%)".format(run_name,n,count,100.*count/tot)) print ("") sys.exit(0) ################################################################ def getRunInfo(run_id, mybase): myrun = BD.Run(mybase) myrun["id"] = run_id myrun.id = run_id run_list = myrun.getMatchedObjectList() if (len(run_list) == 0): print ("no run found with id " + str(run_id)) sys.exit(1) myrun = run_list[0] myjob = BD.Job(mybase) myjob.id = myrun["job_id"] myjob["id"] = myrun["job_id"] job_list = myjob.getMatchedObjectList() if (len(job_list) == 0): print ("no job found with id " + myjob.id) sys.exit(1) myjob = job_list[0] list_entries = myjob.entries.keys() print ("************************ job info *********************************") for entry in list_entries: if (myjob[entry]): print (entry + ": " + str(myjob[entry])) print ("************************ run info *********************************") list_entries = myrun.entries.keys() regular_run_entries = ("run_name", \ "job_id" , \ "state", \ "start_time", \ "machine_name" , \ "exec", \ "nproc", \ "wait_id" \ ) for entry in regular_run_entries: if (myrun[entry]): print (entry + ": " + str(myrun[entry])) list_entries.remove(entry) for entry in list_entries: if (myrun[entry]): print (entry + ": " + str(myrun[entry])) conffiles = myrun.getConfigFiles() for conf in conffiles: print ("****************************************************************") print ("file #" + str(conf.id) + ": " + conf["filename"]) print ("****************************************************************") print (conf["file"]) ################################################################ def getInfoNames(): infos = [] infos.append("run_name") infos.append("id") infos.append("job_id") - infos.append("state") - infos.append("nproc") - infos.append("machine_name") if "infos" in params: infos += params['infos'] + else: + infos += ["state","nproc","machine_name"] infos.append("start_time") infos.append("last step") infos.append("last update") infos.append("Time/step") infos.append("Total Time") return infos ################################################################ def getFormatString(infos): - format_string = " {:<20} | {:^6} | {:^6} | {:<15} | {:^5} | {:<20} |" + format_string = " {:<20} | {:^6} | {:^6} |" if "infos" in params: format_string += " {:^8} |" * len(params['infos']) - + else: format_string += " {:<15} | {:^5} | {:<20} |" format_string += " {:14} | {:9} | {:14} | {:10} | {:14} |" return format_string ################################################################ def formatTimeDelta(t): if (t < datetime.timedelta(seconds=1)): if (t < datetime.timedelta(microseconds=1000)): t = str(t.microseconds) + u'\u00B5'.encode('UTF-8') + "s" else: t = str(1./1000.*t.microseconds) + 'ms' else: ms = t.microseconds t -= datetime.timedelta(microseconds=ms) t = str(t) return t ################################################################ def getTimeInfos(r): step,steptime = r.getLastStep() start_time = r['start_time'] time_perstep = None total_time = None if (step): time_perstep = (steptime-start_time)/step total_time = steptime-start_time time_perstep = formatTimeDelta(time_perstep) total_time = formatTimeDelta(total_time) if start_time: start_time = start_time.strftime("%H:%M %d/%m/%y") if steptime : steptime = steptime.strftime("%H:%M %d/%m/%y") run_infos = [start_time,step,steptime,time_perstep,total_time] return run_infos ################################################################ def getRunInfos(r,j): run_infos = [] for col in info_names: key_run = col.replace('%r.','').strip() if not key_run == 'start_time' and key_run in r.entries: run_infos.append(r[key_run]) key_job = col.replace('%j.','').strip() if not key_job == 'id' and key_job in j.entries: run_infos.append(j[key_job]) run_infos += getTimeInfos(r) return run_infos ################################################################ parser = BD.BDParser() parser.register_params(group="getRunInfo", params={"run_id":int, "order":str, "summary":bool, "infos":[str]}, defaults={"order":"id"}, help={"run_id":"Select a run_id for complete output", "summary":"Output a summary of the completeness of the study", "order": "specify the column which serves to order the lines"}) params = parser.parseBDParameters() mybase = BD.Base(**params) if (params["summary"] == True): printSummary(mybase,params) if ("run_id" in params): getRunInfo(params["run_id"],mybase) else: info_names = getInfoNames() format_string = getFormatString(info_names) header = format_string.format(*info_names) separator = "-" * len(header) print (separator) print (header) print (separator) run_constraints = [] job_constraints = [] runSelector = BD.RunSelector(mybase) run_list = runSelector.selectRuns(params,params,sort_by="runs." + params["order"],quiet=True) for r,j in run_list: line = format_string.format(*getRunInfos(r,j)) print (line)