From 3c03fcbfbbb2c515d0205e5d075083f0d5e5ba83 Mon Sep 17 00:00:00 2001 From: Ell Date: Sun, 1 Jul 2018 13:22:51 -0400 Subject: [PATCH] app: add active async-operations counter to the dashboard Add an "async" field to the dashboard's "misc" group, showing the number of async operations currently in the "running" state (i.e., all those GimpAsync objects for which gimp_async_finish[_full]() or gimp_async_abort() haven't been called yet). (cherry picked from commit aa382650a17c37978e8ac364f4944bbfdf328d92) --- app/core/gimpasync.c | 19 +++++++++ app/core/gimpasync.h | 5 +++ app/widgets/gimpdashboard.c | 83 +++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) diff --git a/app/core/gimpasync.c b/app/core/gimpasync.c index 8238aadc7f..4d572ffc4d 100644 --- a/app/core/gimpasync.c +++ b/app/core/gimpasync.c @@ -120,6 +120,11 @@ G_DEFINE_TYPE_WITH_CODE (GimpAsync, gimp_async, G_TYPE_OBJECT, #define parent_class gimp_async_parent_class +/* local variables */ + +static volatile gint gimp_async_n_running = 0; + + /* private functions */ @@ -159,6 +164,8 @@ gimp_async_init (GimpAsync *async) g_queue_init (&async->priv->callbacks); + g_atomic_int_inc (&gimp_async_n_running); + #ifdef TIME_ASYNC_OPS async->priv->start_time = g_get_monotonic_time (); #endif @@ -308,6 +315,8 @@ gimp_async_stop (GimpAsync *async) } #endif + g_atomic_int_dec_and_test (&gimp_async_n_running); + if (! g_queue_is_empty (&async->priv->callbacks)) { g_object_ref (async); @@ -587,3 +596,13 @@ gimp_async_cancel_and_wait (GimpAsync *async) gimp_cancelable_cancel (GIMP_CANCELABLE (async)); gimp_waitable_wait (GIMP_WAITABLE (async)); } + + +/* public functions (stats) */ + + +gint +gimp_async_get_n_running (void) +{ + return gimp_async_n_running; +} diff --git a/app/core/gimpasync.h b/app/core/gimpasync.h index afd34d6dcc..722dff710f 100644 --- a/app/core/gimpasync.h +++ b/app/core/gimpasync.h @@ -80,4 +80,9 @@ gboolean gimp_async_is_canceled (GimpAsync *async); void gimp_async_cancel_and_wait (GimpAsync *async); +/* stats */ + +gint gimp_async_get_n_running (void); + + #endif /* __GIMP_ASYNC_H__ */ diff --git a/app/widgets/gimpdashboard.c b/app/widgets/gimpdashboard.c index 2b4281a12a..230bade0cb 100644 --- a/app/widgets/gimpdashboard.c +++ b/app/widgets/gimpdashboard.c @@ -54,6 +54,7 @@ #include "core/gimp.h" #include "core/gimp-utils.h" +#include "core/gimpasync.h" #include "gimpactiongroup.h" #include "gimpdocked.h" @@ -120,6 +121,7 @@ typedef enum /* misc */ VARIABLE_MIPMAPED, + VARIABLE_ASYNC_RUNNING, N_VARIABLES, @@ -130,6 +132,7 @@ typedef enum typedef enum { VARIABLE_TYPE_BOOLEAN, + VARIABLE_TYPE_INTEGER, VARIABLE_TYPE_SIZE, VARIABLE_TYPE_SIZE_RATIO, VARIABLE_TYPE_INT_RATIO, @@ -209,6 +212,7 @@ struct _VariableData union { gboolean boolean; + gint integer; guint64 size; /* in bytes */ struct { @@ -306,6 +310,8 @@ static gpointer gimp_dashboard_sample (GimpDashboard static gboolean gimp_dashboard_update (GimpDashboard *dashboard); static gboolean gimp_dashboard_low_swap_space (GimpDashboard *dashboard); +static void gimp_dashboard_sample_function (GimpDashboard *dashboard, + Variable variable); static void gimp_dashboard_sample_gegl_config (GimpDashboard *dashboard, Variable variable); static void gimp_dashboard_sample_gegl_stats (GimpDashboard *dashboard, @@ -585,6 +591,15 @@ static const VariableInfo variables[] = .sample_func = gimp_dashboard_sample_gegl_stats, .data = "zoom-total" }, + + [VARIABLE_ASYNC_RUNNING] = + { .name = "async-running", + .title = NC_("dashboard-variable", "Async"), + .description = N_("Number of ongoing asynchronous operations"), + .type = VARIABLE_TYPE_INTEGER, + .sample_func = gimp_dashboard_sample_function, + .data = gimp_async_get_n_running + } }; static const GroupInfo groups[] = @@ -766,6 +781,9 @@ static const GroupInfo groups[] = { .variable = VARIABLE_MIPMAPED, .default_active = TRUE }, + { .variable = VARIABLE_ASYNC_RUNNING, + .default_active = TRUE + }, {} } @@ -1721,6 +1739,49 @@ gimp_dashboard_low_swap_space (GimpDashboard *dashboard) return G_SOURCE_REMOVE; } +static void +gimp_dashboard_sample_function (GimpDashboard *dashboard, + Variable variable) +{ + GimpDashboardPrivate *priv = dashboard->priv; + const VariableInfo *variable_info = &variables[variable]; + VariableData *variable_data = &priv->variables[variable]; + + #define CALL_FUNC(result_type) \ + (((result_type (*) (void)) variable_info->data) ()) + + switch (variable_info->type) + { + case VARIABLE_TYPE_BOOLEAN: + variable_data->value.boolean = CALL_FUNC (gboolean); + break; + + case VARIABLE_TYPE_INTEGER: + variable_data->value.integer = CALL_FUNC (gint); + + case VARIABLE_TYPE_SIZE: + variable_data->value.size = CALL_FUNC (guint64); + break; + + case VARIABLE_TYPE_PERCENTAGE: + variable_data->value.percentage = CALL_FUNC (gdouble); + break; + + case VARIABLE_TYPE_DURATION: + variable_data->value.duration = CALL_FUNC (gdouble); + break; + + case VARIABLE_TYPE_SIZE_RATIO: + case VARIABLE_TYPE_INT_RATIO: + g_return_if_reached (); + break; + } + + #undef CALL_FUNC + + variable_data->available = TRUE; +} + static void gimp_dashboard_sample_gegl_config (GimpDashboard *dashboard, Variable variable) @@ -2257,6 +2318,17 @@ gimp_dashboard_sample_object (GimpDashboard *dashboard, } break; + case VARIABLE_TYPE_INTEGER: + if (g_object_class_find_property (klass, variable_info->data)) + { + variable_data->available = TRUE; + + g_object_get (object, + variable_info->data, &variable_data->value.integer, + NULL); + } + break; + case VARIABLE_TYPE_SIZE: if (g_object_class_find_property (klass, variable_info->data)) { @@ -2737,6 +2809,9 @@ gimp_dashboard_variable_to_boolean (GimpDashboard *dashboard, case VARIABLE_TYPE_BOOLEAN: return variable_data->value.boolean; + case VARIABLE_TYPE_INTEGER: + return variable_data->value.integer != 0; + case VARIABLE_TYPE_SIZE: return variable_data->value.size > 0; @@ -2774,6 +2849,9 @@ gimp_dashboard_variable_to_double (GimpDashboard *dashboard, case VARIABLE_TYPE_BOOLEAN: return variable_data->value.boolean ? 1.0 : 0.0; + case VARIABLE_TYPE_INTEGER: + return variable_data->value.integer; + case VARIABLE_TYPE_SIZE: return variable_data->value.size; @@ -2830,6 +2908,11 @@ gimp_dashboard_field_to_string (GimpDashboard *dashboard, C_("dashboard-value", "No"); break; + case VARIABLE_TYPE_INTEGER: + str = g_strdup_printf ("%d", variable_data->value.integer); + static_str = FALSE; + break; + case VARIABLE_TYPE_SIZE: str = g_format_size_full (variable_data->value.size, G_FORMAT_SIZE_IEC_UNITS);