summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-09-14 12:55:34 +0100
committerRichard Hughes <richard@hughsie.com>2016-09-14 12:55:46 +0100
commit793ed55702bdc6efea0d1526012e7bf34728e3df (patch)
tree7e896d0cc7c076f50493bd1b982d9dc4e78a9a29
parent4c2508c01a49c8c60482649375477d08167ecbc9 (diff)
downloadappstream-glib-793ed55702bdc6efea0d1526012e7bf34728e3df.tar.gz
Add as_profile_set_autoprune() for automatically limiting the profiling output
-rw-r--r--libappstream-glib/as-profile.c21
-rw-r--r--libappstream-glib/as-profile.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/libappstream-glib/as-profile.c b/libappstream-glib/as-profile.c
index 5c733c8..87a1f83 100644
--- a/libappstream-glib/as-profile.c
+++ b/libappstream-glib/as-profile.c
@@ -33,6 +33,7 @@ struct _AsProfile
GMutex mutex;
GThread *unthreaded;
guint autodump_id;
+ guint autoprune_duration;
};
typedef struct {
@@ -120,6 +121,10 @@ as_profile_start_literal (AsProfile *profile, const gchar *id)
g_return_val_if_fail (AS_IS_PROFILE (profile), NULL);
g_return_val_if_fail (id != NULL, NULL);
+ /* autoprune old data */
+ if (profile->autoprune_duration != 0)
+ as_profile_prune (profile, profile->autoprune_duration);
+
/* only use the thread ID when not using the main thread */
self = g_thread_self ();
if (self != profile->unthreaded) {
@@ -270,6 +275,22 @@ as_profile_prune (AsProfile *profile, guint duration)
}
/**
+ * as_profile_set_autoprune:
+ * @profile: A #AsProfile
+ * @duration: A time in ms
+ *
+ * Automatically prunes events older than @duration when new ones are added.
+ *
+ * Since: 0.6.4
+ **/
+void
+as_profile_set_autoprune (AsProfile *profile, guint duration)
+{
+ profile->autoprune_duration = duration;
+ as_profile_prune (profile, duration);
+}
+
+/**
* as_profile_dump:
* @profile: A #AsProfile
*
diff --git a/libappstream-glib/as-profile.h b/libappstream-glib/as-profile.h
index fe883a3..9662ee4 100644
--- a/libappstream-glib/as-profile.h
+++ b/libappstream-glib/as-profile.h
@@ -47,6 +47,8 @@ void as_profile_prune (AsProfile *profile,
void as_profile_dump (AsProfile *profile);
void as_profile_set_autodump (AsProfile *profile,
guint delay);
+void as_profile_set_autoprune (AsProfile *profile,
+ guint duration);
void as_profile_task_free (AsProfileTask *ptask);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(AsProfileTask, as_profile_task_free)