diff --git a/src/sglib/lib/engine.py b/src/sglib/lib/engine.py index 78d8fa38..c86ed9f0 100644 --- a/src/sglib/lib/engine.py +++ b/src/sglib/lib/engine.py @@ -25,13 +25,14 @@ ] ENGINE_SUBPROCESS = None +ENGINE_PSUTIL = None def close_engine(): """ Ask the engine to gracefully stop itself, then kill the process if it doesn't exit on it's own """ constants.IPC.stop_server() - global ENGINE_SUBPROCESS + global ENGINE_SUBPROCESS, ENGINE_PSUTIL if ENGINE_SUBPROCESS is not None: f_exited = False for i in range(50): @@ -53,6 +54,7 @@ def close_engine(): ) LOG.exception(ex) ENGINE_SUBPROCESS = None + ENGINE_PSUTIL = None if os.path.exists(ENGINE_PIDFILE): os.remove(ENGINE_PIDFILE) constants.READY = False @@ -99,7 +101,6 @@ def open_engine(a_project_path, fps): f_pid = os.getpid() LOG.info(f"Starting audio engine with {a_project_path}") - global ENGINE_SUBPROCESS threads = int(util.DEVICE_SETTINGS['threads']) if threads == 0: @@ -125,6 +126,10 @@ def reopen_engine(): constants.IPC_ENABLED = True def run_engine(cmd): - global ENGINE_SUBPROCESS + global ENGINE_SUBPROCESS, ENGINE_PSUTIL ENGINE_SUBPROCESS = run_process(cmd, ENGINE_PIDFILE) + try: + ENGINE_PSUTIL = psutil.Process(ENGINE_SUBPROCESS.pid) + except: + LOG.exception('Could not create ENGINE_PSUTIL') diff --git a/src/sglib/lib/strings.py b/src/sglib/lib/strings.py index b7de8db1..60faab10 100644 --- a/src/sglib/lib/strings.py +++ b/src/sglib/lib/strings.py @@ -130,3 +130,8 @@ will pass-through any audio from items or sends. """ +ENGINE_MON = """\ +Shows CPU and memory percentage. Note that the CPU usage is a max of the +cores that are in use, not based on the average of CPU load and available +logical cores, which is less useful. +""" diff --git a/src/sgui/daw/entrypoint.py b/src/sgui/daw/entrypoint.py index 5723d68c..91d1c0cb 100644 --- a/src/sgui/daw/entrypoint.py +++ b/src/sgui/daw/entrypoint.py @@ -77,6 +77,10 @@ def __init__(self): self.last_midi_dir = None shared.ROUTING_GRAPH_WIDGET.setToolTip(sg_strings.routing_graph) + self.engine_mon_label = QLabel() + self.engine_mon_label.setToolTip(sg_strings.ENGINE_MON) + self.setCornerWidget(self.engine_mon_label) + self.setObjectName("plugin_ui") # Transport shortcuts (added here so they will work diff --git a/src/sgui/main.py b/src/sgui/main.py index bf3de5ff..6874e427 100644 --- a/src/sgui/main.py +++ b/src/sgui/main.py @@ -125,6 +125,7 @@ class SgMainWindow(QWidget): } daw_callback = Signal(str) wave_edit_callback = Signal(str) + engine_mon_callback = Signal(str) def __init__(self): super().__init__() @@ -204,6 +205,13 @@ def setup(self, scaler): self.current_module = daw self.current_window = daw.MAIN_WINDOW + self.engine_mon_callback.connect( + daw.MAIN_WINDOW.engine_mon_label.setText + ) + self.engine_mon_callback.connect( + wave_edit.MAIN_WINDOW.engine_mon_label.setText + ) + for f_module in shared.HOST_MODULES: self.transport_stack.addWidget(f_module.TRANSPORT.group_box) @@ -751,6 +759,14 @@ def timeout_handler(): f_window.exec() def subprocess_monitor(self): + try: + if engine.ENGINE_PSUTIL: + cpu = round(engine.ENGINE_PSUTIL.cpu_percent(), 1) + mem = round(engine.ENGINE_PSUTIL.memory_percent(), 1) + text = f'CPU: {cpu}% RAM: {mem}%' + self.engine_mon_callback.emit(text) + except: + pass try: if ( engine.ENGINE_SUBPROCESS diff --git a/src/sgui/wave_edit/__init__.py b/src/sgui/wave_edit/__init__.py index 3dc1f6a7..510ff602 100644 --- a/src/sgui/wave_edit/__init__.py +++ b/src/sgui/wave_edit/__init__.py @@ -499,6 +499,10 @@ def __init__(self): self.main_tabwidget = QTabWidget() self.main_layout.addWidget(self.main_tabwidget) + self.engine_mon_label = QLabel() + self.engine_mon_label.setToolTip(sg_strings.ENGINE_MON) + self.main_tabwidget.setCornerWidget(self.engine_mon_label) + self.main_tabwidget.addTab(WAVE_EDITOR.widget, _("Wave Editor")) self.notes_tab = ProjectNotes(