gallium/hud: add monitoring of API thread busy status
authorMarek Olšák <marek.olsak@amd.com>
Sat, 11 Feb 2017 19:46:02 +0000 (20:46 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 14 Feb 2017 20:47:51 +0000 (21:47 +0100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/hud/hud_context.c
src/gallium/auxiliary/hud/hud_cpu.c
src/gallium/auxiliary/hud/hud_private.h

index 57d189fbc523c5dbb9e6e16537a6d2de5c470995..9de260c6cbb0047689dd5bbb26ab2414d9e2614b 100644 (file)
@@ -1149,6 +1149,9 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
       else if (sscanf(name, "cpu%u%s", &i, s) == 1) {
          hud_cpu_graph_install(pane, i);
       }
+      else if (strcmp(name, "API-thread-busy") == 0) {
+         hud_api_thread_busy_install(pane);
+      }
 #if HAVE_GALLIUM_EXTRA_HUD
       else if (sscanf(name, "nic-rx-%s", arg_name) == 1) {
          hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_RX);
index c65444e1e561f87326a56055f6686acd5dcc6663..a8d97b81f356d43c2e69b8775924ab2c5b0654a9 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "hud/hud_private.h"
 #include "os/os_time.h"
+#include "os/os_thread.h"
 #include "util/u_memory.h"
 #include <stdio.h>
 #include <inttypes.h>
@@ -230,3 +231,62 @@ hud_get_num_cpus(void)
 
    return i;
 }
+
+struct thread_info {
+   int64_t last_time;
+   int64_t last_thread_time;
+};
+
+static void
+query_api_thread_busy_status(struct hud_graph *gr)
+{
+   struct thread_info *info = gr->query_data;
+   int64_t now = os_time_get_nano();
+
+   if (info->last_time) {
+      if (info->last_time + gr->pane->period*1000 <= now) {
+         int64_t thread_now = pipe_current_thread_get_time_nano();
+
+         hud_graph_add_value(gr,
+                             (thread_now - info->last_thread_time) * 100 /
+                             (now - info->last_time));
+
+         info->last_thread_time = thread_now;
+         info->last_time = now;
+      }
+   } else {
+      /* initialize */
+      info->last_time = now;
+      info->last_thread_time = pipe_current_thread_get_time_nano();
+   }
+}
+
+void
+hud_api_thread_busy_install(struct hud_pane *pane)
+{
+   struct hud_graph *gr;
+
+   gr = CALLOC_STRUCT(hud_graph);
+   if (!gr)
+      return;
+
+   strcpy(gr->name, "API-thread-busy");
+
+   gr->query_data = CALLOC_STRUCT(thread_info);
+   if (!gr->query_data) {
+      FREE(gr);
+      return;
+   }
+
+   gr->query_new_value = query_api_thread_busy_status;
+
+   /* Don't use free() as our callback as that messes up Gallium's
+    * memory debugger.  Use simple free_query_data() wrapper.
+    */
+   gr->free_query_data = free_query_data;
+
+   hud_graph_set_dump_file(gr);
+
+   hud_pane_add_graph(pane, gr);
+   hud_pane_set_max_value(pane, 100);
+}
index b23439e5c662782bf82b76cfd28e8a0b75c1eb70..1d06e03dbe507dc772f58968956c3d045b0fd3e9 100644 (file)
@@ -93,6 +93,7 @@ int hud_get_num_cpus(void);
 
 void hud_fps_graph_install(struct hud_pane *pane);
 void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);
+void hud_api_thread_busy_install(struct hud_pane *pane);
 void hud_pipe_query_install(struct hud_batch_query_context **pbq,
                             struct hud_pane *pane, struct pipe_context *pipe,
                             const char *name, unsigned query_type,