Commit 5d292f9f authored by Sridutt Bhalachandra's avatar Sridutt Bhalachandra

[refactor] Diff calculation without coolr changes

Refactored diff calculation code to work without needing changes in
coolr module (Patch for Commit 36401a84)
parent 95188157
...@@ -142,12 +142,10 @@ class rapl_reader: ...@@ -142,12 +142,10 @@ class rapl_reader:
ret[k] = dvals ret[k] = dvals
return ret return ret
def diffenergy(self,e1,e2,shortenFlag=False): # e1 is prev and e2 is not def diffenergy(self,e1,e2): # e1 is prev and e2 is not
ret = {} ret = {}
ret['time'] = e2['time'] - e1['time'] ret['time'] = e2['time'] - e1['time']
for k in self.max_energy_range_uj_d: for k in self.max_energy_range_uj_d:
if shortenFlag:
k = self.shortenkey(k)
if e2[k]>=e1[k]: if e2[k]>=e1[k]:
ret[k] = e2[k] - e1[k] ret[k] = e2[k] - e1[k]
else: else:
...@@ -157,7 +155,7 @@ class rapl_reader: ...@@ -157,7 +155,7 @@ class rapl_reader:
# calculate the average power from two energy values # calculate the average power from two energy values
# e1 and e2 are the value returned from readenergy() # e1 and e2 are the value returned from readenergy()
# e1 should be sampled before e2 # e1 should be sampled before e2
def calcpower(self,e1,e2,shortenFlag=False): def calcpower(self,e1,e2):
ret = {} ret = {}
delta = e2['time'] - e1['time'] # assume 'time' never wrap around delta = e2['time'] - e1['time'] # assume 'time' never wrap around
ret['delta'] = delta ret['delta'] = delta
...@@ -168,8 +166,6 @@ class rapl_reader: ...@@ -168,8 +166,6 @@ class rapl_reader:
return ret return ret
for k in self.max_energy_range_uj_d: for k in self.max_energy_range_uj_d:
if shortenFlag:
k = self.shortenkey(k)
if e2[k]>=e1[k]: if e2[k]>=e1[k]:
ret[k] = e2[k] - e1[k] ret[k] = e2[k] - e1[k]
else: else:
......
...@@ -47,8 +47,15 @@ class SensorManager: ...@@ -47,8 +47,15 @@ class SensorManager:
def calc_difference(self, start, end): def calc_difference(self, start, end):
diff = dict() diff = dict()
for k in start.keys():
if k not in ['time']:
start[k.replace('p', 'package-')] = start[k]
start.pop(k)
end[k.replace('p', 'package-')] = end[k]
end.pop(k)
# Calculate energy difference # Calculate energy difference
diff['energy'] = self.rapl.diffenergy(start, end, shortenFlag=True) diff['energy'] = self.rapl.diffenergy(start, end)
# Update time elapsed # Update time elapsed
diff['time'] = diff['energy']['time'] diff['time'] = diff['energy']['time']
# Remove 'time' field returned by function # Remove 'time' field returned by function
...@@ -58,7 +65,7 @@ class SensorManager: ...@@ -58,7 +65,7 @@ class SensorManager:
diff['energy']} diff['energy']}
# Calculate power difference # Calculate power difference
diff['power'] = self.rapl.calcpower(start, end, shortenFlag=True) diff['power'] = self.rapl.calcpower(start, end)
# Remove 'delta' field returned by function # Remove 'delta' field returned by function
diff['power'].pop('delta') diff['power'].pop('delta')
......
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