mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof: calculate min/max/avg/median durations for marks
This commit is contained in:
@ -119,6 +119,7 @@ enum {
|
||||
PROP_FILES,
|
||||
PROP_LOGS,
|
||||
PROP_MARKS,
|
||||
PROP_MARKS_CATALOG,
|
||||
PROP_METADATA,
|
||||
PROP_PROCESSES,
|
||||
PROP_SAMPLES,
|
||||
@ -389,6 +390,10 @@ sysprof_document_get_property (GObject *object,
|
||||
g_value_take_object (value, sysprof_document_list_marks (self));
|
||||
break;
|
||||
|
||||
case PROP_MARKS_CATALOG:
|
||||
g_value_take_object (value, sysprof_document_catalog_marks (self));
|
||||
break;
|
||||
|
||||
case PROP_METADATA:
|
||||
g_value_take_object (value, sysprof_document_list_metadata (self));
|
||||
break;
|
||||
@ -452,6 +457,11 @@ sysprof_document_class_init (SysprofDocumentClass *klass)
|
||||
G_TYPE_LIST_MODEL,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_MARKS_CATALOG] =
|
||||
g_param_spec_object ("marks-catalog", NULL, NULL,
|
||||
G_TYPE_LIST_MODEL,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_METADATA] =
|
||||
g_param_spec_object ("metadata", NULL, NULL,
|
||||
G_TYPE_LIST_MODEL,
|
||||
@ -2210,6 +2220,7 @@ sysprof_document_catalog_marks (SysprofDocument *self)
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
g_autoptr(GListStore) group = NULL;
|
||||
g_autoptr(GArray) median = g_array_new (FALSE, FALSE, sizeof (gint64));
|
||||
g_autofree const char **keys = NULL;
|
||||
const char *group_name = key;
|
||||
GHashTable *names = value;
|
||||
@ -2225,8 +2236,41 @@ sysprof_document_catalog_marks (SysprofDocument *self)
|
||||
const char *name = keys[i];
|
||||
EggBitset *marks = g_hash_table_lookup (names, name);
|
||||
g_autoptr(GListModel) model = _sysprof_document_bitset_index_new (G_LIST_MODEL (self), marks);
|
||||
g_autoptr(SysprofMarkCatalog) names_catalog = _sysprof_mark_catalog_new (group_name, name, model);
|
||||
g_autoptr(SysprofMarkCatalog) names_catalog = NULL;
|
||||
gint64 min = G_MAXINT64;
|
||||
gint64 max = G_MININT64;
|
||||
gint64 total = 0;
|
||||
gint64 count = 0;
|
||||
EggBitsetIter bitset;
|
||||
guint pos;
|
||||
|
||||
median->len = 0;
|
||||
|
||||
if (egg_bitset_iter_init_first (&bitset, marks, &pos))
|
||||
{
|
||||
do
|
||||
{
|
||||
const SysprofDocumentFramePointer *ptr = &g_array_index (self->frames, SysprofDocumentFramePointer, pos);
|
||||
const SysprofCaptureMark *tainted = (const SysprofCaptureMark *)(gpointer)&self->base[ptr->offset];
|
||||
gint64 duration = swap_int64 (self->needs_swap, tainted->duration);
|
||||
|
||||
g_array_append_val (median, duration);
|
||||
|
||||
min = MIN (min, duration);
|
||||
max = MAX (max, duration);
|
||||
total += duration;
|
||||
count++;
|
||||
}
|
||||
while (egg_bitset_iter_next (&bitset, &pos));
|
||||
}
|
||||
|
||||
names_catalog = _sysprof_mark_catalog_new (group_name,
|
||||
name,
|
||||
model,
|
||||
min,
|
||||
max,
|
||||
count ? total/count : 0,
|
||||
median->len ? g_array_index (median, gint64, median->len/2) : 0);
|
||||
g_list_store_append (group, names_catalog);
|
||||
}
|
||||
|
||||
|
||||
@ -28,6 +28,10 @@ G_BEGIN_DECLS
|
||||
|
||||
SysprofMarkCatalog *_sysprof_mark_catalog_new (const char *group,
|
||||
const char *name,
|
||||
GListModel *items);
|
||||
GListModel *items,
|
||||
gint64 min,
|
||||
gint64 max,
|
||||
gint64 avg,
|
||||
gint64 med);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@ -28,12 +28,20 @@ struct _SysprofMarkCatalog
|
||||
GListModel *items;
|
||||
char *group;
|
||||
char *name;
|
||||
gint64 min_duration;
|
||||
gint64 max_duration;
|
||||
gint64 avg_duration;
|
||||
gint64 med_duration;
|
||||
} SysprofMarkCatalogPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_GROUP,
|
||||
PROP_NAME,
|
||||
PROP_MIN_DURATION,
|
||||
PROP_MAX_DURATION,
|
||||
PROP_AVERAGE_DURATION,
|
||||
PROP_MEDIAN_DURATION,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
@ -99,6 +107,22 @@ sysprof_mark_catalog_get_property (GObject *object,
|
||||
g_value_set_string (value, sysprof_mark_catalog_get_name (self));
|
||||
break;
|
||||
|
||||
case PROP_MIN_DURATION:
|
||||
g_value_set_int64 (value, sysprof_mark_catalog_get_min_duration (self));
|
||||
break;
|
||||
|
||||
case PROP_MAX_DURATION:
|
||||
g_value_set_int64 (value, sysprof_mark_catalog_get_max_duration (self));
|
||||
break;
|
||||
|
||||
case PROP_AVERAGE_DURATION:
|
||||
g_value_set_int64 (value, sysprof_mark_catalog_get_average_duration (self));
|
||||
break;
|
||||
|
||||
case PROP_MEDIAN_DURATION:
|
||||
g_value_set_int64 (value, sysprof_mark_catalog_get_median_duration (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
@ -122,6 +146,26 @@ sysprof_mark_catalog_class_init (SysprofMarkCatalogClass *klass)
|
||||
NULL,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties[PROP_MIN_DURATION] =
|
||||
g_param_spec_int64 ("min-duration", NULL, NULL,
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties[PROP_MAX_DURATION] =
|
||||
g_param_spec_int64 ("max-duration", NULL, NULL,
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties[PROP_AVERAGE_DURATION] =
|
||||
g_param_spec_int64 ("average-duration", NULL, NULL,
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties[PROP_MEDIAN_DURATION] =
|
||||
g_param_spec_int64 ("median-duration", NULL, NULL,
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
@ -149,7 +193,11 @@ sysprof_mark_catalog_get_name (SysprofMarkCatalog *self)
|
||||
SysprofMarkCatalog *
|
||||
_sysprof_mark_catalog_new (const char *group,
|
||||
const char *name,
|
||||
GListModel *items)
|
||||
GListModel *items,
|
||||
gint64 min,
|
||||
gint64 max,
|
||||
gint64 avg,
|
||||
gint64 med)
|
||||
{
|
||||
SysprofMarkCatalog *self;
|
||||
|
||||
@ -160,6 +208,40 @@ _sysprof_mark_catalog_new (const char *group,
|
||||
self->group = g_strdup (group);
|
||||
self->name = g_strdup (name);
|
||||
self->items = g_object_ref (items);
|
||||
self->min_duration = min;
|
||||
self->max_duration = max;
|
||||
self->avg_duration = avg;
|
||||
self->med_duration = med;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
gint64
|
||||
sysprof_mark_catalog_get_min_duration (SysprofMarkCatalog *self)
|
||||
{
|
||||
if (self->min_duration == G_MAXINT64)
|
||||
return 0;
|
||||
|
||||
return self->min_duration;
|
||||
}
|
||||
|
||||
gint64
|
||||
sysprof_mark_catalog_get_max_duration (SysprofMarkCatalog *self)
|
||||
{
|
||||
if (self->max_duration == G_MININT64)
|
||||
return 0;
|
||||
|
||||
return self->max_duration;
|
||||
}
|
||||
|
||||
gint64
|
||||
sysprof_mark_catalog_get_average_duration (SysprofMarkCatalog *self)
|
||||
{
|
||||
return self->avg_duration;
|
||||
}
|
||||
|
||||
gint64
|
||||
sysprof_mark_catalog_get_median_duration (SysprofMarkCatalog *self)
|
||||
{
|
||||
return self->med_duration;
|
||||
}
|
||||
|
||||
@ -32,8 +32,16 @@ SYSPROF_AVAILABLE_IN_ALL
|
||||
G_DECLARE_FINAL_TYPE (SysprofMarkCatalog, sysprof_mark_catalog, SYSPROF, MARK_CATALOG, GObject)
|
||||
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
const char *sysprof_mark_catalog_get_group (SysprofMarkCatalog *self);
|
||||
const char *sysprof_mark_catalog_get_group (SysprofMarkCatalog *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
const char *sysprof_mark_catalog_get_name (SysprofMarkCatalog *self);
|
||||
const char *sysprof_mark_catalog_get_name (SysprofMarkCatalog *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
gint64 sysprof_mark_catalog_get_min_duration (SysprofMarkCatalog *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
gint64 sysprof_mark_catalog_get_max_duration (SysprofMarkCatalog *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
gint64 sysprof_mark_catalog_get_average_duration (SysprofMarkCatalog *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
gint64 sysprof_mark_catalog_get_median_duration (SysprofMarkCatalog *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user