Last active
December 28, 2017 17:36
-
-
Save mpkocher/bae1c7c7d4f1dadf8001d38cd1c055c3 to your computer and use it in GitHub Desktop.
Compute Core Hours
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 | |
import json | |
import sys | |
import argparse | |
import os | |
import operator | |
def extract_table_values(dt, column_id): | |
for column_d in dt['columns']: | |
if column_d['id'] == column_id: | |
return column_d['values'] | |
raise Exception("Unable to extract column id {}".format(column_id)) | |
def load_from_task_report_json(x): | |
""" | |
Load from the <JOB-ROOT>/workflow/task-reports.json | |
""" | |
with open(x) as f: | |
d = json.load(f) | |
dt = d['tables'][0] | |
nprocs = extract_table_values(dt, "pbsmrtpipe.tasks.nproc") | |
run_time_sec = extract_table_values(dt, "pbsmrtpipe.tasks.run_time_sec") | |
run_time_hour = [x / 60.0 / 60.0 for x in run_time_sec] | |
run_time_tasks_total = [x * y for x, y in zip(nprocs, run_time_hour)] | |
return reduce(operator.add, run_time_tasks_total, 0) | |
def get_parser(): | |
desc = "Extract core hours from workflow/report-tasks.json" | |
p = argparse.ArgumentParser(description = desc, version = "0.1.0") | |
p.add_argument("task_report_json", help="Path to <JOB-ROOT-DIR>/workflow/report-tasks.json") | |
return p | |
def main(argv): | |
p = get_parser() | |
pargs = p.parse_args(argv) | |
total = load_from_task_report_json(pargs.task_report_json) | |
print total | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv[1:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment