mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof-analyze: calculate counter range after adding values
Otherwise we are just calculating a null set.
This commit is contained in:
@ -24,11 +24,12 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
SysprofDocumentCounter *_sysprof_document_counter_new (guint id,
|
SysprofDocumentCounter *_sysprof_document_counter_new (guint id,
|
||||||
guint type,
|
guint type,
|
||||||
GRefString *category,
|
GRefString *category,
|
||||||
GRefString *name,
|
GRefString *name,
|
||||||
GRefString *description,
|
GRefString *description,
|
||||||
GArray *values);
|
GArray *values);
|
||||||
|
void _sysprof_document_counter_calculate_range (SysprofDocumentCounter *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@ -206,47 +206,6 @@ _sysprof_document_counter_new (guint id,
|
|||||||
self->description = description;
|
self->description = description;
|
||||||
self->values = values;
|
self->values = values;
|
||||||
|
|
||||||
if (type == SYSPROF_CAPTURE_COUNTER_DOUBLE)
|
|
||||||
{
|
|
||||||
double min_value = 0;
|
|
||||||
double max_value = 0;
|
|
||||||
|
|
||||||
for (guint i = 0; i < values->len; i++)
|
|
||||||
{
|
|
||||||
const SysprofDocumentTimedValue *value = &g_array_index (self->values, SysprofDocumentTimedValue, i);
|
|
||||||
double v = value->v_double;
|
|
||||||
|
|
||||||
if (v < min_value)
|
|
||||||
min_value = v;
|
|
||||||
|
|
||||||
if (v > max_value)
|
|
||||||
max_value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->min_value = min_value;
|
|
||||||
self->max_value = max_value;
|
|
||||||
}
|
|
||||||
else if (type == SYSPROF_CAPTURE_COUNTER_INT64)
|
|
||||||
{
|
|
||||||
gint64 min_value = 0;
|
|
||||||
gint64 max_value = 0;
|
|
||||||
|
|
||||||
for (guint i = 0; i < values->len; i++)
|
|
||||||
{
|
|
||||||
const SysprofDocumentTimedValue *value = &g_array_index (self->values, SysprofDocumentTimedValue, i);
|
|
||||||
gint64 v = value->v_int64;
|
|
||||||
|
|
||||||
if (v < min_value)
|
|
||||||
min_value = v;
|
|
||||||
|
|
||||||
if (v > max_value)
|
|
||||||
max_value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->min_value = min_value;
|
|
||||||
self->max_value = max_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,3 +312,59 @@ sysprof_document_counter_get_value_double (SysprofDocumentCounter *self,
|
|||||||
|
|
||||||
return g_array_index (self->values, SysprofDocumentTimedValue, nth).v_double;
|
return g_array_index (self->values, SysprofDocumentTimedValue, nth).v_double;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double
|
||||||
|
value_as_double (guint type,
|
||||||
|
const SysprofDocumentTimedValue *value)
|
||||||
|
{
|
||||||
|
if (type == SYSPROF_CAPTURE_COUNTER_DOUBLE)
|
||||||
|
return value->v_double;
|
||||||
|
else if (type == SYSPROF_CAPTURE_COUNTER_INT64)
|
||||||
|
return value->v_int64;
|
||||||
|
else
|
||||||
|
return .0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_sysprof_document_counter_calculate_range (SysprofDocumentCounter *self)
|
||||||
|
{
|
||||||
|
const SysprofDocumentTimedValue *values;
|
||||||
|
gboolean min_value_changed = FALSE;
|
||||||
|
gboolean max_value_changed = FALSE;
|
||||||
|
double min_value;
|
||||||
|
double max_value;
|
||||||
|
guint n_values;
|
||||||
|
|
||||||
|
g_return_if_fail (SYSPROF_IS_DOCUMENT_COUNTER (self));
|
||||||
|
|
||||||
|
if (self->values->len == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
values = &g_array_index (self->values, SysprofDocumentTimedValue, 0);
|
||||||
|
n_values = self->values->len;
|
||||||
|
|
||||||
|
min_value = value_as_double (self->type, &values[0]);
|
||||||
|
max_value = min_value;
|
||||||
|
|
||||||
|
for (guint i = 1; i < n_values; i++)
|
||||||
|
{
|
||||||
|
double value = value_as_double (self->type, &values[i]);
|
||||||
|
|
||||||
|
min_value = MIN (min_value, value);
|
||||||
|
max_value = MAX (max_value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
min_value_changed = self->min_value != min_value;
|
||||||
|
max_value_changed = self->max_value != max_value;
|
||||||
|
|
||||||
|
self->min_value = min_value;
|
||||||
|
self->max_value = max_value;
|
||||||
|
|
||||||
|
if (min_value_changed)
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MIN_VALUE]);
|
||||||
|
|
||||||
|
if (max_value_changed)
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAX_VALUE]);
|
||||||
|
|
||||||
|
g_print ("%s %lf..%lf\n", self->name, self->min_value, self->max_value);
|
||||||
|
}
|
||||||
|
|||||||
@ -588,6 +588,7 @@ sysprof_document_load_counters (SysprofDocument *self)
|
|||||||
g_autoptr(EggBitset) swap_ids = NULL;
|
g_autoptr(EggBitset) swap_ids = NULL;
|
||||||
GListModel *model;
|
GListModel *model;
|
||||||
EggBitsetIter iter;
|
EggBitsetIter iter;
|
||||||
|
guint n_counters;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_assert (SYSPROF_IS_DOCUMENT (self));
|
g_assert (SYSPROF_IS_DOCUMENT (self));
|
||||||
@ -613,7 +614,8 @@ sysprof_document_load_counters (SysprofDocument *self)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
g_autoptr(SysprofDocumentCtrdef) ctrdef = g_list_model_get_item (model, i);
|
g_autoptr(SysprofDocumentCtrdef) ctrdef = g_list_model_get_item (model, i);
|
||||||
guint n_counters = sysprof_document_ctrdef_get_n_counters (ctrdef);
|
|
||||||
|
n_counters = sysprof_document_ctrdef_get_n_counters (ctrdef);
|
||||||
|
|
||||||
for (guint j = 0; j < n_counters; j++)
|
for (guint j = 0; j < n_counters; j++)
|
||||||
{
|
{
|
||||||
@ -679,11 +681,23 @@ sysprof_document_load_counters (SysprofDocument *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((values = g_hash_table_lookup (self->counter_id_to_values, GUINT_TO_POINTER (id))))
|
if ((values = g_hash_table_lookup (self->counter_id_to_values, GUINT_TO_POINTER (id))))
|
||||||
|
{
|
||||||
|
g_print ("Adding counter to %d\n", id);
|
||||||
g_array_append_val (values, ctrval);
|
g_array_append_val (values, ctrval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (egg_bitset_iter_next (&iter, &i));
|
while (egg_bitset_iter_next (&iter, &i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n_counters = g_list_model_get_n_items (G_LIST_MODEL (self->counters));
|
||||||
|
|
||||||
|
for (i = 0; i < n_counters; i++)
|
||||||
|
{
|
||||||
|
g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (G_LIST_MODEL (self->counters), i);
|
||||||
|
|
||||||
|
_sysprof_document_counter_calculate_range (counter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline gboolean
|
static inline gboolean
|
||||||
|
|||||||
Reference in New Issue
Block a user