[sysprof] libsysprof-ui: calculate min/max/avg for mark durations
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] libsysprof-ui: calculate min/max/avg for mark durations
- Date: Wed, 29 May 2019 22:31:47 +0000 (UTC)
commit abc9d7e1a8897377a65bfd9ec075c6a6cd0be3c7
Author: Christian Hergert <chergert redhat com>
Date: Thu May 16 17:45:40 2019 -0700
libsysprof-ui: calculate min/max/avg for mark durations
This can be used in details later to show information about the marks.
src/libsysprof-ui/sysprof-capture-view.c | 73 +++++++++++++++++++++++++++++++-
src/libsysprof-ui/sysprof-ui-private.h | 29 +++++++++----
2 files changed, 93 insertions(+), 9 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-capture-view.c b/src/libsysprof-ui/sysprof-capture-view.c
index 1744f7d..a704a15 100644
--- a/src/libsysprof-ui/sysprof-capture-view.c
+++ b/src/libsysprof-ui/sysprof-capture-view.c
@@ -89,6 +89,24 @@ load_async_free (gpointer data)
}
}
+SysprofMarkStat *
+_sysprof_mark_stat_new (const gchar *name)
+{
+ SysprofMarkStat *ret;
+
+ ret = g_slice_new0 (SysprofMarkStat);
+ ret->name = g_strdup (name);
+
+ return ret;
+}
+
+void
+_sysprof_mark_stat_free (SysprofMarkStat *self)
+{
+ g_clear_pointer (&self->name, g_free);
+ g_slice_free (SysprofMarkStat, self);
+}
+
/**
* sysprof_capture_view_new:
*
@@ -224,6 +242,7 @@ sysprof_capture_view_scan_worker (GTask *task,
SysprofCaptureView *self = source_object;
SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self);
SysprofCaptureReader *reader = task_data;
+ g_autoptr(GHashTable) mark_stats = NULL;
SysprofCaptureFeatures features = {0};
SysprofCaptureFrame frame;
SysprofCaptureStat st_buf = {{0}};
@@ -233,6 +252,9 @@ sysprof_capture_view_scan_worker (GTask *task,
g_assert (reader != NULL);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+ mark_stats = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ (GDestroyNotify)_sysprof_mark_stat_free);
+
features.begin_time = sysprof_capture_reader_get_start_time (reader);
features.end_time = sysprof_capture_reader_get_end_time (reader);
@@ -248,8 +270,34 @@ sysprof_capture_view_scan_worker (GTask *task,
if (frame.type == SYSPROF_CAPTURE_FRAME_MARK)
{
const SysprofCaptureMark *mark;
+
if ((mark = sysprof_capture_reader_read_mark (reader)))
- end_time = frame.time + mark->duration;
+ {
+ SysprofMarkStat *mstat;
+ gchar name[128];
+
+ end_time = frame.time + mark->duration;
+
+ g_snprintf (name, sizeof name, "%s:%s", mark->group, mark->name);
+
+ if (!(mstat = g_hash_table_lookup (mark_stats, name)))
+ {
+ mstat = _sysprof_mark_stat_new (name);
+ g_hash_table_insert (mark_stats, mstat->name, mstat);
+ }
+
+ if (mark->duration > 0)
+ {
+ if (mstat->min == 0 || mark->duration < mstat->min)
+ mstat->min = mark->duration;
+ }
+
+ if (mark->duration > mstat->max)
+ mstat->max = mark->duration;
+
+ mstat->avg += mark->duration;
+ mstat->count++;
+ }
features.has_marks = TRUE;
}
@@ -275,6 +323,29 @@ sysprof_capture_view_scan_worker (GTask *task,
features.end_time = end_time;
}
+ {
+ GHashTableIter iter;
+ gpointer k,v;
+
+ g_hash_table_iter_init (&iter, mark_stats);
+ while (g_hash_table_iter_next (&iter, &k, &v))
+ {
+ SysprofMarkStat *mstat = v;
+
+ if (mstat->count > 0 && mstat->avg > 0)
+ mstat->avg /= mstat->count;
+
+#if 0
+ g_print ("%s: count=%ld avg=%ld min=%ld max=%ld\n",
+ (gchar*)k,
+ ((SysprofMarkStat *)v)->count,
+ ((SysprofMarkStat *)v)->avg,
+ ((SysprofMarkStat *)v)->min,
+ ((SysprofMarkStat *)v)->max);
+#endif
+ }
+ }
+
sysprof_capture_reader_set_stat (reader, &st_buf);
if (!g_task_return_error_if_cancelled (task))
diff --git a/src/libsysprof-ui/sysprof-ui-private.h b/src/libsysprof-ui/sysprof-ui-private.h
index dcb5633..a57a35c 100644
--- a/src/libsysprof-ui/sysprof-ui-private.h
+++ b/src/libsysprof-ui/sysprof-ui-private.h
@@ -25,13 +25,26 @@
G_BEGIN_DECLS
-void _sysprof_marks_view_set_hadjustment (SysprofMarksView *self,
- GtkAdjustment *hadjustment);
-void _sysprof_visualizer_view_set_hadjustment (SysprofVisualizerView *self,
- GtkAdjustment *hadjustment);
-void _sysprof_rounded_rectangle (cairo_t *cr,
- const GdkRectangle *rect,
- gint x_radius,
- gint y_radius);
+typedef struct
+{
+ gchar *name;
+ guint64 count;
+ gint64 max;
+ gint64 min;
+ gint64 avg;
+} SysprofMarkStat;
+
+SysprofMarkStat *_sysprof_mark_stat_new (const gchar *name);
+void _sysprof_mark_stat_free (SysprofMarkStat *self);
+void _sysprof_marks_view_set_hadjustment (SysprofMarksView *self,
+ GtkAdjustment *hadjustment);
+void _sysprof_visualizer_view_set_hadjustment (SysprofVisualizerView *self,
+ GtkAdjustment *hadjustment);
+void _sysprof_rounded_rectangle (cairo_t *cr,
+ const GdkRectangle *rect,
+ gint x_radius,
+ gint y_radius);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofMarkStat, _sysprof_mark_stat_free)
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]