From 55e463b963675070608b413d36d2395cc29792b6 Mon Sep 17 00:00:00 2001
From: Timothee 'TTimo' Besset <ttimo@valvesoftware.com>
Date: Thu, 15 Feb 2024 21:07:46 -0600
Subject: [PATCH] add a mechanism for async operations to report status
 updates. useful for RGP traces which can be slow to produce and download

---
 client/devkit_client/__init__.py  | 14 ++++++++++++++
 client/devkit_client/gui2/gui2.py |  6 ++++++
 2 files changed, 20 insertions(+)

diff --git a/client/devkit_client/__init__.py b/client/devkit_client/__init__.py
index e29256e..e80c67b 100644
--- a/client/devkit_client/__init__.py
+++ b/client/devkit_client/__init__.py
@@ -64,6 +64,7 @@ import paramiko
 import devkit_client.zeroconf as zeroconf
 import devkit_client.captured_popen as captured_popen
 import devkit_client.custom_terminal as custom_terminal
+import signalslot
 
 try:
     import devkit_client.version
@@ -129,6 +130,9 @@ g_custom_terminal = custom_terminal.CustomTerminal()
 
 g_zeroconf_listener = None
 
+# A signal emitted to update status for long running async operations, for interested parties
+g_signal_status = signalslot.Signal(args=['status'])
+
 # This burned me twice now .. https://twitter.com/TTimo/status/1582509449838989313
 from os import getenv as os_getenv
 def getenv_monkey(key, default=None):
@@ -1484,11 +1488,18 @@ def gpu_trace(args):
 
 
 def rgp_capture(args):
+    global g_signal_status
+    g_signal_status.emit(status='Trigger RGP collection...')
+
     ssh = _open_ssh_for_args(args)
 
     _simple_ssh(ssh, 'rm /tmp/*.rgp', silent=True)
+    # Steam client sets RADV_THREAD_TRACE_TRIGGER=/tmp/rgp.trigger
+    # we could set to a different path, but atm RADV always writes the trace to /tmp regardless of the location of the trigger
     _simple_ssh(ssh, 'touch /tmp/rgp.trigger', silent=True)
 
+    g_signal_status.emit(status='Wait for trace...')
+
     remote_filename = None
     filename_wait = time.time()
     while time.time() - filename_wait < 2:
@@ -1511,6 +1522,8 @@ def rgp_capture(args):
         size = updated_size
         time.sleep(.5)
 
+    g_signal_status.emit(status='Download trace...')
+
     # transfer
     os.makedirs(args.local_folder, exist_ok = True)
     local_path = os.path.join(args.local_folder, remote_filename)
@@ -1519,6 +1532,7 @@ def rgp_capture(args):
     logger.info(f'Downloaded to {local_path}')
 
     if args.launch:
+        g_signal_status.emit(status='Launch profiler...')
         if not os.path.exists(args.rgp_path):
             raise Exception(f'Invalid Radeon GPU Profiler path - does not exist: {args.rgp_path}')
         profiler_cmd = [args.rgp_path, local_path]
diff --git a/client/devkit_client/gui2/gui2.py b/client/devkit_client/gui2/gui2.py
index 1b28a58..2c57fac 100644
--- a/client/devkit_client/gui2/gui2.py
+++ b/client/devkit_client/gui2/gui2.py
@@ -2633,8 +2633,14 @@ class RGPCapture(SubTool):
             if rgp_path is None:
                 rgp_path = 'NOT SET'
             self.settings[self.RGP_KEY] = rgp_path
+        devkit_client.g_signal_status.connect(self._status_update)
         super(RGPCapture, self).setup()
 
+    def _status_update(self, status, **kwargs):
+        if not self.modal_wait:
+            return
+        self.modal_wait.override_output_text = status
+
     def devkits_window_draw(self, selected_devkit):
         imgui.text('Folder:')
         imgui.same_line()
-- 
GitLab