@@ -30,8 +30,9 @@ class Sender(object):
30
30
action_mapping = format_actions (["/2.0" , "-10.0" , "+0.0" , "+10.0" , "*2.0" ])
31
31
action_cnt = len (action_mapping )
32
32
33
- def __init__ (self , port = 0 , train = False ):
33
+ def __init__ (self , port = 0 , train = False , debug = False ):
34
34
self .train = train
35
+ self .debug = debug
35
36
36
37
# UDP socket and poller
37
38
self .peer_addr = None
@@ -47,8 +48,9 @@ def __init__(self, port=0, train=False):
47
48
48
49
self .dummy_payload = 'x' * 1400
49
50
50
- self .sampling_file = open (path .join (project_root .DIR , 'env' , 'sampling_time' ), 'w' , 0 )
51
-
51
+ if self .debug :
52
+ self .sampling_file = open (path .join (project_root .DIR , 'env' , 'sampling_time' ), 'w' , 0 )
53
+
52
54
# congestion control related
53
55
self .seq_num = 0
54
56
self .next_ack = 0
@@ -75,7 +77,8 @@ def __init__(self, port=0, train=False):
75
77
self .rtt_buf = []
76
78
77
79
def cleanup (self ):
78
- self .sampling_file .close ()
80
+ if self .debug and self .sampling_file :
81
+ self .sampling_file .close ()
79
82
self .sock .close ()
80
83
81
84
def handshake (self ):
@@ -186,9 +189,13 @@ def recv(self):
186
189
self .cwnd ]
187
190
188
191
# time how long it takes to get an action from the NN
189
- start_sample = time .time ()
192
+ if self .debug :
193
+ start_sample = time .time ()
194
+
190
195
action = self .sample_action (state )
191
- self .sampling_file .write ('%.2f ms\n ' % ((time .time () - start_sample ) * 1000 ))
196
+
197
+ if self .debug :
198
+ self .sampling_file .write ('%.2f ms\n ' % ((time .time () - start_sample ) * 1000 ))
192
199
193
200
self .take_action (action )
194
201
0 commit comments