summaryrefslogtreecommitdiff
path: root/esds/simulator.py
diff options
context:
space:
mode:
Diffstat (limited to 'esds/simulator.py')
-rw-r--r--esds/simulator.py42
1 files changed, 3 insertions, 39 deletions
diff --git a/esds/simulator.py b/esds/simulator.py
index 44c45c4..2ea77b9 100644
--- a/esds/simulator.py
+++ b/esds/simulator.py
@@ -2,6 +2,7 @@ import numpy as np
import threading,sys,time
from esds.node import Node
from esds.rcode import RCode
+from esds.debug import Debug
class Simulator:
"""
@@ -72,38 +73,6 @@ class Simulator:
event[2][6]=new_datasize_remaining
event[2][5]=new_duration
self.netmat=netmat
-
- def debug(self):
- """
- Log all the informations for debugging
- """
- with open(self.debug_file_path, "a") as debug_file:
- debug_file.write("-----------------------------------------------\n")
- debug_file.write("Started since {}s\n".format(round(time.time()-self.startat,2)))
- debug_file.write("Simulated time {}s (or more precisely {}s)\n".format(self.time_truncated,self.time))
- states=dict()
- timeout_mode=list()
- sharing=dict()
- for node in self.nodes:
- s=node["state"]
- states[s]=states[s]+1 if s in states else 1
- node_key="n"+str(node.node_id)
- for interface in self.sharing.keys():
- if self.sharing[interface][node.node_id] > 0:
- if node_key not in sharing:
- sharing[node_key] = ""
- sharing[node_key]+=str(int(self.sharing[interface][node.node_id]))
- debug_file.write("Node number per state: ")
- for key in states:
- debug_file.write(key+"="+str(states[key]))
- debug_file.write("\nNode sharing: ")
- for node_id in sharing:
- debug_file.write(node_id+"="+sharing[node_id])
- debug_file.write("\nIds of node in timeout mode: ")
- for n in timeout_mode:
- debug_file.write(n)
- debug_file.write("\nSorted events list:\n")
- debug_file.write(np.array_str(self.events)+"\n")
def create_node(self, src, args=None):
"""
@@ -393,12 +362,7 @@ class Simulator:
if breakpoints_every != None:
self.add_event(3,breakpoints_every,0,1)
if debug:
- with open(self.debug_file_path, "w") as f:
- f.write("Python version {}\n".format(sys.version))
- f.write("Simulation started at {}\n".format(self.startat))
- f.write("Number of nodes is "+str(len(self.nodes))+"\n")
- f.write("Manual breakpoints list: "+str(breakpoints)+"\n")
- f.write("Breakpoints every "+str(breakpoints_every)+"s\n")
+ self.debug=Debug(self,self.debug_file_path, breakpoints,breakpoints_every,interferences)
##### Simulation loop
while True:
# Synchronize non-blocking api calls
@@ -409,7 +373,7 @@ class Simulator:
self.sync_node_blocking(node)
# Generate debug logs
if debug:
- self.debug()
+ self.debug.debug()
# Simulation end
if len(self.events) <= 0 or len(self.events) == 1 and self.events[0,0] == 3:
# Notify nodes that wait for the end of the simulation