Commit ec563afb authored by Swann Perarnau's avatar Swann Perarnau
Browse files

Partial Revert of powercap API update

Previous commit 0c93ce6a broke the
sample code used by the daemon, by reverting the sample function to a
json message generator. This is due to inconsistencies between the coolr
code and the NRM import: we removed json generation from coolr, to push
it on the messaging side, while upstream still does it on sensor
reading.

This commit fixes that, but doesn't touch the new test code embedded in
clr_rapl.py
We will move that the test infrastructure later.
parent 0c93ce6a
...@@ -214,7 +214,7 @@ class rapl_reader: ...@@ -214,7 +214,7 @@ class rapl_reader:
e = self.read_energy_acc() e = self.read_energy_acc()
self.stop_time = time.time() self.stop_time = time.time()
def sample_and_json(self, label = "", accflag = False, node = ""): def sample(self, accflag=False):
if not self.initialized(): if not self.initialized():
return return
...@@ -226,55 +226,32 @@ class rapl_reader: ...@@ -226,55 +226,32 @@ class rapl_reader:
if k != 'time': if k != 'time':
if accflag: if accflag:
self.totalenergy[k] += de[k] 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 self.prev_e = e
# constructing a json output ret = dict()
s = '{"sample":"energy","time":%.3f' % (e['time']) ret['energy'] = dict()
if len(node) > 0:
s += ',"node":"%s"' % node
if len(label) > 0:
s += ',"label":"%s"' % label
s += ',"energy":{'
firstitem = True
for k in sorted(e.keys()): for k in sorted(e.keys()):
if k != 'time': if k != 'time':
if firstitem: ret['energy'][self.shortenkey(k)] = e[k]
firstitem = False
else:
s+=','
s += '"%s":%d' % (self.shortenkey(k), e[k])
s += '},'
s += '"power":{'
ret['power'] = dict()
totalpower = 0.0 totalpower = 0.0
firstitem = True
for k in sorted(self.lastpower.keys()): for k in sorted(self.lastpower.keys()):
if k != 'time': if k != 'time':
if firstitem: ret['power'][self.shortenkey(k)] = self.lastpower[k]
firstitem = False # this is a bit ad hoc way to calculate the total.
else: # needs to be fixed later
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
if k.find("core") == -1: if k.find("core") == -1:
totalpower += self.lastpower[k] totalpower += self.lastpower[k]
s += ',"total":%.1f' % (totalpower) ret['power']['total'] = totalpower
s += '},'
s += '"powercap":{' ret['powercap'] = dict()
rlimit = self.readpowerlimitall() rlimit = self.readpowerlimitall()
firstitem = True
for k in sorted(rlimit.keys()): for k in sorted(rlimit.keys()):
if firstitem: ret['powercap'][self.shortenkey(k)] = rlimit[k]['curW']
firstitem = False
else:
s+=','
s += '"%s":%.1f' % (self.shortenkey(k), rlimit[k]['curW'])
s += '}'
s += '}' return ret
return s
def total_energy_json(self): def total_energy_json(self):
if not self.initialized(): if not self.initialized():
......
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