mirror of
https://gitlab.com/manzerbredes/esds.git
synced 2025-04-07 02:26:28 +02:00
Improve debug
This commit is contained in:
parent
c4509c7a26
commit
bc4ce548db
2 changed files with 12 additions and 2 deletions
|
@ -11,6 +11,7 @@ class Debug:
|
||||||
self.simulator=simulator
|
self.simulator=simulator
|
||||||
self.file_path=file_path
|
self.file_path=file_path
|
||||||
self.loop_count=0
|
self.loop_count=0
|
||||||
|
self.logs=list()
|
||||||
header={
|
header={
|
||||||
"python_version" : sys.version,
|
"python_version" : sys.version,
|
||||||
"simulation_started_at": simulator.startat,
|
"simulation_started_at": simulator.startat,
|
||||||
|
@ -20,6 +21,9 @@ class Debug:
|
||||||
}
|
}
|
||||||
self.write(header,append=False)
|
self.write(header,append=False)
|
||||||
|
|
||||||
|
def append_log(self,log):
|
||||||
|
self.logs.append(log)
|
||||||
|
|
||||||
def write(self,data, append=True):
|
def write(self,data, append=True):
|
||||||
mode="a" if append else "w"
|
mode="a" if append else "w"
|
||||||
with open(self.file_path, mode) as f:
|
with open(self.file_path, mode) as f:
|
||||||
|
@ -95,6 +99,8 @@ class Debug:
|
||||||
"simulated_time_accurate": self.simulator.time,
|
"simulated_time_accurate": self.simulator.time,
|
||||||
"network_interfaces": self.get_network_interfaces(),
|
"network_interfaces": self.get_network_interfaces(),
|
||||||
"events_list": self.get_events_list(),
|
"events_list": self.get_events_list(),
|
||||||
"nodes_infos": self.get_nodes_infos()
|
"nodes_infos": self.get_nodes_infos(),
|
||||||
|
"logs": self.logs
|
||||||
}
|
}
|
||||||
self.write(loop_data)
|
self.write(loop_data)
|
||||||
|
self.logs.clear()
|
||||||
|
|
|
@ -50,6 +50,7 @@ class Simulator:
|
||||||
self.interferences=True
|
self.interferences=True
|
||||||
self.wait_end_nodes=list() # Keep track of nodes that wait for the end of the simulation
|
self.wait_end_nodes=list() # Keep track of nodes that wait for the end of the simulation
|
||||||
self.time_truncated=format(self.time,self.precision) # Truncated version is used in log print
|
self.time_truncated=format(self.time,self.precision) # Truncated version is used in log print
|
||||||
|
self.debug=None # No debug by default
|
||||||
|
|
||||||
def update_network(self,netmat):
|
def update_network(self,netmat):
|
||||||
for event in self.events:
|
for event in self.events:
|
||||||
|
@ -85,7 +86,10 @@ class Simulator:
|
||||||
|
|
||||||
def log(self,msg,node=None):
|
def log(self,msg,node=None):
|
||||||
src = "esds" if node is None else "n"+str(node)
|
src = "esds" if node is None else "n"+str(node)
|
||||||
print("[t="+str(self.time_truncated)+",src="+src+"] "+msg)
|
logline="[t="+str(self.time_truncated)+",src="+src+"] "+msg
|
||||||
|
if self.debug is not None:
|
||||||
|
self.debug.append_log(logline)
|
||||||
|
print(logline)
|
||||||
|
|
||||||
def sort_events(self):
|
def sort_events(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue