[gtk: 7/14] profiler: Add _end_mark() version of _add_mark()



commit 2890cd849fd7d8e0cd73ed09a6bf0494dbafc8d5
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Feb 12 11:25:34 2020 +0100

    profiler: Add _end_mark() version of _add_mark()
    
    These don't take a duration, instead they call g_get_monotonic_time() to
    and subtract the start time for it.
    
    Almost all our calls are like this, and this makes the callsites clearer
    and avoids inlining the clock call into the call site.

 gdk/gdkframeclock.c              | 35 +++++-----------------
 gdk/gdkframeclockidle.c          |  8 ++---
 gdk/gdkprofiler.c                | 64 +++++++++++++++++++++++++++++++++++++---
 gdk/gdkprofilerprivate.h         |  7 +++++
 gdk/wayland/gdkdisplay-wayland.c |  4 +--
 gsk/gl/gskglrenderer.c           |  2 +-
 gtk/gtkapplication.c             |  4 +--
 gtk/gtkbuilderparser.c           |  2 +-
 gtk/gtkcssprovider.c             |  4 +--
 gtk/gtkemojichooser.c            |  5 +---
 gtk/gtkicontheme.c               |  4 +--
 gtk/gtkwidget.c                  | 14 ++++-----
 gtk/gtkwindow.c                  |  5 +---
 13 files changed, 93 insertions(+), 65 deletions(-)
---
diff --git a/gdk/gdkframeclock.c b/gdk/gdkframeclock.c
index 7d3277f751..940d39ca6d 100644
--- a/gdk/gdkframeclock.c
+++ b/gdk/gdkframeclock.c
@@ -652,10 +652,7 @@ _gdk_frame_clock_emit_flush_events (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[FLUSH_EVENTS], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "flush-events");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "flush-events");
 }
 
 void
@@ -666,10 +663,7 @@ _gdk_frame_clock_emit_before_paint (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[BEFORE_PAINT], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "before-paint");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "before-paint");
 }
 
 void
@@ -680,10 +674,7 @@ _gdk_frame_clock_emit_update (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[UPDATE], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "update");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "update");
 }
 
 void
@@ -694,10 +685,7 @@ _gdk_frame_clock_emit_layout (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[LAYOUT], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "layout");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "layout");
 }
 
 void
@@ -708,10 +696,7 @@ _gdk_frame_clock_emit_paint (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[PAINT], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "paint");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "paint");
 }
 
 void
@@ -722,10 +707,7 @@ _gdk_frame_clock_emit_after_paint (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[AFTER_PAINT], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "after-paint");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "after-paint");
 }
 
 void
@@ -736,10 +718,7 @@ _gdk_frame_clock_emit_resume_events (GdkFrameClock *frame_clock)
   g_signal_emit (frame_clock, signals[RESUME_EVENTS], 0);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "frameclock", "resume-events");
-    }
+    gdk_profiler_end_mark (before, "frameclock", "resume-events");
 }
 
 static gint64
diff --git a/gdk/gdkframeclockidle.c b/gdk/gdkframeclockidle.c
index f7d03fa79a..2a0dbd8f07 100644
--- a/gdk/gdkframeclockidle.c
+++ b/gdk/gdkframeclockidle.c
@@ -502,7 +502,7 @@ gdk_frame_clock_paint_idle (void *data)
     priv->sleep_serial = get_sleep_serial ();
 
   if (GDK_PROFILER_IS_RUNNING)
-    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "frameclock", "paint_idle");
+    gdk_profiler_end_mark (before, "frameclock", "paint_idle");
 
   return FALSE;
 }
@@ -598,10 +598,8 @@ gdk_frame_clock_idle_thaw (GdkFrameClock *clock)
         {
           if (priv->freeze_time != 0)
             {
-              gint64 thaw_time = g_get_monotonic_time ();
-              gdk_profiler_add_mark (priv->freeze_time,
-                                     (thaw_time - priv->freeze_time),
-                                     "frameclock freeze", "");
+              gdk_profiler_end_mark (priv->freeze_time,
+                                     "frameclock freeze", NULL);
               priv->freeze_time = 0;
             }
         }
diff --git a/gdk/gdkprofiler.c b/gdk/gdkprofiler.c
index 81288be173..4d122b7b91 100644
--- a/gdk/gdkprofiler.c
+++ b/gdk/gdkprofiler.c
@@ -100,6 +100,23 @@ gdk_profiler_add_mark (gint64      start,
                                    "gtk", name, message);
 }
 
+static void
+add_markvf (gint64      start,
+            guint64     duration,
+            const char *name,
+            const char *format,
+            va_list      args)
+{
+  char *message;
+  message = g_strdup_vprintf (format, args);
+  sysprof_capture_writer_add_mark (writer,
+                                   start * 1000L,
+                                   -1, getpid (),
+                                   duration * 1000L,
+                                   "gtk", name, message);
+  g_free (message);
+}
+
 void
 gdk_profiler_add_markf (gint64      start,
                         guint64     duration,
@@ -108,23 +125,47 @@ gdk_profiler_add_markf (gint64      start,
                         ...)
 {
   va_list args;
-  char *message;
 
   if (!running)
     return;
 
   va_start (args, format);
-  message = g_strdup_vprintf (format, args);
+  add_markvf (start, duration, name, format, args);
   va_end (args);
+}
+
+void
+gdk_profiler_end_mark (gint64      start,
+                       const char *name,
+                       const char *message)
+{
+  if (!running)
+    return;
 
   sysprof_capture_writer_add_mark (writer,
                                    start * 1000L,
                                    -1, getpid (),
-                                   duration * 1000L,
+                                   (g_get_monotonic_time () - start) * 1000L,
                                    "gtk", name, message);
-  g_free (message);
 }
 
+void
+gdk_profiler_end_markf (gint64      start,
+                        const char *name,
+                        const char *format,
+                        ...)
+{
+  va_list args;
+
+  if (!running)
+    return;
+
+  va_start (args, format);
+  add_markvf (start, g_get_monotonic_time () - start, name, format, args);
+  va_end (args);
+}
+
+
 static guint
 define_counter (const char *name,
                 const char *description,
@@ -235,6 +276,21 @@ gdk_profiler_add_markf (gint64      start,
 {
 }
 
+void
+gdk_profiler_end_mark (gint64      start,
+                       const char *name,
+                       const char *message)
+{
+}
+
+void
+gdk_profiler_end_markf (gint64      start,
+                        const char *name,
+                        const char *format,
+                        ...)
+{
+}
+
 guint
 gdk_profiler_define_counter (const char *name,
                              const char *description)
diff --git a/gdk/gdkprofilerprivate.h b/gdk/gdkprofilerprivate.h
index 1c68739e0e..f06296d359 100644
--- a/gdk/gdkprofilerprivate.h
+++ b/gdk/gdkprofilerprivate.h
@@ -50,6 +50,13 @@ void     gdk_profiler_add_markf   (gint64           start,
                                    const char      *name,
                                    const char      *format,
                                    ...)  G_GNUC_PRINTF (4, 5);
+void     gdk_profiler_end_mark   (gint64           start,
+                                  const char      *name,
+                                  const char      *message);
+void     gdk_profiler_end_markf   (gint64           start,
+                                   const char      *name,
+                                   const char      *format,
+                                   ...)  G_GNUC_PRINTF (3, 4);
 guint    gdk_profiler_define_counter (const char *name,
                                       const char *description);
 void     gdk_profiler_set_counter    (guint  id,
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 2243440421..8ffc2d048e 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -1154,9 +1154,7 @@ _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland)
   g_value_unset (&v);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "wayland", "load cursor theme");
-    }
+    gdk_profiler_end_mark (before, "wayland", "load cursor theme");
 
 }
 
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index fac7f266c9..066fbf0ae2 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -2858,7 +2858,7 @@ gsk_gl_renderer_realize (GskRenderer  *renderer,
   gsk_gl_shadow_cache_init (&self->shadow_cache);
 
   if (GDK_PROFILER_IS_RUNNING)
-    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gl renderer realize", NULL);
+    gdk_profiler_end_mark (before, "gl renderer realize", NULL);
 
   return TRUE;
 }
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index be3758376c..768915c807 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -307,7 +307,7 @@ gtk_application_startup (GApplication *g_application)
   before2 = g_get_monotonic_time ();
   gtk_init ();
   if (GDK_PROFILER_IS_RUNNING)
-    gdk_profiler_add_mark (before2, (g_get_monotonic_time () - before2), "gtk init", NULL);
+    gdk_profiler_end_mark (before2, "gtk init", NULL);
 
   priv->impl = gtk_application_impl_new (application, gdk_display_get_default ());
   gtk_application_impl_startup (priv->impl, priv->register_session);
@@ -315,7 +315,7 @@ gtk_application_startup (GApplication *g_application)
   gtk_application_load_resources (application);
 
   if (GDK_PROFILER_IS_RUNNING)
-    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gtk application startup", NULL);
+    gdk_profiler_end_mark (before, "gtk application startup", NULL);
 }
 
 static void
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index 6247f53f9d..1aea5c2799 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -1625,5 +1625,5 @@ _gtk_builder_parser_parse_buffer (GtkBuilder   *builder,
   /* restore the original domain */
   gtk_builder_set_translation_domain (builder, domain);
 
-  gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "builder load", filename);
+  gdk_profiler_end_mark (before, "builder load", filename);
 }
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 3747b35076..829e2ec42c 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1010,7 +1010,7 @@ gtk_css_provider_postprocess (GtkCssProvider *css_provider)
 #endif
 
   if (GDK_PROFILER_IS_RUNNING)
-    gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "create selector tree", NULL);
+    gdk_profiler_end_mark (before, "create selector tree", NULL);
 }
 
 static void
@@ -1071,7 +1071,7 @@ gtk_css_provider_load_internal (GtkCssProvider *self,
   if (GDK_PROFILER_IS_RUNNING)
     {
       char *uri = g_file_get_uri (file);
-      gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "theme load", uri);
+      gdk_profiler_end_mark (before, "theme load", uri);
       g_free (uri);
     }
 }
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index d317cfc0c5..00a9edc262 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -477,10 +477,7 @@ populate_emoji_chooser (gpointer data)
   chooser->populate_idle = 0;
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      now = g_get_monotonic_time ();
-      gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate (finish)");
-    }
+    gdk_profiler_end_mark (start, "emojichooser", "populate (finish)");
 
   return G_SOURCE_REMOVE;
 }
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 38bb7c0f1a..3151d3b316 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -1847,7 +1847,7 @@ ensure_valid_themes (GtkIconTheme *self,
       load_themes (self);
 
       if (GDK_PROFILER_IS_RUNNING)
-        gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "icon theme load", 
self->current_theme);
+        gdk_profiler_end_mark (before, "icon theme load", self->current_theme);
 
       if (was_valid)
         queue_theme_changed (self);
@@ -3606,7 +3606,7 @@ icon_ensure_texture__locked (GtkIconPaintable *icon,
   g_assert (icon->texture != NULL);
 
   if (GDK_PROFILER_IS_RUNNING)
-    gdk_profiler_add_markf (before, g_get_monotonic_time () - before, in_thread ?  "icon load (thread)" : 
"icon load" ,
+    gdk_profiler_end_markf (before, in_thread ?  "icon load (thread)" : "icon load" ,
                             "%s size %d@%d", icon->filename, icon->desired_size, icon->desired_scale);
 }
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 9bcf7c0000..ff51d12dfe 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -12177,8 +12177,8 @@ gtk_widget_render (GtkWidget            *widget,
   GskRenderer *renderer;
   GskRenderNode *root;
   int x, y;
-  gint64 before = g_get_monotonic_time ();
-  gint64 after = 0;
+  gint64 before_snapshot = g_get_monotonic_time ();
+  gint64 before_render = 0;
 
   if (!GTK_IS_NATIVE (widget))
     return;
@@ -12195,8 +12195,8 @@ gtk_widget_render (GtkWidget            *widget,
 
   if (GDK_PROFILER_IS_RUNNING)
     {
-      after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "widget snapshot", "");
+      before_render = g_get_monotonic_time ();
+      gdk_profiler_add_mark (before_snapshot, (before_render - before_snapshot), "widget snapshot", "");
     }
 
   if (root != NULL)
@@ -12212,11 +12212,7 @@ gtk_widget_render (GtkWidget            *widget,
       gsk_render_node_unref (root);
 
       if (GDK_PROFILER_IS_RUNNING)
-        {
-          before = after;
-          after = g_get_monotonic_time ();
-          gdk_profiler_add_mark (before, (after - before), "widget render", "");
-        }
+        gdk_profiler_end_mark (before_render, "widget render", "");
     }
 }
 
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index eb49687ebd..701cfb6f33 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6317,10 +6317,7 @@ gtk_window_check_resize (GtkWindow *self)
     gtk_window_move_resize (self);
 
   if (GDK_PROFILER_IS_RUNNING)
-    {
-      gint64 after = g_get_monotonic_time ();
-      gdk_profiler_add_mark (before, (after - before), "size allocation", "");
-    }
+    gdk_profiler_end_mark (before, "size allocation", "");
 }
 
 static void


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