[gtk/startup-profiling] Add more sysprof marks




commit fce23c981b81b55328253cc7a6d181cd7c10971c
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 22 11:36:29 2021 -0400

    Add more sysprof marks
    
    Add a few more marks during gtk_init to figure out where
    our startup time goes, and avoid the sysprof initialization
    from distorting the first mark.

 gdk/gdkdisplay.c                   | 12 ++++++++++++
 gdk/wayland/gdkglcontext-wayland.c | 25 ++++++++++++++++++++++---
 gsk/ngl/gskngldriver.c             |  9 +++++++++
 gsk/ngl/gsknglrenderer.c           |  2 +-
 gtk/gtkmain.c                      | 14 ++++++++++++++
 5 files changed, 58 insertions(+), 4 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 8da1a4cc9f..5067065b03 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -1200,6 +1200,10 @@ gdk_display_init_gl (GdkDisplay *self)
 {
   GdkDisplayPrivate *priv = gdk_display_get_instance_private (self);
   GdkGLContext *context;
+  gint64 before G_GNUC_UNUSED;
+  gint64 before2 G_GNUC_UNUSED;
+
+  before = GDK_PROFILER_CURRENT_TIME;
 
   if (GDK_DISPLAY_DEBUG_CHECK (self, GL_DISABLE))
     {
@@ -1213,17 +1217,23 @@ gdk_display_init_gl (GdkDisplay *self)
   if (context == NULL)
     return;
 
+  before2 = GDK_PROFILER_CURRENT_TIME;
+
   if (!gdk_gl_context_realize (context, &priv->gl_error))
     {
       g_object_unref (context);
       return;
     }
 
+  gdk_profiler_end_mark (before2, "realize OpenGL context", NULL);
+
   /* Only assign after realize, so GdkGLContext::realize() can use
    * gdk_display_get_gl_context() == NULL to differentiate between
    * the display's context and any other context.
    */
   priv->gl_context = context;
+
+  gdk_profiler_end_mark (before, "initialize OpenGL", NULL);
 }
 
 /**
@@ -1268,6 +1278,8 @@ gdk_display_prepare_gl (GdkDisplay  *self,
         {
           if (error)
             *error = g_error_copy (priv->gl_error);
+
+
           return FALSE;
         }
 
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 0bc24824f6..7e6dd07225 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -62,6 +62,7 @@ gdk_wayland_gl_context_realize (GdkGLContext *context,
   int major, minor, flags;
   gboolean debug_bit, forward_bit, legacy_bit, use_es;
   int i = 0;
+  G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
 
   gdk_gl_context_get_required_version (context, &major, &minor);
   debug_bit = gdk_gl_context_get_debug_enabled (context);
@@ -197,6 +198,8 @@ gdk_wayland_gl_context_realize (GdkGLContext *context,
   gdk_gl_context_set_is_legacy (context, legacy_bit);
   gdk_gl_context_set_use_es (context, use_es);
 
+  gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
+
   return TRUE;
 }
 
@@ -467,8 +470,13 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
   GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
   EGLint major, minor;
   EGLDisplay dpy;
+  GdkGLContext *ctx;
+  G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
+  G_GNUC_UNUSED gint64 start_time2;
 
+  start_time2 = GDK_PROFILER_CURRENT_TIME;
   dpy = get_egl_display (display_wayland);
+  gdk_profiler_end_mark (start_time, "get_egl_display", NULL);
   if (dpy == NULL)
     {
       g_set_error_literal (error, GDK_GL_ERROR,
@@ -477,6 +485,7 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
       return NULL;
     }
 
+  start_time2 = GDK_PROFILER_CURRENT_TIME;
   if (!eglInitialize (dpy, &major, &minor))
     {
       g_set_error_literal (error, GDK_GL_ERROR,
@@ -484,6 +493,8 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
                            _("Could not initialize EGL display"));
       return NULL;
     }
+  gdk_profiler_end_mark (start_time2, "eglInitialize", NULL);
+
   if (major < GDK_EGL_MIN_VERSION_MAJOR ||
       (major == GDK_EGL_MIN_VERSION_MAJOR && minor < GDK_EGL_MIN_VERSION_MINOR))
     {
@@ -495,6 +506,7 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
       return NULL;
     }
 
+  start_time2 = GDK_PROFILER_CURRENT_TIME;
   if (!eglBindAPI (EGL_OPENGL_API))
     {
       eglTerminate (dpy);
@@ -503,6 +515,7 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
                            _("No GL implementation is available"));
       return NULL;
     }
+  gdk_profiler_end_mark (start_time2, "eglBindAPI", NULL);
 
   if (!epoxy_has_egl_extension (dpy, "EGL_KHR_create_context"))
     {
@@ -522,7 +535,9 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
       return NULL;
     }
 
+  start_time2 = GDK_PROFILER_CURRENT_TIME;
   display_wayland->egl_config = get_eglconfig (dpy);
+  gdk_profiler_end_mark (start_time2, "get_eglconfig", NULL);
   if (!display_wayland->egl_config)
     {
       eglTerminate (dpy);
@@ -556,9 +571,13 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
                        eglQueryString (dpy, EGL_CLIENT_APIS),
                        eglQueryString (dpy, EGL_EXTENSIONS)));
 
-  return g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
-                       "display", display,
-                       NULL);
+  ctx = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
+                      "display", display,
+                      NULL);
+
+  gdk_profiler_end_mark (start_time, "init Wayland GL", NULL);
+
+  return ctx;
 }
 
 static void
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index eba888f514..bc4a9ad413 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -26,6 +26,7 @@
 #include <gdk/gdkglcontextprivate.h>
 #include <gdk/gdkdisplayprivate.h>
 #include <gdk/gdktextureprivate.h>
+#include <gdk/gdkprofilerprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <gsk/gskglshaderprivate.h>
 #include <gsk/gskrendererprivate.h>
@@ -329,6 +330,7 @@ gsk_ngl_driver_load_programs (GskNglDriver  *self,
 {
   GskNglCompiler *compiler;
   gboolean ret = FALSE;
+  G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
 
   g_assert (GSK_IS_NGL_DRIVER (self));
   g_assert (GSK_IS_NGL_COMMAND_QUEUE (self->command_queue));
@@ -396,6 +398,8 @@ gsk_ngl_driver_load_programs (GskNglDriver  *self,
 failure:
   g_clear_object (&compiler);
 
+  gdk_profiler_end_mark (start_time, "load programs", NULL);
+
   return ret;
 }
 
@@ -422,9 +426,12 @@ gsk_ngl_driver_new (GskNglCommandQueue  *command_queue,
 {
   GskNglDriver *self;
   GdkGLContext *context;
+  gint64 before G_GNUC_UNUSED;
 
   g_return_val_if_fail (GSK_IS_NGL_COMMAND_QUEUE (command_queue), NULL);
 
+  before = GDK_PROFILER_CURRENT_TIME;
+
   context = gsk_ngl_command_queue_get_context (command_queue);
 
   gdk_gl_context_make_current (context);
@@ -444,6 +451,8 @@ gsk_ngl_driver_new (GskNglCommandQueue  *command_queue,
   self->icons = gsk_ngl_icon_library_new (self);
   self->shadows = gsk_ngl_shadow_library_new (self);
 
+  gdk_profiler_end_mark (before, "create GskNglDriver", NULL);
+
   return g_steal_pointer (&self);
 }
 
diff --git a/gsk/ngl/gsknglrenderer.c b/gsk/ngl/gsknglrenderer.c
index fa393c11cf..5f8a683b1e 100644
--- a/gsk/ngl/gsknglrenderer.c
+++ b/gsk/ngl/gsknglrenderer.c
@@ -125,7 +125,7 @@ failure:
   g_clear_object (&driver);
   g_clear_object (&context);
 
-  gdk_profiler_end_mark (start_time, "GskNglRenderer realize", NULL);
+  gdk_profiler_end_mark (start_time, "realize GskNglRenderer", NULL);
 
   return ret;
 }
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index accaee07c1..9a7b36eb05 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -26,6 +26,7 @@
 
 #include "gdk/gdk.h"
 #include "gdk/gdk-private.h"
+#include "gdk/gdkprofilerprivate.h"
 #include "gsk/gskprivate.h"
 #include "gsk/gskrendernodeprivate.h"
 #include "gtknative.h"
@@ -520,10 +521,13 @@ static void
 do_post_parse_initialization (void)
 {
   GdkDisplayManager *display_manager;
+  gint64 before G_GNUC_UNUSED;
 
   if (gtk_initialized)
     return;
 
+  before = GDK_PROFILER_CURRENT_TIME;
+
   gettext_initialization ();
 
 #ifdef SIGPIPE
@@ -533,21 +537,28 @@ do_post_parse_initialization (void)
   gtk_widget_set_default_direction (gtk_get_locale_direction ());
 
   gdk_event_init_types ();
+
   gsk_ensure_resources ();
   gsk_render_node_init_types ();
   _gtk_ensure_resources ();
 
+  gdk_profiler_end_mark (before, "basic initialization", NULL);
+
   gtk_initialized = TRUE;
 
+  before = GDK_PROFILER_CURRENT_TIME;
 #ifdef G_OS_UNIX
   gtk_print_backends_init ();
 #endif
   gtk_im_modules_init ();
   gtk_media_file_extension_init ();
+  gdk_profiler_end_mark (before, "init modules", NULL);
 
+  before = GDK_PROFILER_CURRENT_TIME;
   display_manager = gdk_display_manager_get ();
   if (gdk_display_manager_get_default_display (display_manager) != NULL)
     default_display_notify_cb (display_manager);
+  gdk_profiler_end_mark (before, "create display", NULL);
 
   g_signal_connect (display_manager, "notify::default-display",
                     G_CALLBACK (default_display_notify_cb),
@@ -580,6 +591,9 @@ gtk_init_check (void)
   if (gtk_initialized)
     return TRUE;
 
+  if (gdk_profiler_is_running ())
+    g_info ("Profiling is active");
+
   gettext_initialization ();
 
   if (!check_setugid ())


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