diff options
author | Richard Hughes <richard@hughsie.com> | 2016-09-14 12:46:39 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-09-14 12:46:39 +0100 |
commit | 4c2508c01a49c8c60482649375477d08167ecbc9 (patch) | |
tree | 42e77d0f5ac4800095cd318e43215b574ec6a6bc | |
parent | 8c2fcbfd9456bc1d11ef94ea66e37509ac7f6af7 (diff) | |
download | appstream-glib-4c2508c01a49c8c60482649375477d08167ecbc9.tar.gz |
Add as_profile_prune() for limiting the profiling output
-rw-r--r-- | libappstream-glib/as-profile.c | 32 | ||||
-rw-r--r-- | libappstream-glib/as-profile.h | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/libappstream-glib/as-profile.c b/libappstream-glib/as-profile.c index a99a047..5c733c8 100644 --- a/libappstream-glib/as-profile.c +++ b/libappstream-glib/as-profile.c @@ -238,6 +238,38 @@ as_profile_clear (AsProfile *profile) } /** + * as_profile_prune: + * @profile: A #AsProfile + * @duration: A time in ms + * + * Clears the list of profiled events older than @duration. + * + * Since: 0.6.4 + **/ +void +as_profile_prune (AsProfile *profile, guint duration) +{ + gint64 now; + guint i; + g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&profile->mutex); + g_autoptr(GPtrArray) removal = g_ptr_array_new (); + + /* find all events older than duration */ + now = g_get_real_time () / 1000; + for (i = 0; i < profile->archived->len; i++) { + AsProfileItem *item = g_ptr_array_index (profile->archived, i); + if (now - item->time_start / 1000 > duration) + g_ptr_array_add (removal, item); + } + + /* remove each one */ + for (i = 0; i < removal->len; i++) { + AsProfileItem *item = g_ptr_array_index (removal, i); + g_ptr_array_remove (profile->archived, item); + } +} + +/** * as_profile_dump: * @profile: A #AsProfile * diff --git a/libappstream-glib/as-profile.h b/libappstream-glib/as-profile.h index 3e26df2..fe883a3 100644 --- a/libappstream-glib/as-profile.h +++ b/libappstream-glib/as-profile.h @@ -42,6 +42,8 @@ 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_prune (AsProfile *profile, + guint duration); void as_profile_dump (AsProfile *profile); void as_profile_set_autodump (AsProfile *profile, guint delay); |