[gtk/matthiasc/perf-tests: 3/3] Prototype a list sysprof helper



commit da6015d5a4ef99ed7b5d86e50edc2f348e7f7263
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 21 13:59:12 2020 -0500

    Prototype a list sysprof helper
    
    This is an attempt to see how we can use sysprof data
    in our tests to extract useful performance numbers.

 tests/meson.build |  5 ++++
 tests/testperf.c  | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 37d6f0d87f..2330883090 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -150,4 +150,9 @@ foreach t: gtk_tests
              dependencies: [libgtk_dep, libm])
 endforeach
 
+
+
+executable('testperf', 'testperf.c',
+            dependencies: [profiler_dep, libm])
+
 subdir('visuals')
diff --git a/tests/testperf.c b/tests/testperf.c
new file mode 100644
index 0000000000..1c18b7da34
--- /dev/null
+++ b/tests/testperf.c
@@ -0,0 +1,81 @@
+#include <sysprof-capture.h>
+
+typedef struct {
+  const char *group;
+  int count;
+  gint64 total;
+  gint64 first;
+  gint64 min;
+  gint64 max;
+} Data;
+
+static gboolean
+callback (const SysprofCaptureFrame *frame,
+          gpointer              user_data)
+{
+  Data *data = user_data;
+
+  if (frame->type == SYSPROF_CAPTURE_FRAME_MARK)
+    {
+      SysprofCaptureMark *mark = (SysprofCaptureMark *)frame;
+      gint64 value = mark->duration;
+
+      if (strcmp (mark->name, data->group) == 0)
+        {
+          if (data->count == 0)
+            data->first = value;
+          data->count++;
+          data->total += value;
+          if (data->max < value)
+            data->max = value;
+          if (data->min > value)
+            data->min = value;
+        }
+    }
+
+  return TRUE;
+}
+
+#define MILLISECONDS(v) ((v) / (1000.0 * G_TIME_SPAN_MILLISECOND))
+
+int
+main (int argc, char *argv[])
+{
+  SysprofCaptureReader *reader;
+  SysprofCaptureCursor *cursor;
+  SysprofCaptureCondition *condition;
+  GError *error = NULL;
+  Data data;
+  SysprofCaptureFrameType type;
+
+  if (argc != 2)
+    {
+      g_print ("Usage: testperf SYSCAP\n");
+      exit (1);
+    }
+
+  reader = sysprof_capture_reader_new (argv[1], &error);
+  g_assert_no_error (error);
+
+  data.group = "style";
+  data.count = 0;
+  data.total = 0;
+  data.min = G_MAXINT64;
+  data.max = 0;
+
+  cursor = sysprof_capture_cursor_new (reader);
+
+  type = SYSPROF_CAPTURE_FRAME_MARK;
+  condition = sysprof_capture_condition_new_where_type_in (1, &type);
+  sysprof_capture_cursor_add_condition (cursor, condition);
+
+  sysprof_capture_cursor_foreach (cursor, callback, &data);
+
+  g_print ("%d marks for '%s', first %g, min %g, max %g, avg %g\n",
+           data.count,
+           data.group,
+           MILLISECONDS (data.first),
+           MILLISECONDS (data.min),
+           MILLISECONDS (data.max),
+           MILLISECONDS (data.total / data.count));
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]