@@ -330,25 +330,48 @@ def get_finished_job_stats(jobid):
330330 except Exception , e :
331331 log ("Unable to read in CSV output from sacct: %s" % str (e ))
332332 return return_dict
333-
334- sacct_parser = {'RemoteUserCpu' : lambda orig , results : orig + \
335- convert_cpu_to_seconds (results ["AveCPU" ]) * int (results ["AllocCPUS" ]),
336- 'ImageSize' : lambda orig , results : orig + int (results ["MaxRSS" ].replace ('K' , '' )),
337- 'ExitCode' : lambda orig , results : int (results ["ExitCode" ].split (":" )[0 ])}
333+
338334 # Slurm can return more than 1 row, for some odd reason.
339335 # so sum up relevant values
340336 for row in reader :
341- for attr , func in sacct_parser . items () :
337+ if row [ "AveCPU" ] is not "" :
342338 try :
343- return_dict [attr ] = func (return_dict [attr ], row )
344- except (ValueError , KeyError ), exc :
345- log ("Could not parse %s for Jobid %s: %s" % (attr , jobid , exc ))
346-
347- # PBS completion
339+ return_dict ['RemoteUserCpu' ] += convert_cpu_to_seconds (row ["AveCPU" ]) * int (row ["AllocCPUS" ])
340+ except :
341+ log ("Failed to parse CPU usage for job id %s: %s, %s" % (jobid , row ["AveCPU" ], row ["AllocCPUS" ]))
342+ raise
343+ if row ["MaxRSS" ] is not "" :
344+ # Remove the trailing [KMGTP] and scale the value appropriately
345+ # Note: We assume that all values will have a suffix, and we
346+ # want the value in kilos.
347+ try :
348+ value = row ["MaxRSS" ]
349+ factor = 1
350+ if value [- 1 ] == 'M' :
351+ factor = 1024
352+ elif value [- 1 ] == 'G' :
353+ factor = 1024 * 1024
354+ elif value [- 1 ] == 'T' :
355+ factor = 1024 * 1024 * 1024
356+ elif value [- 1 ] == 'P' :
357+ factor = 1024 * 1024 * 1024 * 1024
358+ return_dict ["ImageSize" ] += int (value .strip ('KMGTP' )) * factor
359+ except :
360+ log ("Failed to parse memory usage for job id %s: %s" % (jobid , row ["MaxRSS" ]))
361+ raise
362+ if row ["ExitCode" ] is not "" :
363+ try :
364+ return_dict ["ExitCode" ] = int (row ["ExitCode" ].split (":" )[0 ])
365+ except :
366+ log ("Failed to parse ExitCode for job id %s: %s" % (jobid , row ["ExitCode" ]))
367+ raise
368+
369+ # PBS completion
348370 elif _cluster_type_cache == "pbs" :
349371 pass
350372
351373 return return_dict
374+
352375
353376_qstat_location_cache = None
354377def get_qstat_location ():
0 commit comments