Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

print elasped time per frame

Endurance Idehen14a2d792fb58
diff --git a/requirements.txt b/requirements.txt
index f3ab8ea7..62d5706a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -24,5 +24,6 @@ sqlalchemy==1.4.31
singleton-decorator==1.0.0
orjson==3.6.7
aiomultiprocess==0.9.0
-faster-fifo==1.3.0
+# faster-fifo==1.3.0
+# viztracer==0.14.5
# Requirements for core-processor
diff --git a/src/api/routes/camera/cam_data_ws.py b/src/api/routes/camera/cam_data_ws.py
index 88579408..74e1cb6d 100644
--- a/src/api/routes/camera/cam_data_ws.py
+++ b/src/api/routes/camera/cam_data_ws.py
@@ -4,6 +4,7 @@ import logging
import cv2
import orjson
from fastapi import APIRouter, WebSocket
+from time import perf_counter
from jon_scratch.opencv_camera import OpenCVCamera
@@ -21,6 +22,7 @@ async def websocket_endpoint(websocket: WebSocket, webcam_id: str):
try:
while True:
+ t1_start = perf_counter()
success, image, timestamp = cam.get_next_frame()
if not success:
continue
@@ -36,6 +38,8 @@ async def websocket_endpoint(websocket: WebSocket, webcam_id: str):
}
d = orjson.dumps(d)
await websocket.send_bytes(d)
+ t1_stop = perf_counter()
+ print("Elapsed time per frame:", t1_stop-t1_start)
except:
logger.info(f"Camera {webcam_id} is now closed.")
cam.close()
diff --git a/src/core_processor/app_events/event_notify.py b/src/core_processor/app_events/event_notify.py
index 69e69b50..78d40cfd 100644
--- a/src/core_processor/app_events/event_notify.py
+++ b/src/core_processor/app_events/event_notify.py
@@ -1,4 +1,3 @@
-import asyncio
import logging
import multiprocessing
@@ -16,12 +15,11 @@ class EventNotifier:
async def notify_all_subscribers(self, queue: multiprocessing.Queue):
while True:
try:
- message = queue.get(timeout=1)
+ message = queue.get(timeout=.1)
for worker in self._workers:
await worker.process(message)
except Exception as e:
- print(e)
- logger.error("Notifier dead")
+ pass
def _construct(self):
return [sub() for sub in subscribers]
diff --git a/src/core_processor/board_detection/detect.py b/src/core_processor/board_detection/detect.py
index 57c3bcd4..62cea399 100644
--- a/src/core_processor/board_detection/detect.py
+++ b/src/core_processor/board_detection/detect.py
@@ -9,4 +9,5 @@ class BoardDetection:
pass
async def process(self, message, *args, **kwargs):
+ # logger.info(message)
logger.info(message["timestamp"])
diff --git a/src/core_processor/ws_connection.py b/src/core_processor/ws_connection.py
index 96e06b0c..b5d74b60 100644
--- a/src/core_processor/ws_connection.py
+++ b/src/core_processor/ws_connection.py
@@ -14,10 +14,8 @@ class WSConnection:
async for websocket in websockets.connect(uri, max_size=None, ping_timeout=None):
try:
async for message in websocket:
- # How expensive is it to parse a json string?
as_json = orjson.loads(message)
- logger.info(f"webcam_id: {webcam_id}, msg rcv")
- queue.put(as_json, timeout=1)
+ queue.put_nowait(as_json)
except websockets.ConnectionClosed as e:
logger.error(e)
continue