diff options
author | Marek Olšák <[email protected]> | 2017-02-11 20:46:02 +0100 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-02-14 21:47:51 +0100 |
commit | 579ffe81f1365d5cbe785283b2a7f96ccaabafcc (patch) | |
tree | ddca1a58607d3c4b30205b7601678f33e026ee4e /src/gallium/auxiliary/hud/hud_cpu.c | |
parent | 626e4ef18f1ffc521ab3e6faef3173abedd52dbf (diff) |
gallium/hud: add monitoring of API thread busy status
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/hud/hud_cpu.c')
-rw-r--r-- | src/gallium/auxiliary/hud/hud_cpu.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c index c65444e1e56..a8d97b81f35 100644 --- a/src/gallium/auxiliary/hud/hud_cpu.c +++ b/src/gallium/auxiliary/hud/hud_cpu.c @@ -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); +} |