Add toggle menu to open pipeline perf monitor.

looper
Ben Niemann 2016-08-07 00:18:02 +02:00
parent 7855ded6d5
commit 8f936a5786
3 changed files with 33 additions and 11 deletions

View File

@ -218,7 +218,7 @@ class EditorApp(BaseEditorApp):
self._old_excepthook = None
self.win = None
self._pipeline_perf_monitor = None
self.pipeline_perf_monitor = None
async def setup(self):
logger.info("Installing custom excepthook.")
@ -230,14 +230,14 @@ class EditorApp(BaseEditorApp):
logger.info("Creating InstrumentLibrary.")
self.instrument_library = library.InstrumentLibrary()
logger.info("Creating PipelinePerfMonitor.")
self.pipeline_perf_monitor = pipeline_perf_monitor.PipelinePerfMonitor(self)
logger.info("Creating EditorWindow.")
self.win = EditorWindow(self)
await self.win.setup()
self.win.show()
self._pipeline_perf_monitor = pipeline_perf_monitor.PipelinePerfMonitor(self)
self._pipeline_perf_monitor.show()
if self.paths:
logger.info("Starting with projects from cmdline.")
for path in self.paths:
@ -266,9 +266,9 @@ class EditorApp(BaseEditorApp):
self.dumpSettings()
async def cleanup(self):
if self._pipeline_perf_monitor is not None:
self._pipeline_perf_monitor.storeState()
self._pipeline_perf_monitor = None
if self.pipeline_perf_monitor is not None:
self.pipeline_perf_monitor.storeState()
self.pipeline_perf_monitor = None
if self.win is not None:
await self.win.cleanup()
@ -303,6 +303,6 @@ class EditorApp(BaseEditorApp):
if 'utilization' in status:
pass
if 'perf_data' in status:
if self._pipeline_perf_monitor is not None:
self._pipeline_perf_monitor.addPerfData(
if self.pipeline_perf_monitor is not None:
self.pipeline_perf_monitor.addPerfData(
status['perf_data'])

View File

@ -261,6 +261,15 @@ class EditorWindow(ui_base.CommonMixin, QMainWindow):
"Stop",
self, triggered=self.onPlayerStop)
self._show_pipeline_perf_monitor_action = QAction(
"Pipeline Performance Monitor", self,
checkable=True,
checked=self.app.pipeline_perf_monitor.isVisible())
self._show_pipeline_perf_monitor_action.toggled.connect(
self.app.pipeline_perf_monitor.setVisible)
self.app.pipeline_perf_monitor.visibilityChanged.connect(
self._show_pipeline_perf_monitor_action.setChecked)
def createMenus(self):
menu_bar = self.menuBar()
@ -296,6 +305,8 @@ class EditorWindow(ui_base.CommonMixin, QMainWindow):
self._dev_menu.addAction(self._restart_clean_action)
self._dev_menu.addAction(self._crash_action)
self._dev_menu.addAction(self.app.show_edit_areas_action)
self._dev_menu.addAction(
self._show_pipeline_perf_monitor_action)
menu_bar.addSeparator()

View File

@ -4,6 +4,7 @@ import math
import time
from PyQt5.QtCore import Qt
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
@ -11,6 +12,8 @@ from . import ui_base
class PipelinePerfMonitor(ui_base.CommonMixin, QtWidgets.QMainWindow):
visibilityChanged = QtCore.pyqtSignal(bool)
def __init__(self, app):
super().__init__(app=app)
@ -19,7 +22,7 @@ class PipelinePerfMonitor(ui_base.CommonMixin, QtWidgets.QMainWindow):
self.current_spans = None
self.max_fps = 20
self.last_update = None
self.max_time_nsec = 100e6
self.max_time_nsec = 100000000
self.time_scale = 4096
self.setWindowTitle("noisicaä - Pipeline Performance Monitor")
@ -68,6 +71,14 @@ class PipelinePerfMonitor(ui_base.CommonMixin, QtWidgets.QMainWindow):
s.setValue('geometry', self.saveGeometry())
s.endGroup()
def showEvent(self, event):
self.visibilityChanged.emit(True)
super().showEvent(event)
def hideEvent(self, event):
self.visibilityChanged.emit(False)
super().hideEvent(event)
def onToggleRealtime(self):
if self.realtime:
self.realtime = False
@ -169,7 +180,7 @@ class PipelinePerfMonitor(ui_base.CommonMixin, QtWidgets.QMainWindow):
if num_purge > 0:
del self.history[:num_purge]
if self.realtime:
if self.realtime and self.isVisible():
now = time.time()
if (self.last_update is None
or now - self.last_update > 1.0 / self.max_fps):