-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_process.py
105 lines (97 loc) · 4.43 KB
/
log_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import multiprocessing as mp
import queue
from common_utils import MODE_SCHEDULING_RANDOM
class LogProcess(mp.Process):
'''
This process is responsible for logging the scheduling samples.
There are two scheduling samples:
1) Data returned by a scheduler running infinitely that will be further processed for training
2) Data returned by the ATHENA/srsRAN scheduler that are used to evaluate the solutions
'''
def __init__(self, log_queue: mp.Queue, scheduling_mode, log_file, stop_flag: mp.Value):
super(LogProcess, self).__init__()
self.log_queue = log_queue
self.scheduling_mode = scheduling_mode
self.log_file = log_file
self.stop_flag = stop_flag
def run(self):
import signal
signal.signal(signal.SIGINT , self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
if (self.scheduling_mode == MODE_SCHEDULING_RANDOM):
self.sched_mode_random()
else:
self.sched_mode_inference()
print('Log thread exiting...')
def exit_gracefully(self, signum, frame):
self.stop_flag.value = 1
def sched_mode_random(self):
with open(self.log_file, 'w') as file:
file.write('|'.join(['cpu', 'snr', 'mcs', 'prb', 'crc', 'decoding_time', 'snr_decode', 'noise_decode', 'snr_decode_custom', 'gain']) + '\n')
sample_idx = 0
while self.stop_flag.value == 0:
try:
sample = self.log_queue.get(block = True, timeout = 2)
timestamp = sample['timestamp']
tti = sample['tti']
hrq = sample['hrq']
mcs = sample['mcs']
prb = sample['prb']
tbs = sample['tbs']
crc = sample['crc']
dec_time = sample['dec_time']
cpu = sample['cpu']
snr = sample['snr']
gain = sample['gain']
snr_decode = sample['snr_decode']
noise_decode = sample['noise_decode']
snr_custom = sample['snr_custom']
fields = [cpu, snr, mcs, prb, crc, dec_time, snr_decode, noise_decode, snr_custom, gain]
record = [str(x) for x in fields]
file.write('|'.join(record) + '\n')
sample_idx += 1
if (sample_idx == 10):
file.flush()
sample_idx = 0
except queue.Empty:
pass
def sched_mode_inference(self):
columns = [
'timestamp', 'tti', 'hrq',
'mcs', 'prb', 'tbs',
'crc' , 'dec_time',
'cpu', 'snr', 'gain', 'snr_decode', 'noise_decode', 'snr_decode_custom']
with open(self.log_file, 'w') as file:
file.write('|'.join(columns) + '\n')
sample_idx = 0
while self.stop_flag.value == 0:
try:
sample = self.log_queue.get(block = True, timeout = 2)
timestamp = sample['timestamp']
tti = sample['tti']
hrq = sample['hrq']
mcs = sample['mcs']
prb = sample['prb']
tbs = sample['tbs']
crc = sample['crc']
dec_time = sample['dec_time']
cpu = sample['cpu']
snr = sample['snr']
gain = sample['gain']
snr_decode = sample['snr_decode']
noise_decode = sample['noise_decode']
snr_custom = sample['snr_custom']
fields = [
timestamp, tti, hrq,
mcs, prb, tbs,
crc, dec_time,
cpu, snr, gain, snr_decode, noise_decode, snr_custom
]
record = [str(x) for x in fields]
file.write('|'.join(record) + '\n')
sample_idx += 1
if (sample_idx == 10):
file.flush()
sample_idx = 0
except queue.Empty:
pass