[gtk/delayed-loading: 3/5] loaders: Add profiler marks




commit 83782bd9400caaca34778ff1dc394df25398ab53
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 18 14:12:39 2021 -0400

    loaders: Add profiler marks
    
    These are potentially expensive calls, we
    should make sure they show up in profiles.

 gdk/loaders/gdkjpeg.c | 13 +++++++++++++
 gdk/loaders/gdkpng.c  | 11 ++++++++++-
 gdk/loaders/gdktiff.c |  9 +++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/gdk/loaders/gdkjpeg.c b/gdk/loaders/gdkjpeg.c
index c64a0ea99d..d84ae71a50 100644
--- a/gdk/loaders/gdkjpeg.c
+++ b/gdk/loaders/gdkjpeg.c
@@ -23,6 +23,8 @@
 #include "gdktexture.h"
 #include "gdkmemorytextureprivate.h"
 
+#include "gdkprofilerprivate.h"
+
 #include <jpeglib.h>
 #include <jerror.h>
 #include <setjmp.h>
@@ -174,6 +176,7 @@ gdk_load_jpeg (GBytes  *input_bytes,
   GBytes *bytes;
   GdkTexture *texture;
   GdkMemoryFormat format;
+  guint64 before = GDK_PROFILER_CURRENT_TIME;
 
   info.err = jpeg_std_error (&jerr.pub);
   jerr.pub.error_exit = fatal_error_handler;
@@ -260,6 +263,8 @@ gdk_load_jpeg (GBytes  *input_bytes,
 
   g_bytes_unref (bytes);
 
+  gdk_profiler_end_mark (before, "jpeg load", NULL);
+ 
   return texture;
 }
 
@@ -274,6 +279,7 @@ gdk_save_jpeg (GdkTexture *texture)
   guchar *input = NULL;
   guchar *row;
   int width, height, stride;
+  gint64 before = GDK_PROFILER_CURRENT_TIME;
 
   width = gdk_texture_get_width (texture);
   height = gdk_texture_get_height (texture);
@@ -321,6 +327,13 @@ gdk_save_jpeg (GdkTexture *texture)
   g_free (input);
   jpeg_destroy_compress (&info);
 
+  if (GDK_PROFILER_IS_RUNNING)
+    {
+      gint64 end = GDK_PROFILER_CURRENT_TIME;
+      if (end - before > 500000)
+        gdk_profiler_add_mark (before, end - before, "jpeg load", NULL);
+    }
+
   return g_bytes_new_with_free_func (data, size, (GDestroyNotify) free, NULL);
 }
 
diff --git a/gdk/loaders/gdkpng.c b/gdk/loaders/gdkpng.c
index 80fca2460b..4d1302202d 100644
--- a/gdk/loaders/gdkpng.c
+++ b/gdk/loaders/gdkpng.c
@@ -21,6 +21,7 @@
 
 #include "gdkintl.h"
 #include "gdkmemorytextureprivate.h"
+#include "gdkprofilerprivate.h"
 #include "gdktexture.h"
 #include "gdktextureprivate.h"
 #include "gsk/ngl/fp16private.h"
@@ -291,7 +292,7 @@ premultiply_16bit (guchar *data,
 }
 
 /* }}} */
-/* {{{ Public API */
+/* {{{ Public API */ 
 
 GdkTexture *
 gdk_load_png (GBytes  *bytes,
@@ -309,6 +310,7 @@ gdk_load_png (GBytes  *bytes,
   GBytes *out_bytes;
   GdkTexture *texture;
   int bpp;
+  gint64 before = GDK_PROFILER_CURRENT_TIME;
 
   io.data = (guchar *)g_bytes_get_data (bytes, &io.size);
   io.position = 0;
@@ -449,6 +451,13 @@ gdk_load_png (GBytes  *bytes,
   g_free (row_pointers);
   png_destroy_read_struct (&png, &info, NULL);
 
+  if (GDK_PROFILER_IS_RUNNING)
+    {
+      gint64 end = GDK_PROFILER_CURRENT_TIME;
+      if (end - before > 500000)
+        gdk_profiler_add_mark (before, end - before, "png load", NULL);
+    }
+
   return texture;
 }
 
diff --git a/gdk/loaders/gdktiff.c b/gdk/loaders/gdktiff.c
index 62d2194f0c..08b7eb5eab 100644
--- a/gdk/loaders/gdktiff.c
+++ b/gdk/loaders/gdktiff.c
@@ -21,6 +21,7 @@
 
 #include "gdkintl.h"
 #include "gdkmemorytextureprivate.h"
+#include "gdkprofilerprivate.h"
 #include "gdktexture.h"
 #include "gdktextureprivate.h"
 
@@ -411,6 +412,7 @@ gdk_load_tiff (GBytes  *input_bytes,
   int bpp;
   GBytes *bytes;
   GdkTexture *texture;
+  gint64 before = GDK_PROFILER_CURRENT_TIME;
 
   tif = tiff_open_read (input_bytes);
 
@@ -505,6 +507,13 @@ gdk_load_tiff (GBytes  *input_bytes,
 
   TIFFClose (tif);
 
+  if (GDK_PROFILER_IS_RUNNING)
+    {
+      gint64 end = GDK_PROFILER_CURRENT_TIME;
+      if (end - before > 500000)
+        gdk_profiler_add_mark (before, end - before, "tiff load", NULL);
+    }
+
   return texture;
 }
 


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