diff --git a/slurm2sql.py b/slurm2sql.py index f5c85c3..c211976 100644 --- a/slurm2sql.py +++ b/slurm2sql.py @@ -502,7 +502,9 @@ def calc(row): m_used = RE_TRES_MEM.search(row['TRESUsageInTot']) m_alloc = RE_TRES_MEM.search(row['AllocTRES']) if m_alloc and m_used: - return float_bytes(m_used.group(1)) / float_bytes(m_alloc.group(1)) + alloc = float_bytes(m_alloc.group(1)) + if alloc == 0: return None + return float_bytes(m_used.group(1)) / alloc return None diff --git a/test.py b/test.py index 4bc2474..7d14a9c 100644 --- a/test.py +++ b/test.py @@ -162,6 +162,18 @@ def test_cpueff(db): assert fetch(db, 1, 'TotalCPU') == 1500 assert fetch(db, 1, 'CPUeff', table='eff') == 0.5 +def test_memeff(db): + data = """ + JobID,AllocTRES,TRESUsageInTot + 1,mem=1000K,mem=500K + 2,mem=0K,mem=0K + """ + slurm2sql.slurm2sql(db, [], csv_input=csvdata(data)) + print(db.execute('select * from eff;').fetchall()) + assert fetch(db, 1, 'Memeff', table='eff') == 0.5 + assert fetch(db, 2, 'Memeff', table='eff') == None + + def test_gpueff(db): data = """ JobID,AllocTRES,TRESUsageInTot