Commit 36401a84 by Sridutt Bhalachandra

### [Feature] Added diff calculation of stored values

```Made changes in `SensorManager` to allow calculation of the difference in measured
(stored) values using `rapl_reader` functions

See Issue #12```
parent a3b46d29
 ... ... @@ -142,10 +142,12 @@ class rapl_reader: ret[k] = dvals return ret def diffenergy(self,e1,e2): # e1 is prev and e2 is not def diffenergy(self,e1,e2,shortenFlag=False): # e1 is prev and e2 is not ret = {} ret['time'] = e2['time'] - e1['time'] for k in self.max_energy_range_uj_d: if shortenFlag: k = self.shortenkey(k) if e2[k]>=e1[k]: ret[k] = e2[k] - e1[k] else: ... ... @@ -155,7 +157,7 @@ class rapl_reader: # calculate the average power from two energy values # e1 and e2 are the value returned from readenergy() # e1 should be sampled before e2 def calcpower(self,e1,e2): def calcpower(self,e1,e2,shortenFlag=False): ret = {} delta = e2['time'] - e1['time'] # assume 'time' never wrap around ret['delta'] = delta ... ... @@ -166,6 +168,8 @@ class rapl_reader: return ret for k in self.max_energy_range_uj_d: if shortenFlag: k = self.shortenkey(k) if e2[k]>=e1[k]: ret[k] = e2[k] - e1[k] else: ... ...
 ... ... @@ -6,6 +6,7 @@ This module should be the only one interfacing with coolr. """ from __future__ import print_function import time import coolr import coolr.clr_rapl import coolr.clr_hwmon ... ... @@ -33,6 +34,7 @@ class SensorManager: machine_info = dict() machine_info['energy'] = self.rapl.sample(accflag=True) machine_info['temperature'] = self.coretemp.sample() machine_info['time'] = time.time() return machine_info def get_powerlimits(self): ... ... @@ -42,3 +44,22 @@ class SensorManager: def set_powerlimit(self, domain, value): self.rapl.set_powerlimit(value, domain) def calc_difference(self, start, end): diff = dict() # Calculate energy difference diff['energy'] = self.rapl.diffenergy(start, end, shortenFlag=True) # Update time elapsed diff['time'] = diff['energy']['time'] # Remove 'time' field returned by function diff['energy'].pop('time') # Convert uJ to J diff['energy'] = {k: diff['energy'][k]/(1000000.0) for k in diff['energy']} # Calculate power difference diff['power'] = self.rapl.calcpower(start, end, shortenFlag=True) # Remove 'delta' field returned by function diff['power'].pop('delta') return diff
Supports Markdown
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