diff options
author | Richard Hughes <richard@hughsie.com> | 2015-09-28 13:48:28 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-09-28 13:48:28 +0100 |
commit | 56b61abea965c94246c957637cc5814285bdf1d2 (patch) | |
tree | 3efc20b047f2cab8a49ea0bb0b15a6bec0142d53 /libappstream-glib | |
parent | f635e4c5aec03c7c2882f6efd692d61d7e4d80fa (diff) | |
download | appstream-glib-56b61abea965c94246c957637cc5814285bdf1d2.tar.gz |
Add as_profile_set_autodump()
This makes it easier to profile GUI code that uses AppstreamGlib.
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-profile.c | 50 | ||||
-rw-r--r-- | libappstream-glib/as-profile.h | 3 |
2 files changed, 53 insertions, 0 deletions
diff --git a/libappstream-glib/as-profile.c b/libappstream-glib/as-profile.c index c0594b4..b2286f2 100644 --- a/libappstream-glib/as-profile.c +++ b/libappstream-glib/as-profile.c @@ -32,6 +32,7 @@ struct _AsProfile GPtrArray *archived; GMutex mutex; GThread *unthreaded; + guint autodump_id; }; typedef struct { @@ -234,7 +235,26 @@ as_profile_sort_cb (gconstpointer a, gconstpointer b) } /** + * as_profile_clear: + * @profile: A #AsProfile + * + * Clears the list of profiled events. + * + * Since: 0.2.2 + **/ +void +as_profile_clear (AsProfile *profile) +{ + g_ptr_array_set_size (profile->archived, 0); +} + +/** * as_profile_dump: + * @profile: A #AsProfile + * + * Dumps the current profiling table to stdout. + * + * Since: 0.2.2 **/ void as_profile_dump (AsProfile *profile) @@ -307,6 +327,34 @@ as_profile_dump (AsProfile *profile) } /** + * as_profile_autodump_cb: + **/ +static gboolean +as_profile_autodump_cb (gpointer user_data) +{ + AsProfile *profile = AS_PROFILE (user_data); + as_profile_dump (profile); + profile->autodump_id = 0; + return G_SOURCE_REMOVE; +} + +/** + * as_profile_set_autodump: + * @profile: A #AsProfile + * + * Dumps the current profiling table to stdout on a set interval. + * + * Since: 0.2.2 + **/ +void +as_profile_set_autodump (AsProfile *profile, guint delay) +{ + if (profile->autodump_id != 0) + g_source_remove (profile->autodump_id); + profile->autodump_id = g_timeout_add (delay, as_profile_autodump_cb, profile); +} + +/** * as_profile_finalize: **/ static void @@ -314,6 +362,8 @@ as_profile_finalize (GObject *object) { AsProfile *profile = AS_PROFILE (object); + if (profile->autodump_id != 0) + g_source_remove (profile->autodump_id); g_ptr_array_foreach (profile->current, (GFunc) as_profile_item_free, NULL); g_ptr_array_unref (profile->current); g_ptr_array_unref (profile->archived); diff --git a/libappstream-glib/as-profile.h b/libappstream-glib/as-profile.h index ea0d4e5..3e26df2 100644 --- a/libappstream-glib/as-profile.h +++ b/libappstream-glib/as-profile.h @@ -41,7 +41,10 @@ AsProfileTask *as_profile_start (AsProfile *profile, ...) G_GNUC_PRINTF (2, 3) G_GNUC_WARN_UNUSED_RESULT; +void as_profile_clear (AsProfile *profile); void as_profile_dump (AsProfile *profile); +void as_profile_set_autodump (AsProfile *profile, + guint delay); void as_profile_task_free (AsProfileTask *ptask); G_DEFINE_AUTOPTR_CLEANUP_FUNC(AsProfileTask, as_profile_task_free) |