mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 07:00:53 +00:00
libsysprof-analyze: pre-calculate ranges for counters
This commit is contained in:
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "sysprof-document-counter.h"
|
#include "sysprof-document-counter.h"
|
||||||
#include "sysprof-document-counter-value-private.h"
|
#include "sysprof-document-counter-value-private.h"
|
||||||
#include "sysprof-document-private.h"
|
#include "sysprof-document-private.h"
|
||||||
@ -31,6 +33,8 @@ struct _SysprofDocumentCounter
|
|||||||
GRefString *description;
|
GRefString *description;
|
||||||
GRefString *name;
|
GRefString *name;
|
||||||
GArray *values;
|
GArray *values;
|
||||||
|
double min_value;
|
||||||
|
double max_value;
|
||||||
guint id;
|
guint id;
|
||||||
guint type;
|
guint type;
|
||||||
};
|
};
|
||||||
@ -40,6 +44,8 @@ enum {
|
|||||||
PROP_CATEGORY,
|
PROP_CATEGORY,
|
||||||
PROP_DESCRIPTION,
|
PROP_DESCRIPTION,
|
||||||
PROP_ID,
|
PROP_ID,
|
||||||
|
PROP_MAX_VALUE,
|
||||||
|
PROP_MIN_VALUE,
|
||||||
PROP_NAME,
|
PROP_NAME,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
@ -115,6 +121,14 @@ sysprof_document_counter_get_property (GObject *object,
|
|||||||
g_value_set_string (value, sysprof_document_counter_get_description (self));
|
g_value_set_string (value, sysprof_document_counter_get_description (self));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_MIN_VALUE:
|
||||||
|
g_value_set_double (value, self->min_value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_MAX_VALUE:
|
||||||
|
g_value_set_double (value, self->max_value);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_NAME:
|
case PROP_NAME:
|
||||||
g_value_set_string (value, sysprof_document_counter_get_name (self));
|
g_value_set_string (value, sysprof_document_counter_get_name (self));
|
||||||
break;
|
break;
|
||||||
@ -156,6 +170,16 @@ sysprof_document_counter_class_init (SysprofDocumentCounterClass *klass)
|
|||||||
NULL,
|
NULL,
|
||||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
properties[PROP_MIN_VALUE] =
|
||||||
|
g_param_spec_double ("min-value", NULL, NULL,
|
||||||
|
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
|
||||||
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
properties[PROP_MAX_VALUE] =
|
||||||
|
g_param_spec_double ("max-value", NULL, NULL,
|
||||||
|
-G_MAXDOUBLE, G_MAXDOUBLE, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,6 +206,45 @@ _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 = INFINITY;
|
||||||
|
double max_value = -INFINITY;
|
||||||
|
|
||||||
|
for (guint i = 0; i < values->len; i++)
|
||||||
|
{
|
||||||
|
double v = g_array_index (self->values, double, i);
|
||||||
|
|
||||||
|
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 = G_MAXINT64;
|
||||||
|
gint64 max_value = G_MININT64;
|
||||||
|
|
||||||
|
for (guint i = 0; i < values->len; i++)
|
||||||
|
{
|
||||||
|
gint64 v = g_array_index (self->values, gint64, i);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user