Skip to content

Commit 10af341

Browse files
committed
slurm2sql: Split --completed into --ended, --completed, --failed, --cancelled
1 parent 5c9d634 commit 10af341

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

slurm2sql.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,14 @@ def main(argv=sys.argv[1:], db=None, raw_sacct=None, csv_input=None):
699699
help="Don't parse sacct but import this CSV file. It's read with "
700700
"Python's default csv reader (excel format). Beware badly "
701701
"formatted inputs, for example line breaks in job names.")
702-
parser.add_argument('--completed', '-c', action='store_true',
703-
help=f"Select for completed job states ({COMPLETED_STATES}) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'")
702+
parser.add_argument('--ended', '-e', action='store_true',
703+
help=f"Select for finished job states ({ENDED_STATES}) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'. Not compatible with --db.")
704+
parser.add_argument('--completed', action='store_true', help=f"Like --ended but {COMPLETED_STATES}")
705+
parser.add_argument('--cancelled', action='store_true', help=f"Like --ended but {CANCELLED_STATES}")
706+
parser.add_argument('--failed', action='store_true', help=f"Like --ended but {FAILED_STATES}")
707+
parser.add_argument('--running-at-time', metavar='TIME', help="Only jobs running at this time. Not compatible with --db. Expanded to --start=TIME --end=TIME --state=R.")
708+
709+
704710
parser.add_argument('--quiet', '-q', action='store_true',
705711
help="Don't output anything unless errors")
706712
parser.add_argument('--verbose', '-v', action='store_true',
@@ -914,7 +920,8 @@ def infer_type(cd):
914920
'max(JobName) AS JobName, '
915921
'group_concat(SubmitLine, \'\n\') AS SubmitLines, '
916922
'Account, '
917-
'State, '
923+
'(SELECT State FROM allocations AS allocations2 WHERE allocations2.jobid=slurm1.JobIDnostep) AS State, '
924+
#'State AS State, '
918925
'NodeList, '
919926
'Time, '
920927
'TimeLimit, '
@@ -944,7 +951,7 @@ def infer_type(cd):
944951
'MaxDiskWrite, '
945952
'sum(TotDiskRead) as TotDiskRead, '
946953
'sum(TotDiskWrite) as TotDiskWrite '
947-
'FROM slurm GROUP BY JobIDnostep')
954+
'FROM slurm AS slurm1 GROUP BY JobIDnostep')
948955
#db.execute('PRAGMA journal_mode = WAL;')
949956
db.commit()
950957
c = db.cursor()
@@ -1006,8 +1013,14 @@ def args_to_sacct_filter(args, sacct_filter):
10061013
if len(sacct_filter) == 1 and re.match(r'[0-9+_]+(.[0-9a-z]+)?', sacct_filter[0]):
10071014
sacct_filter = [f'--jobs={sacct_filter[0]}']
10081015
# Set for completed jobs.
1016+
if getattr(args, 'ended', None):
1017+
sacct_filter[:0] = ['--endtime=now', f'--state={ENDED_STATES}']
10091018
if getattr(args, 'completed', None):
10101019
sacct_filter[:0] = ['--endtime=now', f'--state={COMPLETED_STATES}']
1020+
if getattr(args, 'cancelled', None):
1021+
sacct_filter[:0] = ['--endtime=now', f'--state={CANCELLED_STATES}']
1022+
if getattr(args, 'failed', None):
1023+
sacct_filter[:0] = ['--endtime=now', f'--state={FAILED_STATES}']
10111024
if getattr(args, 'user', None):
10121025
sacct_filter[:0] = [f'--user={args.user}']
10131026
# Set args.user to None. We have already handled it here and
@@ -1107,7 +1120,10 @@ def compact_table():
11071120

11081121
SACCT_DEFAULT_FIELDS = "JobID,User,State,datetime(Start, 'unixepoch') AS Start,datetime(End, 'unixepoch') AS End,Partition,ExitCodeRaw,NodeList,NCPUS,CPUtime,CPUEff,AllocMem,TotalMem,MemEff,ReqGPUS,GPUEff,TotDiskRead,TotDiskWrite,ReqTRES,AllocTRES,TRESUsageInTot,TRESUsageOutTot"
11091122
SACCT_DEFAULT_FIELDS_LONG = "JobID,User,State,datetime(Start, 'unixepoch') AS Start,datetime(End, 'unixepoch') AS End,Elapsed,Partition,ExitCodeRaw,NodeList,NCPUS,CPUtime,CPUEff,AllocMem,TotalMem,MemEff,ReqMem,MaxRSS,ReqGPUS,GPUEff,GPUUtil,TotDiskRead,TotDiskWrite,ReqTRES,AllocTRES,TRESUsageInTot,TRESUsageOutTot"
1110-
COMPLETED_STATES = 'CA,CD,DL,F,NF,OOM,PR,RV,TO'
1123+
ENDED_STATES = 'CA,CD,DL,F,NF,OOM,PR,RV,TO'
1124+
COMPLETED_STATES = 'CD'
1125+
CANCELLED_STATES = 'CA,DL'
1126+
FAILED_STATES = 'F,NF,OOM,TO'
11111127
def sacct_cli(argv=sys.argv[1:], csv_input=None):
11121128
"""A command line that uses slurm2sql to give an sacct-like interface."""
11131129
parser = argparse.ArgumentParser(description=
@@ -1136,9 +1152,13 @@ def sacct_cli(argv=sys.argv[1:], csv_input=None):
11361152
help="Output more logging info")
11371153
# No --db compatibility
11381154
group = parser.add_argument_group(description="Selectors that only works when getting new data (not with --db):")
1139-
group.add_argument('--completed', '-c', action='store_true',
1140-
help=f"Select for completed job states ({COMPLETED_STATES}) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'. Not compatible with --db.")
1141-
group.add_argument('--running-at-time', metavar='TIME', help="Only jobs running at this time. Not compatible with --db. Expanded to --start=TIME --end=TIME --state=R.")
1155+
state_grp = group.add_mutually_exclusive_group()
1156+
state_grp.add_argument('--ended', '-e', action='store_true',
1157+
help=f"Select for finished job states ({ENDED_STATES}) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'. Not compatible with --db.")
1158+
state_grp.add_argument('--completed', action='store_true', help=f"Like --ended but {COMPLETED_STATES}")
1159+
state_grp.add_argument('--cancelled', action='store_true', help=f"Like --ended but {CANCELLED_STATES}")
1160+
state_grp.add_argument('--failed', action='store_true', help=f"Like --ended but {FAILED_STATES}")
1161+
state_grp.add_argument('--running-at-time', metavar='TIME', help="Only jobs running at this time. Not compatible with --db. Expanded to --start=TIME --end=TIME --state=R.")
11421162
# --db compatibility
11431163
group = parser.add_argument_group(description="Selectors that also work with --db:")
11441164
group.add_argument('--user', '-u', help="Limit to this or these users. Compatible with --db.")
@@ -1168,16 +1188,16 @@ def sacct_cli(argv=sys.argv[1:], csv_input=None):
11681188

11691189
def seff_cli(argv=sys.argv[1:], csv_input=None):
11701190
parser = argparse.ArgumentParser(usage=
1171-
"slurm2sql-seff [-h] [--order ORDER] [--completed --starttime TIME] SACCT_ARGS",
1191+
"slurm2sql-seff [-h] [--order ORDER] [--ended --starttime TIME] SACCT_ARGS",
11721192
description=
11731193
"""Print out efficiency of different jobs. Included is CPU,
11741194
memory, GPU, and i/o stats.
11751195
11761196
All extra arguments get passed to `sacct` to fetch data job
11771197
data. For example, one would usually give '-a' or '-S
11781198
2019-08-01' here, for example. To look only at completed
1179-
jobs, use "--completed -S now-1week" (a start time must be
1180-
given with --completed because of how sacct works).
1199+
jobs, use "--ended -S now-1week" (a start time must be
1200+
given with --ended because of how sacct works).
11811201
11821202
This only queries jobs with an End time (unlike most other commands).
11831203
@@ -1207,9 +1227,13 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
12071227
help="Output more logging info")
12081228
# No --db compatibility
12091229
group = parser.add_argument_group(description="Selectors that only works when getting new data (not with --db):")
1210-
group.add_argument('--completed', '-c', action='store_true',
1211-
help=f"Select for completed job states ({COMPLETED_STATES}) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'. Not compatible with --db.")
1212-
group.add_argument('--running-at-time', metavar='TIME', help="Only jobs running at this time. Not compatible with --db. Expanded to --start=TIME --end=TIME --state=R.")
1230+
state_grp = group.add_mutually_exclusive_group()
1231+
state_grp.add_argument('--ended', '-e', action='store_true',
1232+
help=f"Select for finished job states ({ENDED_STATES}) You need to specify --starttime (-S) at some point in the past, due to how saccont default works (for example '-S now-1week'). This option automatically sets '-E now'. Not compatible with --db.")
1233+
state_grp.add_argument('--completed', action='store_true', help=f"Like --ended but {COMPLETED_STATES}")
1234+
state_grp.add_argument('--cancelled', action='store_true', help=f"Like --ended but {CANCELLED_STATES}")
1235+
state_grp.add_argument('--failed', action='store_true', help=f"Like --ended but {FAILED_STATES}")
1236+
state_grp.add_argument('--running-at-time', metavar='TIME', help="Only jobs running at this time. Not compatible with --db. Expanded to --start=TIME --end=TIME --state=R.")
12131237
# --db compatibility
12141238
group = parser.add_argument_group(description="Selectors that also work with --db:")
12151239
group.add_argument('--user', '-u', help="Limit to this or these users. Compatible with --db.")
@@ -1272,7 +1296,7 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
12721296
JobID,
12731297
User,
12741298
round(Elapsed/3600,2) AS hours,
1275-
substr(state, 1, 2) AS ST,
1299+
substr(State, 1, 2) AS ST,
12761300
{long_output}
12771301
12781302
NCPUS,
@@ -1290,7 +1314,7 @@ def seff_cli(argv=sys.argv[1:], csv_input=None):
12901314
round(TotDiskWrite/Elapsed/1048576,2) AS write_MiBps
12911315
12921316
FROM eff
1293-
WHERE End IS NOT NULL {where} ) {order_by}""", {'user': args.user, 'partition': args.partition})
1317+
WHERE Start IS NOT NULL and End IS NOT NULL {where} ) {order_by}""", {'user': args.user, 'partition': args.partition})
12941318
headers = [ x[0] for x in cur.description ]
12951319
data = cur.fetchall()
12961320
if len(data) == 0:

0 commit comments

Comments
 (0)