summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--esds/plugins/power_states.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/esds/plugins/power_states.py b/esds/plugins/power_states.py
index 144deed..f8af5ad 100644
--- a/esds/plugins/power_states.py
+++ b/esds/plugins/power_states.py
@@ -5,8 +5,8 @@ from .node_plugin import NodePlugin
# PowerStates allows you to measure the energy consumption of a
# node that go through several power states during the simulation
# Two version of Powerstates is provided by mean of two classes:
-# - Powerstates: Allow you to set power to any user's defined values
-# - PowerstatesFromFile: Allow you to set power from states defined in a file
+# - Powerstates: Allow you to set the node power consumption to arbitraries values
+# - PowerstatesFromFile: Allow you to set the node power consumption from power values defined in a file
######################
# _ ____ ___ #
@@ -19,7 +19,7 @@ from .node_plugin import NodePlugin
# #Regarding PowerStates:
# import Powerstates as ps
-# pstates=ps.PowerStates(<node>,<power_init>)
+# pstates=ps.PowerStates(<api>,<power_init>)
# pstates.set_power(<power>) # Switch the power consumption to <power>
# pstates.report_energy() # Display the current node energy consumption up to the current simulated time
# pstates.report_power_changes() # Display all the power changes up to the current simulated time
@@ -28,7 +28,7 @@ from .node_plugin import NodePlugin
# #Format of <file> is one <entry> per line that follow this format <state-0>:<state-1>:...:<state-n>
# #Each line can corresponds to one node (line 0 for node 0 etc..)
# import Powerstates as ps
-# pstates=ps.PowerStatesFromFile(<node>,<file>,<entry-line>) # Create a power states on node <node> using line <entry-line> of file <file>
+# pstates=ps.PowerStatesFromFile(<api>,<file>,<entry-line>) # Create a power states on a node that uses <api> using line <entry-line> of file <file>
# pstates.set_state(<id>) # Switch to the <id> power states
# pstates.report_energy() # Display the current node energy consumption up to the current simulated time
# pstates.report_power_changes() # Display all the power changes up to the current simulated time
@@ -39,18 +39,17 @@ class PowerStates(NodePlugin):
"""
PowerStates model the energy consumed by the various changes of power consumption of a node over time.
"""
- def __init__(self,node,power_init):
- self.node=node
- self.clock=self.node.read("clock")
+ def __init__(self,api,power_init):
+ super().__init__("Powerstates",api)
+ self.clock=self.api.read("clock")
self.energy=0
self.power=power_init
self.power_changes=dict()
self.set_power(power_init)
- super().__init__("Powerstates",api)
def set_power(self,power_watt):
- cur_clock=self.node.read("clock")
+ cur_clock=self.api.read("clock")
self.energy+=self.power*(cur_clock-self.clock)
self.clock=cur_clock
if self.power != power_watt:
@@ -60,12 +59,12 @@ class PowerStates(NodePlugin):
def report_energy(self):
self.set_power(self.power)
- self.node.log("[PowerStates Plugin] Consumed "+str(self.energy) +"J")
+ self.log("Consumed "+str(self.energy) +"J")
def report_power_changes(self):
self.set_power(self.power)
for key in self.power_changes.keys():
- self.node.log("[PowerStates Plugin] At t="+str(key)+" power is "+str(self.power_changes[key])+"W")
+ self.log("At t="+str(key)+" power is "+str(self.power_changes[key])+"W")
@@ -73,8 +72,7 @@ class PowerStatesFromFile(PowerStates):
"""
A version of Powerstates that load the power values from a file.
"""
- def __init__(self,node,state_file,entry_line=1):
- self.node=node
+ def __init__(self,api,state_file,entry_line=1):
self.state_changes=dict()
self.states=[]
self.state=0
@@ -84,7 +82,7 @@ class PowerStatesFromFile(PowerStates):
self.states=line.split(":")
self.states=[float(i) for i in self.states]
assert len(self.states) > 0
- super().__init__(node,self.states[0])
+ super().__init__(api,self.states[0])
self.set_state(0)
def set_state(self,state_id):
@@ -98,7 +96,7 @@ class PowerStatesFromFile(PowerStates):
def report_state_changes(self):
self.set_state(self.state)
for key in self.state_changes.keys():
- self.node.log("[PowerStates Plugin] At t="+str(key)+" state is "+str(self.state_changes[key]))
+ self.log("At t="+str(key)+" state is "+str(self.state_changes[key]))
class PowerStatesComms(NodePlugin):