diff --git a/src/libsysprof-analyze/sysprof-document-counter-private.h b/src/libsysprof-analyze/sysprof-document-counter-private.h index 821d2bbc..b76ee679 100644 --- a/src/libsysprof-analyze/sysprof-document-counter-private.h +++ b/src/libsysprof-analyze/sysprof-document-counter-private.h @@ -24,11 +24,12 @@ G_BEGIN_DECLS -SysprofDocumentCounter *_sysprof_document_counter_new (guint id, - guint type, - GRefString *category, - GRefString *name, - GRefString *description, - GArray *values); +SysprofDocumentCounter *_sysprof_document_counter_new (guint id, + guint type, + GRefString *category, + GRefString *name, + GRefString *description, + GArray *values); +void _sysprof_document_counter_calculate_range (SysprofDocumentCounter *self); G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-document-counter.c b/src/libsysprof-analyze/sysprof-document-counter.c index 5487088c..ccced724 100644 --- a/src/libsysprof-analyze/sysprof-document-counter.c +++ b/src/libsysprof-analyze/sysprof-document-counter.c @@ -206,47 +206,6 @@ _sysprof_document_counter_new (guint id, self->description = description; 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; } @@ -353,3 +312,59 @@ sysprof_document_counter_get_value_double (SysprofDocumentCounter *self, 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); +} diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index def8fa8f..1d974c6e 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -588,6 +588,7 @@ sysprof_document_load_counters (SysprofDocument *self) g_autoptr(EggBitset) swap_ids = NULL; GListModel *model; EggBitsetIter iter; + guint n_counters; guint i; g_assert (SYSPROF_IS_DOCUMENT (self)); @@ -613,7 +614,8 @@ sysprof_document_load_counters (SysprofDocument *self) do { 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++) { @@ -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)))) + { + g_print ("Adding counter to %d\n", id); g_array_append_val (values, ctrval); + } } } 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