Skip to content

Commit 6b9715d

Browse files
committed
Fix memeff when alloc is reported as zero
- Apparently sometime Slurm can report zero bytes allocated. This doesn't make sense, but it's not slurm2sql's job to make it make sense. This change prevents a crash and make the memeff in these cases 'null', so that an observer can inspect what's going wrong. - Closes: #20
1 parent 43ac437 commit 6b9715d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

slurm2sql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ def calc(row):
502502
m_used = RE_TRES_MEM.search(row['TRESUsageInTot'])
503503
m_alloc = RE_TRES_MEM.search(row['AllocTRES'])
504504
if m_alloc and m_used:
505-
return float_bytes(m_used.group(1)) / float_bytes(m_alloc.group(1))
505+
alloc = float_bytes(m_alloc.group(1))
506+
if alloc == 0: return None
507+
return float_bytes(m_used.group(1)) / alloc
506508
return None
507509

508510

test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ def test_cpueff(db):
162162
assert fetch(db, 1, 'TotalCPU') == 1500
163163
assert fetch(db, 1, 'CPUeff', table='eff') == 0.5
164164

165+
def test_memeff(db):
166+
data = """
167+
JobID,AllocTRES,TRESUsageInTot
168+
1,mem=1000K,mem=500K
169+
2,mem=0K,mem=0K
170+
"""
171+
slurm2sql.slurm2sql(db, [], csv_input=csvdata(data))
172+
print(db.execute('select * from eff;').fetchall())
173+
assert fetch(db, 1, 'Memeff', table='eff') == 0.5
174+
assert fetch(db, 2, 'Memeff', table='eff') == None
175+
176+
165177
def test_gpueff(db):
166178
data = """
167179
JobID,AllocTRES,TRESUsageInTot

0 commit comments

Comments
 (0)