mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 23:46:17 +01:00
trace: Add support for integer counters
This will be used in GTask.
This commit is contained in:
parent
ab65fb1951
commit
0a4803a063
@ -67,4 +67,15 @@ void (g_trace_mark) (gint64 begin_time_nsec,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
guint (g_trace_define_int64_counter) (const char *group,
|
||||
const char *name,
|
||||
const char *description);
|
||||
void (g_trace_set_int64_counter) (guint id,
|
||||
gint64 value);
|
||||
|
||||
#ifndef HAVE_SYSPROF
|
||||
#define g_trace_define_int64_counter(g, n, d) ((guint) -1)
|
||||
#define g_trace_set_int64_counter(i,v)
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -96,3 +96,82 @@ void
|
||||
va_end (args);
|
||||
#endif /* HAVE_SYSPROF */
|
||||
}
|
||||
|
||||
/*
|
||||
* g_trace_define_int64_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_int64_counter().
|
||||
*
|
||||
* Returns: ID of the counter, for use with g_trace_set_int64_counter(),
|
||||
* guaranteed to never be zero
|
||||
*
|
||||
* Since: 2.68
|
||||
*/
|
||||
guint
|
||||
(g_trace_define_int64_counter) (const char *group,
|
||||
const char *name,
|
||||
const char *description)
|
||||
{
|
||||
#ifdef HAVE_SYSPROF
|
||||
SysprofCaptureCounter counter;
|
||||
|
||||
counter.id = sysprof_collector_request_counters (1);
|
||||
|
||||
/* sysprof not enabled? */
|
||||
if (counter.id == 0)
|
||||
return (guint) -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);
|
||||
|
||||
g_assert (counter.id != 0);
|
||||
|
||||
return counter.id;
|
||||
#else
|
||||
return (guint) -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* g_trace_set_int64_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_int64_counter()
|
||||
* before using this function.
|
||||
*
|
||||
* Since: 2.68
|
||||
*/
|
||||
void
|
||||
(g_trace_set_int64_counter) (guint id,
|
||||
gint64 val)
|
||||
{
|
||||
#ifdef HAVE_SYSPROF
|
||||
SysprofCaptureCounterValue value;
|
||||
|
||||
g_return_if_fail (id != 0);
|
||||
|
||||
/* Ignore setting the counter if we failed to define it in the first place. */
|
||||
if (id == (guint) -1)
|
||||
return;
|
||||
|
||||
value.v64 = val;
|
||||
sysprof_collector_set_counters (&id, &value, 1);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user