[glib: 5/6] gtask: Improve task names used internally within GLib



commit b08bd04abe0d031fb7baa4ad2147ebe07c4a7521
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Jun 25 23:36:08 2020 +0100

    gtask: Improve task names used internally within GLib
    
    And improve them externally, where not otherwise set, by setting them
    from the function name passed to `g_task_set_source_tag()`, if called by
    third party code.
    
    This should make profiling and debug output from GLib more useful.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 gio/gasyncinitable.c         | 1 +
 gio/gdbusinterfaceskeleton.c | 1 +
 gio/gdbusprivate.c           | 2 ++
 gio/gdbusproxy.c             | 3 +++
 gio/gresolver.c              | 3 +++
 gio/gtask.c                  | 5 +++--
 gio/gtask.h                  | 8 ++++++++
 gio/gthreadedresolver.c      | 7 +++++++
 gio/gtlsdatabase.c           | 4 ++++
 gio/gunixmount.c             | 8 +++++---
 gio/gunixvolume.c            | 8 +++++---
 11 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/gio/gasyncinitable.c b/gio/gasyncinitable.c
index 8936f98b2..6af650688 100644
--- a/gio/gasyncinitable.c
+++ b/gio/gasyncinitable.c
@@ -87,6 +87,7 @@
  *   GTask *task;
  *
  *   task = g_task_new (initable, cancellable, callback, user_data);
+ *   g_task_set_name (task, G_STRFUNC);
  *
  *   switch (self->priv->state)
  *     {
diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
index 4a06516c1..a0125c541 100644
--- a/gio/gdbusinterfaceskeleton.c
+++ b/gio/gdbusinterfaceskeleton.c
@@ -632,6 +632,7 @@ g_dbus_interface_method_dispatch_helper (GDBusInterfaceSkeleton       *interface
 
       task = g_task_new (interface, NULL, NULL, NULL);
       g_task_set_source_tag (task, g_dbus_interface_method_dispatch_helper);
+      g_task_set_name (task, "[gio] D-Bus interface method dispatch");
       g_task_set_task_data (task, data, (GDestroyNotify) dispatch_data_unref);
       g_task_run_in_thread (task, dispatch_in_thread_func);
       g_object_unref (task);
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index 8526f6925..5c980b40b 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -183,6 +183,7 @@ _g_socket_read_with_control_messages (GSocket                 *socket,
 
   task = g_task_new (socket, cancellable, callback, user_data);
   g_task_set_source_tag (task, _g_socket_read_with_control_messages);
+  g_task_set_name (task, "[gio] D-Bus read");
   g_task_set_task_data (task, data, (GDestroyNotify) read_with_control_data_free);
 
   if (g_socket_condition_check (socket, G_IO_IN))
@@ -1123,6 +1124,7 @@ write_message_async (GDBusWorker         *worker,
 {
   data->task = g_task_new (NULL, NULL, callback, user_data);
   g_task_set_source_tag (data->task, write_message_async);
+  g_task_set_name (data->task, "[gio] D-Bus write message");
   data->total_written = 0;
   write_message_continue_writing (data);
 }
diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c
index 4c682978d..45fa99a17 100644
--- a/gio/gdbusproxy.c
+++ b/gio/gdbusproxy.c
@@ -1631,6 +1631,7 @@ async_initable_init_second_async (GAsyncInitable      *initable,
 
   task = g_task_new (proxy, cancellable, callback, user_data);
   g_task_set_source_tag (task, async_initable_init_second_async);
+  g_task_set_name (task, "[gio] D-Bus proxy init");
   g_task_set_priority (task, io_priority);
 
   /* Check name ownership asynchronously - possibly also start the service */
@@ -1802,6 +1803,7 @@ async_initable_init_async (GAsyncInitable      *initable,
 
   task = g_task_new (proxy, cancellable, callback, user_data);
   g_task_set_source_tag (task, async_initable_init_async);
+  g_task_set_name (task, "[gio] D-Bus proxy init");
   g_task_set_priority (task, io_priority);
 
   if (proxy->priv->bus_type != G_BUS_TYPE_NONE)
@@ -2649,6 +2651,7 @@ g_dbus_proxy_call_internal (GDBusProxy          *proxy,
       my_callback = (GAsyncReadyCallback) reply_cb;
       task = g_task_new (proxy, cancellable, callback, user_data);
       g_task_set_source_tag (task, g_dbus_proxy_call_internal);
+      g_task_set_name (task, "[gio] D-Bus proxy call");
     }
   else
     {
diff --git a/gio/gresolver.c b/gio/gresolver.c
index 651e7d0ef..cd5445a65 100644
--- a/gio/gresolver.c
+++ b/gio/gresolver.c
@@ -576,6 +576,7 @@ lookup_by_name_async_real (GResolver                *resolver,
 
       task = g_task_new (resolver, cancellable, callback, user_data);
       g_task_set_source_tag (task, lookup_by_name_async_real);
+      g_task_set_name (task, "[gio] resolver lookup");
       if (addrs)
         g_task_return_pointer (task, addrs, (GDestroyNotify) g_resolver_free_addresses);
       else
@@ -595,6 +596,7 @@ lookup_by_name_async_real (GResolver                *resolver,
                            _("Invalid hostname"));
       task = g_task_new (resolver, cancellable, callback, user_data);
       g_task_set_source_tag (task, lookup_by_name_async_real);
+      g_task_set_name (task, "[gio] resolver lookup");
       g_task_return_error (task, error);
       g_object_unref (task);
       return;
@@ -613,6 +615,7 @@ lookup_by_name_async_real (GResolver                *resolver,
                        _("%s not implemented"), "lookup_by_name_with_flags_async");
           task = g_task_new (resolver, cancellable, callback, user_data);
           g_task_set_source_tag (task, lookup_by_name_async_real);
+          g_task_set_name (task, "[gio] resolver lookup");
           g_task_return_error (task, error);
           g_object_unref (task);
         }
diff --git a/gio/gtask.c b/gio/gtask.c
index fc992c7f9..9a5c14850 100644
--- a/gio/gtask.c
+++ b/gio/gtask.c
@@ -759,6 +759,7 @@ g_task_report_error (gpointer             source_object,
 
   task = g_task_new (source_object, NULL, callback, callback_data);
   g_task_set_source_tag (task, source_tag);
+  g_task_set_name (task, G_STRFUNC);
   g_task_return_error (task, error);
   g_object_unref (task);
 }
@@ -982,8 +983,8 @@ g_task_set_return_on_cancel (GTask    *task,
  * Since: 2.36
  */
 void
-g_task_set_source_tag (GTask    *task,
-                       gpointer  source_tag)
+(g_task_set_source_tag) (GTask    *task,
+                         gpointer  source_tag)
 {
   g_return_if_fail (G_IS_TASK (task));
 
diff --git a/gio/gtask.h b/gio/gtask.h
index 73a31e157..08ed7be72 100644
--- a/gio/gtask.h
+++ b/gio/gtask.h
@@ -78,6 +78,14 @@ GLIB_AVAILABLE_IN_2_60
 void          g_task_set_name              (GTask               *task,
                                             const gchar         *name);
 
+/* Macro wrapper to set the task name when setting the source tag. */
+#define g_task_set_source_tag(task, tag) G_STMT_START { \
+  GTask *_task = (task); \
+  (g_task_set_source_tag) (_task, tag); \
+  if (g_task_get_name (_task) == NULL) \
+    g_task_set_name (_task, G_STRINGIFY (tag)); \
+} G_STMT_END
+
 GLIB_AVAILABLE_IN_2_36
 gpointer      g_task_get_source_object     (GTask               *task);
 GLIB_AVAILABLE_IN_2_36
diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c
index 3486162e5..48435b36f 100644
--- a/gio/gthreadedresolver.c
+++ b/gio/gthreadedresolver.c
@@ -187,6 +187,7 @@ lookup_by_name (GResolver     *resolver,
   data = lookup_data_new (hostname, AF_UNSPEC);
   task = g_task_new (resolver, cancellable, NULL, NULL);
   g_task_set_source_tag (task, lookup_by_name);
+  g_task_set_name (task, "[gio] resolver lookup");
   g_task_set_task_data (task, data, (GDestroyNotify)lookup_data_free);
   g_task_set_return_on_cancel (task, TRUE);
   g_task_run_in_thread_sync (task, do_lookup_by_name);
@@ -228,6 +229,7 @@ lookup_by_name_with_flags (GResolver                 *resolver,
   data = lookup_data_new (hostname, AF_UNSPEC);
   task = g_task_new (resolver, cancellable, NULL, NULL);
   g_task_set_source_tag (task, lookup_by_name_with_flags);
+  g_task_set_name (task, "[gio] resolver lookup");
   g_task_set_task_data (task, data, (GDestroyNotify)lookup_data_free);
   g_task_set_return_on_cancel (task, TRUE);
   g_task_run_in_thread_sync (task, do_lookup_by_name);
@@ -251,6 +253,7 @@ lookup_by_name_with_flags_async (GResolver                *resolver,
   data = lookup_data_new (hostname, flags_to_family (flags));
   task = g_task_new (resolver, cancellable, callback, user_data);
   g_task_set_source_tag (task, lookup_by_name_with_flags_async);
+  g_task_set_name (task, "[gio] resolver lookup");
   g_task_set_task_data (task, data, (GDestroyNotify)lookup_data_free);
   g_task_set_return_on_cancel (task, TRUE);
   g_task_run_in_thread (task, do_lookup_by_name);
@@ -350,6 +353,7 @@ lookup_by_address (GResolver        *resolver,
 
   task = g_task_new (resolver, cancellable, NULL, NULL);
   g_task_set_source_tag (task, lookup_by_address);
+  g_task_set_name (task, "[gio] resolver lookup");
   g_task_set_task_data (task, g_object_ref (address), g_object_unref);
   g_task_set_return_on_cancel (task, TRUE);
   g_task_run_in_thread_sync (task, do_lookup_by_address);
@@ -370,6 +374,7 @@ lookup_by_address_async (GResolver           *resolver,
 
   task = g_task_new (resolver, cancellable, callback, user_data);
   g_task_set_source_tag (task, lookup_by_address_async);
+  g_task_set_name (task, "[gio] resolver lookup");
   g_task_set_task_data (task, g_object_ref (address), g_object_unref);
   g_task_set_return_on_cancel (task, TRUE);
   g_task_run_in_thread (task, do_lookup_by_address);
@@ -1040,6 +1045,7 @@ lookup_records (GResolver              *resolver,
 
   task = g_task_new (resolver, cancellable, NULL, NULL);
   g_task_set_source_tag (task, lookup_records);
+  g_task_set_name (task, "[gio] resolver lookup records");
 
   lrd = g_slice_new (LookupRecordsData);
   lrd->rrname = g_strdup (rrname);
@@ -1067,6 +1073,7 @@ lookup_records_async (GResolver           *resolver,
 
   task = g_task_new (resolver, cancellable, callback, user_data);
   g_task_set_source_tag (task, lookup_records_async);
+  g_task_set_name (task, "[gio] resolver lookup records");
 
   lrd = g_slice_new (LookupRecordsData);
   lrd->rrname = g_strdup (rrname);
diff --git a/gio/gtlsdatabase.c b/gio/gtlsdatabase.c
index 256369da3..9341206f1 100644
--- a/gio/gtlsdatabase.c
+++ b/gio/gtlsdatabase.c
@@ -186,6 +186,7 @@ g_tls_database_real_verify_chain_async (GTlsDatabase           *self,
 
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task, g_tls_database_real_verify_chain_async);
+  g_task_set_name (task, "[gio] verify TLS chain");
   g_task_set_task_data (task, args, async_verify_chain_free);
   g_task_run_in_thread (task, async_verify_chain_thread);
   g_object_unref (task);
@@ -264,6 +265,7 @@ g_tls_database_real_lookup_certificate_for_handle_async (GTlsDatabase
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task,
                          g_tls_database_real_lookup_certificate_for_handle_async);
+  g_task_set_name (task, "[gio] lookup TLS certificate");
   g_task_set_task_data (task, args, async_lookup_certificate_for_handle_free);
   g_task_run_in_thread (task, async_lookup_certificate_for_handle_thread);
   g_object_unref (task);
@@ -338,6 +340,7 @@ g_tls_database_real_lookup_certificate_issuer_async (GTlsDatabase           *sel
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task,
                          g_tls_database_real_lookup_certificate_issuer_async);
+  g_task_set_name (task, "[gio] lookup certificate issuer");
   g_task_set_task_data (task, args, async_lookup_certificate_issuer_free);
   g_task_run_in_thread (task, async_lookup_certificate_issuer_thread);
   g_object_unref (task);
@@ -419,6 +422,7 @@ g_tls_database_real_lookup_certificates_issued_by_async (GTlsDatabase
   task = g_task_new (self, cancellable, callback, user_data);
   g_task_set_source_tag (task,
                          g_tls_database_real_lookup_certificates_issued_by_async);
+  g_task_set_name (task, "[gio] lookup certificates issued by");
   g_task_set_task_data (task, args, async_lookup_certificates_issued_by_free);
   g_task_run_in_thread (task, async_lookup_certificates_issued_by_thread);
   g_object_unref (task);
diff --git a/gio/gunixmount.c b/gio/gunixmount.c
index 0a6d7f3bf..acfebffdd 100644
--- a/gio/gunixmount.c
+++ b/gio/gunixmount.c
@@ -302,7 +302,8 @@ eject_unmount_do (GMount              *mount,
                   GCancellable        *cancellable,
                   GAsyncReadyCallback  callback,
                   gpointer             user_data,
-                  char               **argv)
+                  char               **argv,
+                  const gchar         *task_name)
 {
   GUnixMount *unix_mount = G_UNIX_MOUNT (mount);
   GTask *task;
@@ -310,6 +311,7 @@ eject_unmount_do (GMount              *mount,
 
   task = g_task_new (mount, cancellable, callback, user_data);
   g_task_set_source_tag (task, eject_unmount_do);
+  g_task_set_name (task, task_name);
   g_task_set_task_data (task, g_strdupv (argv), (GDestroyNotify) g_strfreev);
 
   if (unix_mount->volume_monitor != NULL)
@@ -337,7 +339,7 @@ g_unix_mount_unmount (GMount             *mount,
   else
     argv[1] = unix_mount->device_path;
 
-  eject_unmount_do (mount, cancellable, callback, user_data, argv);
+  eject_unmount_do (mount, cancellable, callback, user_data, argv, "[gio] unmount mount");
 }
 
 static gboolean
@@ -363,7 +365,7 @@ g_unix_mount_eject (GMount             *mount,
   else
     argv[1] = unix_mount->device_path;
 
-  eject_unmount_do (mount, cancellable, callback, user_data, argv);
+  eject_unmount_do (mount, cancellable, callback, user_data, argv, "[gio] eject mount");
 }
 
 static gboolean
diff --git a/gio/gunixvolume.c b/gio/gunixvolume.c
index a3768e11d..60ae628a2 100644
--- a/gio/gunixvolume.c
+++ b/gio/gunixvolume.c
@@ -305,7 +305,8 @@ eject_mount_do (GVolume              *volume,
                 GCancellable         *cancellable,
                 GAsyncReadyCallback   callback,
                 gpointer              user_data,
-                const gchar * const  *argv)
+                const gchar * const  *argv,
+                const gchar          *task_name)
 {
   GSubprocess *subprocess;
   GError *error = NULL;
@@ -313,6 +314,7 @@ eject_mount_do (GVolume              *volume,
 
   task = g_task_new (volume, cancellable, callback, user_data);
   g_task_set_source_tag (task, eject_mount_do);
+  g_task_set_name (task, task_name);
 
   if (g_task_return_error_if_cancelled (task))
     {
@@ -344,7 +346,7 @@ g_unix_volume_mount (GVolume            *volume,
   else
     argv[1] = unix_volume->device_path;
 
-  eject_mount_do (volume, cancellable, callback, user_data, argv);
+  eject_mount_do (volume, cancellable, callback, user_data, argv, "[gio] mount volume");
 }
 
 static gboolean
@@ -369,7 +371,7 @@ g_unix_volume_eject (GVolume             *volume,
 
   argv[1] = unix_volume->device_path;
 
-  eject_mount_do (volume, cancellable, callback, user_data, argv);
+  eject_mount_do (volume, cancellable, callback, user_data, argv, "[gio] eject volume");
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]