forked from Saher-Amasha/PythonProfiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiler_server.py
More file actions
39 lines (33 loc) · 1.36 KB
/
profiler_server.py
File metadata and controls
39 lines (33 loc) · 1.36 KB
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
import os
import socket
from controller import Model
from logic.stamps.memory_stamp import MemoryStamp
from logic.stamps.time_stamp import TimeStamp
class ProfilerServer:
HOST = os.environ.get('HOST', "127.0.0.1")
PORT = int(os.environ.get('PORT', "65434") )
@staticmethod
def run():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((ProfilerServer.HOST, ProfilerServer.PORT))
s.listen()
while True:
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
ProfilerServer.init_stamp_from_bytes(data)
if not data:
break
print(data)
@staticmethod
def init_stamp_from_bytes(data):
split_desc_string = data.decode('utf-8').split(';')
if len(split_desc_string) > 0 :
match split_desc_string[0]:
case 'time':
Model.add_time_stamp(split_desc_string[1],TimeStamp.init_from_bytes(split_desc_string[1:]))
case 'memory':
# TODO FIX
Model.add_memmory_stamp(split_desc_string[1],MemoryStamp.init_from_bytes(split_desc_string[1:]))