Last active
August 29, 2015 14:21
-
-
Save astatide/aba3ecb5d77bca9d3420 to your computer and use it in GitHub Desktop.
Pulls time information from a WESTPA .h5 file and spits it out in easily human readable format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# Script name: get-time.py | |
# Script created by: Adam J Pratt | |
# Date: Wed Jul 25 15:54:43 EDT 2013 | |
# | |
#################################################################### DESCRIPTION #################################################################### | |
# Pulls time information from a WESTPA .h5 file and spits it out in easily human readable format. | |
##################################################################### VARIABLES ##################################################################### | |
import numpy | |
import argparse | |
import h5py | |
import math | |
import profile | |
####################################################################### BEGIN ####################################################################### | |
class TimeParser: | |
def __init__(self): | |
self.__argument_parser__() | |
def __argument_parser__(self): | |
# Argument Parser | |
parser = argparse.ArgumentParser(description='Pulls time information from a WESTPA .h5 file and prints it the console in DAYS, HOURS, MINUTES, SECONDS.') | |
parser.add_argument('-W', dest='west', help='The main west.h5 file. Defaults to west.h5', default='west.h5') | |
parser.add_argument('--last-iter', dest='last_iter', default=-1) | |
self.last_iter = int(parser.parse_args().last_iter) | |
self.west_h5 = h5py.File(parser.parse_args().west, 'r') | |
def format_into_dd_hh_mm_ss(self, time): | |
m, s = divmod(time, 60) | |
h, m = divmod(m, 60) | |
d, h = divmod(h, 24) | |
return d, h, m, s | |
def run(self): | |
summary = self.west_h5['summary'] | |
walltime = summary['walltime'][:self.last_iter] | |
cputime = summary['cputime'][:self.last_iter] | |
print("Total Wallclock Time: " + "%02d:%02d:%02d:%02d" % self.format_into_dd_hh_mm_ss(walltime.sum())) | |
print("Total CPU Time: " + "%02d:%02d:%02d:%02d" % self.format_into_dd_hh_mm_ss(cputime.sum())) | |
print(cputime.sum()) | |
WALLTIME = self.format_into_dd_hh_mm_ss(walltime.sum()) | |
CPUTIME = self.format_into_dd_hh_mm_ss(cputime.sum()) | |
f = open('CPUTIME', 'w') | |
f.write(str(CPUTIME) + "\n") | |
f.close() | |
f = open('WALLTIME', 'w') | |
f.write(str(WALLTIME) + "\n") | |
f.close() | |
a = TimeParser() | |
a.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment