Make the performance testcase more general
authorMatthias Clasen <mclasen@redhat.com>
Wed, 22 Jan 2020 05:55:11 +0000 (00:55 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 22 Jan 2020 05:59:04 +0000 (00:59 -0500)
Reuse the performance test for layout and snapshot timings.

testsuite/css/performance/meson.build
testsuite/css/performance/test-css-performance.c [deleted file]
testsuite/gtk/meson.build
testsuite/meson.build
testsuite/performance/meson.build [new file with mode: 0644]
testsuite/performance/test-performance.c [new file with mode: 0644]

index 781b1b3658e125bde14f3ba5791ee7775c0fe932..16a8dce1ef5512abb41a180419865b60a0137c29 100644 (file)
@@ -1,10 +1,15 @@
 if get_option ('profiler')
-  test_css_performance = executable('test-css-performance', 'test-css-performance.c',
-                                    dependencies: [profiler_dep, platform_gio_dep, libm])
 
-  test('performance', test_css_performance,
-       args: [ join_paths(meson.current_build_dir(), '../../../demos/widget-factory/gtk4-widget-factory') ],
+  test('performance-adwaita', test_performance,
+       args: [ '--mark', 'style', join_paths(meson.current_build_dir(), '../../../demos/widget-factory/gtk4-widget-factory') ],
        env: [ 'GTK_THEME=Adwaita',
               'GSETTINGS_SCHEMA_DIR=@0@'.format(gtk_schema_build_dir) ],
        suite: [ 'css' ])
+
+  test('performance-empty', test_performance,
+       args: [ '--mark', 'style', join_paths(meson.current_build_dir(), '../../../demos/widget-factory/gtk4-widget-factory') ],
+       env: [ 'GTK_THEME=Empty',
+              'GSETTINGS_SCHEMA_DIR=@0@'.format(gtk_schema_build_dir) ],
+       suite: [ 'css' ])
+
 endif
diff --git a/testsuite/css/performance/test-css-performance.c b/testsuite/css/performance/test-css-performance.c
deleted file mode 100644 (file)
index c4fbc54..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <stdio.h>
-#include <sysprof-capture.h>
-#include <gio/gio.h>
-
-typedef struct {
-  const char *group;
-  gint64 value;
-} 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;
-      if (strcmp (mark->group, "gtk") == 0 &&
-          strcmp (mark->name, data->group) == 0)
-        {
-          data->value = mark->duration;
-          return FALSE;
-        }
-    }
-
-  return TRUE;
-}
-
-#define MILLISECONDS(v) ((v) / (1000.0 * G_TIME_SPAN_MILLISECOND))
-
-static int opt_rep = 10;
-static char *opt_mark;
-
-static GOptionEntry options[] = {
-  { "mark", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_mark, "Name of the mark", "NAME" },
-  { "runs", 'r', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &opt_rep, "Number of runs", "COUNT" },
-  { NULL, }
-};
-
-int
-main (int argc, char *argv[])
-{
-  GOptionContext *context;
-  GError *error = NULL;
-  Data data;
-  SysprofCaptureFrameType type;
-  char fd_str[20];
-  gint64 *values;
-  gint64 min, max, total;
-  int i;
-
-  context = g_option_context_new ("COMMANDLINE");
-  g_option_context_add_main_entries (context, options, NULL);
-  if (!g_option_context_parse (context, &argc, &argv, &error))
-    g_error ("Parsing options: %s", error->message);
-
-  if (argc < 2)
-    {
-      g_print ("Usage: testperf [OPTIONS] COMMANDLINE\n");
-      exit (1);
-    }
-
-  if (opt_rep < 1)
-    g_error ("COUNT must be a positive number");
-
-  values = g_new (gint64, opt_rep);
-
-  for (i = 0; i < opt_rep; i++)
-    {
-      GSubprocessLauncher *launcher;
-      GSubprocess *subprocess;
-      int fd;
-      gchar *name;
-      SysprofCaptureReader *reader;
-      SysprofCaptureCursor *cursor;
-      SysprofCaptureCondition *condition;
-
-      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);
-      g_subprocess_launcher_setenv (launcher, "GTK_DEBUG_AUTO_QUIT", "1", 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);
-
-      if (!g_subprocess_get_successful (subprocess))
-        g_error ("Child process failed");
-        
-      g_object_unref (subprocess);
-      g_object_unref (launcher);
-
-      reader = sysprof_capture_reader_new (name, &error);
-      if (error)
-        g_error ("Opening syscap file: %s", error->message);
-
-      data.group = opt_mark ? opt_mark : "style";
-      data.value = 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);
-
-      values[i] = data.value;
-
-      sysprof_capture_cursor_unref (cursor);
-      sysprof_capture_reader_unref (reader);
-
-      remove (name);
-
-      g_free (name);
-    }
-
-  min = G_MAXINT64;
-  max = 0;
-  total = 0;
-
-  for (i = 0; i < opt_rep; i++)
-    {
-      if (min > values[i])
-        min = values[i];
-      if (max < values[i])
-        max = values[i];
-      total += values[i];
-    }
-
-  g_print ("%d runs, min %g, max %g, avg %g\n",
-           opt_rep,
-           MILLISECONDS (min),
-           MILLISECONDS (max),
-           MILLISECONDS (total / opt_rep));
-}
index 2b5db6289262c681cebcbc8a38d0e5d34f39f2e6..416b087c12caa92ea58d81988b0806d42545ea19 100644 (file)
@@ -186,3 +186,22 @@ if get_option('install-tests')
 
 endif
 
+if get_option ('profiler')
+
+  test('performance-layout', test_performance,
+       args: [ '--mark', 'layout', join_paths(meson.current_build_dir(), '../../demos/widget-factory/gtk4-widget-factory') ],
+       env: [ 'GTK_THEME=Empty',
+              'GSETTINGS_SCHEMA_DIR=@0@'.format(gtk_schema_build_dir) ],
+       suite: [ 'css' ])
+
+endif
+
+if get_option ('profiler')
+
+  test('performance-snapshot', test_performance,
+       args: [ '--mark', 'snapshot', join_paths(meson.current_build_dir(), '../../demos/widget-factory/gtk4-widget-factory') ],
+       env: [ 'GTK_THEME=Empty',
+              'GSETTINGS_SCHEMA_DIR=@0@'.format(gtk_schema_build_dir) ],
+       suite: [ 'css' ])
+
+endif
index bb7c8160f4deb337444e6cfed1e1b963ddf902e6..e5c0abe3981655feaad39420f487f875a1739066 100644 (file)
@@ -6,6 +6,7 @@ installed_test_datadir = join_paths(gtk_datadir, 'installed-tests', 'gtk-4.0')
 # otherwise we're going to have failures down the line
 diff = find_program('diff', required: true)
 
+subdir('performance')
 subdir('gdk')
 subdir('gsk')
 subdir('gtk')
diff --git a/testsuite/performance/meson.build b/testsuite/performance/meson.build
new file mode 100644 (file)
index 0000000..c449cbd
--- /dev/null
@@ -0,0 +1,4 @@
+if get_option ('profiler')
+  test_performance = executable('test-performance', 'test-performance.c',
+                                dependencies: [profiler_dep, platform_gio_dep, libm])
+endif
diff --git a/testsuite/performance/test-performance.c b/testsuite/performance/test-performance.c
new file mode 100644 (file)
index 0000000..c4fbc54
--- /dev/null
@@ -0,0 +1,145 @@
+#include <stdio.h>
+#include <sysprof-capture.h>
+#include <gio/gio.h>
+
+typedef struct {
+  const char *group;
+  gint64 value;
+} 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;
+      if (strcmp (mark->group, "gtk") == 0 &&
+          strcmp (mark->name, data->group) == 0)
+        {
+          data->value = mark->duration;
+          return FALSE;
+        }
+    }
+
+  return TRUE;
+}
+
+#define MILLISECONDS(v) ((v) / (1000.0 * G_TIME_SPAN_MILLISECOND))
+
+static int opt_rep = 10;
+static char *opt_mark;
+
+static GOptionEntry options[] = {
+  { "mark", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_mark, "Name of the mark", "NAME" },
+  { "runs", 'r', G_OPTION_FLAG_NONE, G_OPTION_ARG_INT, &opt_rep, "Number of runs", "COUNT" },
+  { NULL, }
+};
+
+int
+main (int argc, char *argv[])
+{
+  GOptionContext *context;
+  GError *error = NULL;
+  Data data;
+  SysprofCaptureFrameType type;
+  char fd_str[20];
+  gint64 *values;
+  gint64 min, max, total;
+  int i;
+
+  context = g_option_context_new ("COMMANDLINE");
+  g_option_context_add_main_entries (context, options, NULL);
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    g_error ("Parsing options: %s", error->message);
+
+  if (argc < 2)
+    {
+      g_print ("Usage: testperf [OPTIONS] COMMANDLINE\n");
+      exit (1);
+    }
+
+  if (opt_rep < 1)
+    g_error ("COUNT must be a positive number");
+
+  values = g_new (gint64, opt_rep);
+
+  for (i = 0; i < opt_rep; i++)
+    {
+      GSubprocessLauncher *launcher;
+      GSubprocess *subprocess;
+      int fd;
+      gchar *name;
+      SysprofCaptureReader *reader;
+      SysprofCaptureCursor *cursor;
+      SysprofCaptureCondition *condition;
+
+      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);
+      g_subprocess_launcher_setenv (launcher, "GTK_DEBUG_AUTO_QUIT", "1", 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);
+
+      if (!g_subprocess_get_successful (subprocess))
+        g_error ("Child process failed");
+        
+      g_object_unref (subprocess);
+      g_object_unref (launcher);
+
+      reader = sysprof_capture_reader_new (name, &error);
+      if (error)
+        g_error ("Opening syscap file: %s", error->message);
+
+      data.group = opt_mark ? opt_mark : "style";
+      data.value = 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);
+
+      values[i] = data.value;
+
+      sysprof_capture_cursor_unref (cursor);
+      sysprof_capture_reader_unref (reader);
+
+      remove (name);
+
+      g_free (name);
+    }
+
+  min = G_MAXINT64;
+  max = 0;
+  total = 0;
+
+  for (i = 0; i < opt_rep; i++)
+    {
+      if (min > values[i])
+        min = values[i];
+      if (max < values[i])
+        max = values[i];
+      total += values[i];
+    }
+
+  g_print ("%d runs, min %g, max %g, avg %g\n",
+           opt_rep,
+           MILLISECONDS (min),
+           MILLISECONDS (max),
+           MILLISECONDS (total / opt_rep));
+}