libsysprof-analyze: give counter values access to type

Otherwise they won't know how to return the proper value to callers.
This commit is contained in:
Christian Hergert
2023-06-27 15:50:10 -07:00
parent b5f3bd2b26
commit 4efb0abbf8
3 changed files with 25 additions and 5 deletions

View File

@ -25,6 +25,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
SysprofDocumentCounterValue *_sysprof_document_counter_value_new (const SysprofDocumentTimedValue *value); SysprofDocumentCounterValue *_sysprof_document_counter_value_new (guint type,
const SysprofDocumentTimedValue *value);
G_END_DECLS G_END_DECLS

View File

@ -26,12 +26,14 @@ struct _SysprofDocumentCounterValue
{ {
GObject parent_instance; GObject parent_instance;
SysprofDocumentTimedValue value; SysprofDocumentTimedValue value;
guint type;
}; };
enum { enum {
PROP_0, PROP_0,
PROP_TIME, PROP_TIME,
PROP_VALUE_DOUBLE, PROP_VALUE_DOUBLE,
PROP_VALUE_INT64,
N_PROPS N_PROPS
}; };
@ -57,6 +59,10 @@ sysprof_document_counter_value_get_property (GObject *object,
g_value_set_double (value, sysprof_document_counter_value_get_value_double (self)); g_value_set_double (value, sysprof_document_counter_value_get_value_double (self));
break; break;
case PROP_VALUE_INT64:
g_value_set_int64 (value, sysprof_document_counter_value_get_value_int64 (self));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@ -79,6 +85,11 @@ sysprof_document_counter_value_class_init (SysprofDocumentCounterValueClass *kla
-G_MAXDOUBLE, G_MAXDOUBLE, 0, -G_MAXDOUBLE, G_MAXDOUBLE, 0,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties[PROP_VALUE_INT64] =
g_param_spec_int64 ("value-int64", NULL, NULL,
G_MININT64, G_MAXINT64, 0,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
} }
@ -88,11 +99,13 @@ sysprof_document_counter_value_init (SysprofDocumentCounterValue *self)
} }
SysprofDocumentCounterValue * SysprofDocumentCounterValue *
_sysprof_document_counter_value_new (const SysprofDocumentTimedValue *value) _sysprof_document_counter_value_new (guint type,
const SysprofDocumentTimedValue *value)
{ {
SysprofDocumentCounterValue *self; SysprofDocumentCounterValue *self;
self = g_object_new (SYSPROF_TYPE_DOCUMENT_COUNTER_VALUE, NULL); self = g_object_new (SYSPROF_TYPE_DOCUMENT_COUNTER_VALUE, NULL);
self->type = type;
self->value = *value; self->value = *value;
return self; return self;
@ -124,11 +137,17 @@ sysprof_document_counter_value_get_value (SysprofDocumentCounterValue *self,
gint64 gint64
sysprof_document_counter_value_get_value_int64 (SysprofDocumentCounterValue *self) sysprof_document_counter_value_get_value_int64 (SysprofDocumentCounterValue *self)
{ {
return self->value.v_int64; if (self->type == SYSPROF_CAPTURE_COUNTER_INT64)
return self->value.v_int64;
else
return (gint64)self->value.v_double;
} }
double double
sysprof_document_counter_value_get_value_double (SysprofDocumentCounterValue *self) sysprof_document_counter_value_get_value_double (SysprofDocumentCounterValue *self)
{ {
return self->value.v_double; if (self->type == SYSPROF_CAPTURE_COUNTER_DOUBLE)
return self->value.v_double;
else
return (double)self->value.v_int64;
} }

View File

@ -74,7 +74,7 @@ sysprof_document_counter_get_item (GListModel *model,
value = &g_array_index (self->values, SysprofDocumentTimedValue, position); value = &g_array_index (self->values, SysprofDocumentTimedValue, position);
return _sysprof_document_counter_value_new (value); return _sysprof_document_counter_value_new (self->type, value);
} }
static void static void