Commit 6f53bbbd authored by Swann Perarnau's avatar Swann Perarnau

Merge branch 'coolr-improve-and-check' into 'master'

Fix recent coolr issues and start building tests for it

See merge request !7
parents 0c93ce6a 37097b20
......@@ -214,7 +214,7 @@ class rapl_reader:
e = self.read_energy_acc()
self.stop_time = time.time()
def sample_and_json(self, label = "", accflag = False, node = ""):
def sample(self, accflag=False):
if not self.initialized():
return
......@@ -226,55 +226,32 @@ class rapl_reader:
if k != 'time':
if accflag:
self.totalenergy[k] += de[k]
self.lastpower[k] = de[k]/de['time']/1000.0/1000.0;
self.lastpower[k] = de[k]/de['time']/1000.0/1000.0
self.prev_e = e
# constructing a json output
s = '{"sample":"energy","time":%.3f' % (e['time'])
if len(node) > 0:
s += ',"node":"%s"' % node
if len(label) > 0:
s += ',"label":"%s"' % label
s += ',"energy":{'
firstitem = True
ret = dict()
ret['energy'] = dict()
for k in sorted(e.keys()):
if k != 'time':
if firstitem:
firstitem = False
else:
s+=','
s += '"%s":%d' % (self.shortenkey(k), e[k])
s += '},'
s += '"power":{'
ret['energy'][self.shortenkey(k)] = e[k]
ret['power'] = dict()
totalpower = 0.0
firstitem = True
for k in sorted(self.lastpower.keys()):
if k != 'time':
if firstitem:
firstitem = False
else:
s+=','
s += '"%s":%.1f' % (self.shortenkey(k), self.lastpower[k])
# this is a bit ad hoc way to calculate the total. needs to be fixed later
ret['power'][self.shortenkey(k)] = self.lastpower[k]
# this is a bit ad hoc way to calculate the total.
# needs to be fixed later
if k.find("core") == -1:
totalpower += self.lastpower[k]
s += ',"total":%.1f' % (totalpower)
s += '},'
ret['power']['total'] = totalpower
s += '"powercap":{'
ret['powercap'] = dict()
rlimit = self.readpowerlimitall()
firstitem = True
for k in sorted(rlimit.keys()):
if firstitem:
firstitem = False
else:
s+=','
s += '"%s":%.1f' % (self.shortenkey(k), rlimit[k]['curW'])
s += '}'
ret['powercap'][self.shortenkey(k)] = rlimit[k]['curW']
s += '}'
return s
return ret
def total_energy_json(self):
if not self.initialized():
......
"""Tests for the Coolr RAPL module."""
import nrm
import nrm.coolr
import nrm.coolr.clr_rapl
import pytest
@pytest.fixture
def rapl_reader():
"""Fixture for a regular rapl reader."""
rr = nrm.coolr.clr_rapl.rapl_reader()
assert rr.initialized(), "no rapl sysfs detected"
return rr
def test_read_powerdomains(rapl_reader):
"""Ensure we can read the power domains."""
assert rapl_reader.get_powerdomains()
def test_get_powerlimits(rapl_reader):
"""Ensure we can read the power limits."""
data = rapl_reader.get_powerlimits()
for k in data:
if data[k]['enabled']:
break
else:
assert False, "No power domain enabled."
def test_set_powerlimits(rapl_reader):
"""Ensure we can set a power limit."""
data = rapl_reader.get_powerlimits()
for k in data:
if data[k]['enabled']:
# compute a new limit in between cur and max
newlim = (data[k]['maxW'] - data[k]['curW'])/2.0
rapl_reader.set_powerlimit_pkg(newlim)
def test_sample(rapl_reader):
"""Ensure we can sample power consumption properly."""
import time
rapl_reader.start_energy_counter()
for i in range(0, 3):
time.sleep(1)
assert rapl_reader.sample(accflag=True)
rapl_reader.stop_energy_counter()
assert rapl_reader.total_energy_json()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment