Jitter monitor phase 0
This commit is contained in:
parent
7391b4e61c
commit
8c60d6a03d
27
app/jittermonitor.py
Normal file
27
app/jittermonitor.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from PyQt6.QtCore import QObject, QTimer, QElapsedTimer, pyqtSignal
|
||||||
|
|
||||||
|
class EventLoopJitterMonitor(QObject):
|
||||||
|
long_pause_detected = pyqtSignal(float) # pause length in ms
|
||||||
|
|
||||||
|
def __init__(self, parent=None, interval_ms: int = 20, threshold_ms: int = 80):
|
||||||
|
super().__init__(parent)
|
||||||
|
self._interval = interval_ms
|
||||||
|
self._threshold = threshold_ms
|
||||||
|
self._timer = QTimer(self)
|
||||||
|
self._timer.setInterval(self._interval)
|
||||||
|
self._timer.timeout.connect(self._on_timeout)
|
||||||
|
self._elapsed = QElapsedTimer()
|
||||||
|
self._elapsed.start()
|
||||||
|
self._last = self._elapsed.elapsed()
|
||||||
|
|
||||||
|
def start(self) -> None:
|
||||||
|
self._timer.start()
|
||||||
|
|
||||||
|
def _on_timeout(self) -> None:
|
||||||
|
now = self._elapsed.elapsed()
|
||||||
|
delta = now - self._last # ms since last timeout
|
||||||
|
self._last = now
|
||||||
|
if delta > self._interval + self._threshold:
|
||||||
|
# log somewhere with timestamp + current track + position
|
||||||
|
print(f"[JITTER] {delta} ms gap in event loop")
|
||||||
|
self.long_pause_detected.emit(delta)
|
||||||
@ -90,6 +90,7 @@ from ui.main_window_footer_ui import Ui_FooterSection # type: ignore
|
|||||||
from utilities import check_db, update_bitrates
|
from utilities import check_db, update_bitrates
|
||||||
import helpers
|
import helpers
|
||||||
|
|
||||||
|
from jittermonitor import EventLoopJitterMonitor
|
||||||
|
|
||||||
class Current:
|
class Current:
|
||||||
base_model: PlaylistModel
|
base_model: PlaylistModel
|
||||||
@ -1206,6 +1207,9 @@ class Window(QMainWindow):
|
|||||||
self.action_quicklog = QShortcut(QKeySequence("Ctrl+L"), self)
|
self.action_quicklog = QShortcut(QKeySequence("Ctrl+L"), self)
|
||||||
self.action_quicklog.activated.connect(self.quicklog)
|
self.action_quicklog.activated.connect(self.quicklog)
|
||||||
|
|
||||||
|
self.jitter_monitor = EventLoopJitterMonitor(self)
|
||||||
|
self.jitter_monitor.start()
|
||||||
|
|
||||||
self.load_last_playlists()
|
self.load_last_playlists()
|
||||||
self.stop_autoplay = False
|
self.stop_autoplay = False
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user