[gtk/matthiasc/perf-tests] Prototype a sysprof helper
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/perf-tests] Prototype a sysprof helper
- Date: Tue, 21 Jan 2020 19:52:14 +0000 (UTC)
commit 11c6e62676f78e4836238295ce7238d5a717516c
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jan 21 13:59:12 2020 -0500
Prototype a sysprof helper
This is an attempt to see how we can use sysprof data
in our tests to extract useful performance numbers.
Use it as a wrapper around any GTK+ process:
./testperf ./gtk4-widget-factory
Currently, it just writes out first/min/max/avg values
of the "style" mark that we emit around toplevel css node
invalidations.
tests/meson.build | 5 +++
tests/testperf.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 116 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 37d6f0d87f..e7aa88ce87 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, platform_gio_dep, libm])
+
subdir('visuals')
diff --git a/tests/testperf.c b/tests/testperf.c
new file mode 100644
index 0000000000..6311284676
--- /dev/null
+++ b/tests/testperf.c
@@ -0,0 +1,111 @@
+#include <sysprof-capture.h>
+#include <gio/gio.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->group, "gtk") == 0 &&
+ 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;
+ int fd;
+ gchar *name;
+ char fd_str[20];
+ GSubprocessLauncher *launcher;
+ GSubprocess *subprocess;
+
+ if (argc < 2)
+ {
+ g_print ("Usage: testperf COMMANDLINE\n");
+ exit (1);
+ }
+
+ fd = g_file_open_tmp ("gtk.XXXXXX.syscap", &name, &error);
+ if (error)
+ g_error ("Create syscap file: %s", error->message);
+
+ launcher = g_subprocess_launcher_new (0);
+ g_subprocess_launcher_take_fd (launcher, fd, fd);
+ g_snprintf (fd_str, sizeof (fd_str), "%d", fd);
+ g_subprocess_launcher_setenv (launcher, "GTK_TRACE_FD", fd_str, TRUE);
+
+ subprocess = g_subprocess_launcher_spawnv (launcher, (const char *const *)argv + 1, &error);
+ if (error)
+ g_error ("Launch child: %s", error->message);
+
+ if (!g_subprocess_wait (subprocess, NULL, &error))
+ g_error ("Run child: %s", error->message);
+
+
+ reader = sysprof_capture_reader_new (name, &error);
+ if (error)
+ g_error ("Opening syscap file: %s", error->message);
+
+ 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);
+
+ if (data.count == 0)
+ {
+ g_print ("No marks for '%s' found.\n", data.group);
+ return 0;
+ }
+
+ 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]