[glib/task-trace: 2/5] trace: Add support for integer counters
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/task-trace: 2/5] trace: Add support for integer counters
- Date: Thu, 8 Oct 2020 23:10:36 +0000 (UTC)
commit 731796e5dd58dde7d71738571a9f12bf44350cf7
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Aug 21 11:48:40 2020 -0400
trace: Add support for integer counters
This will be used in GTask.
glib/gtrace-private.h | 11 +++++++++
glib/gtrace.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
---
diff --git a/glib/gtrace-private.h b/glib/gtrace-private.h
index 24550152d..41258ed6b 100644
--- a/glib/gtrace-private.h
+++ b/glib/gtrace-private.h
@@ -67,4 +67,15 @@ void (g_trace_mark) (gint64 begin_time_nsec,
#endif
#endif
+guint (g_trace_define_int_counter) (const char *group,
+ const char *name,
+ const char *description);
+void (g_trace_set_int_counter) (guint id,
+ gint64 value);
+
+#ifndef HAVE_SYSPROF
+#define g_trace_define_int_counter(g, n, d) 0
+#define g_trace_set_int_counter(i,v) 0
+#endif
+
G_END_DECLS
diff --git a/glib/gtrace.c b/glib/gtrace.c
index 29726778d..174e5233a 100644
--- a/glib/gtrace.c
+++ b/glib/gtrace.c
@@ -96,3 +96,68 @@ void
va_end (args);
#endif /* HAVE_SYSPROF */
}
+
+/*
+ * g_trace_define_int_counter:
+ * @group: name of the group for categorising this counter
+ * @name: name of the counter
+ * @description: description for the counter
+ *
+ * Defines a new counter with integer values.
+ *
+ * The name should be unique within all counters defined with
+ * the same @group. The description will be shown in the sysprof UI.
+ *
+ * To add entries for this counter to a trace, use
+ * g_trace_set_int_counter().
+ *
+ * Returns: ID of the counter, for use with g_trace_set_int_counter()
+ *
+ * Since: 2.68
+ */
+guint
+(g_trace_define_int_counter) (const char *group,
+ const char *name,
+ const char *description)
+{
+#ifdef HAVE_SYSPROF
+ SysprofCaptureCounter counter;
+
+ counter.id = sysprof_collector_request_counters (1);
+ counter.type = SYSPROF_CAPTURE_COUNTER_INT64;
+ counter.value.v64 = 0;
+ g_strlcpy (counter.category, group, sizeof counter.category);
+ g_strlcpy (counter.name, name, sizeof counter.name);
+ g_strlcpy (counter.description, description, sizeof counter.description);
+
+ sysprof_collector_define_counters (&counter, 1);
+
+ return counter.id;
+#else
+ return 0;
+#endif
+}
+
+/*
+ * g_trace_set_int_counter:
+ * @id: ID of the counter
+ * @val: the value to set the counter to
+ *
+ * Adds a counter value to a trace.
+ *
+ * The ID must be obtained via g_trace_define_int_counter()
+ * before using this function.
+ *
+ * Since: 2.68
+ */
+void
+(g_trace_set_int_counter) (guint id,
+ gint64 val)
+{
+#ifdef HAVE_SYSPROF
+ SysprofCaptureCounterValue value;
+
+ value.v64 = val;
+ sysprof_collector_set_counters (&id, &value, 1);
+#endif
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]