Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JPRichings committed Oct 2, 2024
1 parent 827e262 commit 4442e48
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/env/slurm_energy_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import reframe.utility.sanity as sn
import numpy as np


@rfm.simple_test
class SlurmEnergy1nodeTest(rfm.RunOnlyRegressionTest):
"""Checks the energy reporting with a delay"""
Expand All @@ -32,7 +33,7 @@ def assert_finished(self):
def extract_perf(self):
"""Extract energy from counters to compare with slurm and check diff is zero"""
jobid = self.job.jobid
#print("jobid: ", jobid)
# print("jobid: ", jobid)
slurm = rfm.utility.osext.run_command(
"sacct -j " + str(jobid) + " --format=JobID,ConsumedEnergy --noconvert | tr '\n' ' ' ",
check=True,
Expand Down Expand Up @@ -62,7 +63,6 @@ def extract_perf(self):
return diff



@rfm.simple_test
class SlurmEnergy4nodesTest(rfm.RunOnlyRegressionTest):
"""Checks the energy reporting with a delay"""
Expand All @@ -75,7 +75,6 @@ class SlurmEnergy4nodesTest(rfm.RunOnlyRegressionTest):
num_nodes = 4
num_tasks_per_node = 1
num_tasks = num_nodes * num_tasks_per_node


tags = {"production", "maintenance", "craype"}

Expand All @@ -90,56 +89,56 @@ def assert_finished(self):
def extract_perf(self):
"""Extract energy from counters to compare with slurm and check diff is zero"""
jobid = self.job.jobid
#print("jobid: ", jobid)
# print("jobid: ", jobid)
slurm = rfm.utility.osext.run_command(
"sacct -j " + str(jobid) + " --format=JobID,ConsumedEnergy --noconvert | tr '\n' ' ' ",
check=True,
shell=True,
)
print("slurm: ", slurm.stdout)
# print("slurm: ", slurm.stdout)

nodelist_raw = rfm.utility.osext.run_command(
"ls nid* | tr '\n' ',' | sed 's/,$//g'",
check=True,
shell=True,
)

#print("nodelist output: ", nodelist_raw.stdout)
# print("nodelist output: ", nodelist_raw.stdout)

nodelist = list(nodelist_raw.stdout.split(","))

#print("nodelist: ", nodelist)
# print("nodelist: ", nodelist)

energy_data = []

energy_counters = []

for i, nodeid in enumerate(nodelist):
energy_data.append(sn.extractall(r"(?P<energy>[0-9]+)\sJ\s(?P<time>[0-9]+)\sus", nodeid , "energy"))
energy_data.append(sn.extractall(r"(?P<energy>[0-9]+)\sJ\s(?P<time>[0-9]+)\sus", nodeid, "energy"))

for i, energy in enumerate(energy_data):
energy_counters.append(int(str(energy[0])))
energy_counters.append(int(str(energy[1])))

#print("energy counters: ", energy_counters)
# print("energy counters: ", energy_counters)

energy_slurm = sn.extractall_s(
r"JobID\s+ConsumedEnergy\s+------------ --------------\s+[0-9]+\s+[0-9]+\s+[0-9]+.bat\+\s+[0-9]+\s+[0-9]+.ext\+\s+[0-9]+\s+[0-9]+.0\s+(?P<energy>[0-9]+)",
str(slurm.stdout),
"energy",
)
#print("energy slurm: ", energy_slurm)
# print("energy slurm: ", energy_slurm)

energy_counters_diff = 0

for i in np.arange(0, len(energy_counters), 2):
print(energy_counters[i+1] - energy_counters[i])
energy_counters_diff+=energy_counters[i+1] - energy_counters[i]
# print(energy_counters[i + 1] - energy_counters[i])
energy_counters_diff += energy_counters[i + 1] - energy_counters[i]

#print("energy counters diff: ", energy_counters_diff)
# print("energy counters diff: ", energy_counters_diff)

diff = energy_counters_diff - int(str(energy_slurm[0]))

#print("diff: ", diff)
# print("diff: ", diff)

return diff

0 comments on commit 4442e48

Please sign in to comment.