# sim-info -- information about simfactory # # Michael Thomas # Center for Computation & Technology # Louisiana State University # import sys, os, time optionGroups = ['sim-info'] Purpose = "display some convienient information about simfactory" ############################################ import simarchive,simenv,simlib,restartlib,simrestart from libutil import * global known_commands global known_help known_commands = ['list-machines', 'print-mdb-entry', 'whoami', 'print-mdb', 'list-archived-simulations', 'list-configurations', 'list-simulations'] usage_strings = {'list-machines':'list all the machines in the machine database', 'print-mdb-entry':'list information about a single machine', 'whoami':'what is the name of the machine simfactory is running on', 'print-mdb':'print parsable mdb', 'list-configurations':'list simfactory cactus configurations', 'list-simulations':'list simfactory cactus simulations', 'list-archived-simulations': 'list archived simulations'} ############################### INFO FUNCTIONS ############################### def list_archived_simulations(): simenv.ConfigurationDatabase.RequireCapability("archive") simlib.RequireMachine() machineEntry = simenv.LocalMachineEntry archiveType = machineEntry.archivetype ArchiveEngine = simarchive.SimArchive(archiveType) ArchiveEngine.authenticate() simulations = ArchiveEngine.listSimulations() for sim in simulations: display("") display("%s: " % sim['SimulationId']) display(" Archive Path: %s" % sim['StoredPath']) display(" Simulation Name: %s" % sim['SimulationName']) display(" Machine: %s" % sim['Machine']) display(" Hostname: %s" % sim['Hostname']) display(" User: %s" % sim['User']) display(" Date: %s" % sim['Date']) restarts = sim['Restarts'] display(" Restarts: found %s restart(s)" % len(restarts)) for r in restarts: display(" %s" % r) def list_simulations(): simlib.RequireMachine() simenv.ConfigurationDatabase.RequireCapability("simulation") if len(simenv.OptionsManager.args) == 0: simulations = simlib.GetSimulations() else: simulations = simenv.OptionsManager.args simulations.sort() if len(simulations) == 0: display("There are no simulations") return display("Simulations:") for sim in simulations: active = True restart = simrestart.SimRestart() restart.load(sim) restartIds = restartlib.GetRestartIds(restart) activeId = restartlib.GetActiveRestartId(restart) if len(restartIds) == 0: display(" %-21s [INACTIVE]" % sim) restart.done() continue if activeId == -1: activeId = restartIds[len(restartIds)-1] active = False ret = restart.load(sim, activeId) if ret < 0: display(" %-21s [INACTIVE]" % sim) continue # TODO: This does not distinguish between active and inactive # simulations. Also, only active simulations have a current # restart. # TODO: The number of presubmitted restarts should also be # output. job_id = restart.GetJobId() if active: job_status = restartlib.GetJobStatus(job_id) else: # this job status is never displayed with the letter I # it is used internally only for the purpose of mapping # to the word inactive. job_status = 'I' state_map = dict() state_map['H'] = 'ACTIVE' state_map['R'] = 'ACTIVE' state_map['Q'] = 'QUEUED' state_map['U'] = 'FINISHED' state_map['E'] = 'UNKNOWN' state_map['I'] = 'INACTIVE' # TODO: A simulation can never be in status "H" (HELD), since # this indicates a presubmitted restart (and is not a legal # simulation state). state = 'FINISHED' if job_status in state_map.keys(): state = state_map[job_status] # TODO: What if we can't analyse the job status? This should # be an error. if not simenv.OptionsManager.GetOption('long'): display(" %-21s [%-9s restart id \"%04d\", job id \"%s\"]" % (sim, "%s," % state, int(activeId), job_id)) else: display(" %-21s= %s" % (sim, state)) fd = os.popen("du -sk %s | cut -f1" % restart.SimulationDir) size_in_k = int(fd.read().strip()) fd.close() size_in_bytes = size_in_k * 1024 size_in_gb = size_in_bytes / 1.0e+9 # Active Restart Id display(" %-16s= \"%04d\"" % ("restart id", int(activeId))) #str = libutil.BuildWithSpace("restart id", 16) #libutil.PrintManyLeadingSpace("%s= \"%04d\"" % (str, int(activeId)), 4) # Job display(" %-16s= \"%s\"" % ("job id", job_id)) #str = libutil.BuildWithSpace("job id", 16) #libutil.PrintManyLeadingSpace("%s= \"%s\"" % (str, job_id), 4) # Disk Usage display(" %-16s= \"%04d\"" % ("Disk usage", size_in_gb)) #str = libutil.BuildWithSpace("Disk usage", 16) #libutil.PrintManyLeadingSpace("%s= %02f Gbytes" % (str, size_in_gb), 4) # current iteration (if running) if state == 'RUNNING': pass # Properties PrintManyLeadingSpace(restart.Properties.toString(), 8) restart.done() def list_machines(): machines = simenv.ConfigurationDatabase.GetMachines() for machine in machines: entry = simenv.ConfigurationDatabase.GetMachine(machine) display(" %-12s %6d nodes, %4d ppn %-30s %s" % (machine, int(entry.nodes), int(entry.ppn), entry.hostname, entry.status)) def print_mdb_entry(): if len(simenv.OptionsManager.args) == 0: fatal("no machine specified") for i in range(len(simenv.OptionsManager.args)): machineName = simenv.OptionsManager.args[i] simenv.ConfigurationDatabase.MachineParser.PrintSection(machineName) def whoami(): machine = simlib.GetMachineName() display("Current machine: %s" % machine) def print_mdb(): if len(simenv.OptionsManager.args) == 0: simenv.ConfigurationDatabase.MachineParser.PrintIni() return else: print_mdb_entry() return def list_configurations(): simenv.ConfigurationDatabase.RequireCapability("source") #display("list_configurations") simlib.RequireMachine() configs = simlib.GetConfigurations() configs.sort() if len(configs) == 0: display("There are no configurations") return display("Configurations:") for config in configs: display(" %-40s" % config, noNewLine=True) exe = simlib.BuildPath(simenv.CACTUS_PATH, 'exe', 'cactus_%s' % config) if not(os.path.exists(exe)): display(" [incomplete]") else: statinfo = os.stat(exe) tinfo = time.localtime(statinfo.st_mtime) date = "%s-%02d-%02d %2d:%02d:%02d" % (tinfo.tm_year,tinfo.tm_mon,tinfo.tm_mday, tinfo.tm_hour,tinfo.tm_min,tinfo.tm_sec) display(" [built %s]" % date) ############################### MAIN ############################### def main(): global known_commands ############################################ ## HEADER # if len(simenv.OptionsManager.args) == 0 and simenv.COMMAND == None: simenv.OptionsManager.PrintHelp() sys.exit(0) cactusDir = simenv.CACTUS_PATH if simenv.VERBOSE: display("Cactus Directory: %s" % cactusDir) #if os.getcwd() != cactusDir: #info("Current Working directory does not match Cactus sourcetree, changing to %s" % cactusDir) # make sure we're in the Cactus source directory, otherwise all of this will blow way up. #os.chdir(cactusDir) if simenv.COMMAND != None: command = simenv.COMMAND else: command = simenv.OptionsManager.args[0] if command not in known_commands: fatal("unknown sim-info command %s" % command) # - not a valid function character command = command.replace("-", "_") # execute the reqisite function. globals()[command]()