[gtksourceview] sysprof: use Sysprof collector interface for profiling



commit f0091198fe901b0f9984d697809563eb368a0047
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 22 18:19:12 2020 -0700

    sysprof: use Sysprof collector interface for profiling
    
    This uses the sysprof collector interface for both debug and profiling
    when we detect we are being monitored by sysprof. This ensures that we
    get all of our profiling data in one place (since we will want profiling
    information from GTK itself side-by-side).

 gtksourceview/gtksourcebuffer.c          |   5 +
 gtksourceview/gtksourcecontextengine.c   |  36 ++----
 gtksourceview/gtksourceprintcompositor.c | 202 +++++++++++++------------------
 gtksourceview/gtksourcespacedrawer.c     |  28 +----
 gtksourceview/gtksourcetrace.h           |  14 ++-
 gtksourceview/gtksourceview.c            |  66 +++-------
 6 files changed, 136 insertions(+), 215 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 11312466..e4425fca 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -41,6 +41,7 @@
 #include "gtksourcesearchcontext-private.h"
 #include "gtksourcetag.h"
 #include "gtksource-enumtypes.h"
+#include "gtksourcetrace.h"
 
 /**
  * SECTION:buffer
@@ -1014,7 +1015,11 @@ cursor_moved (GtkSourceBuffer *buffer)
 {
        queue_bracket_highlighting_update (buffer);
 
+       GTK_SOURCE_PROFILER_BEGIN_MARK;
+
        g_signal_emit (buffer, buffer_signals[CURSOR_MOVED], 0);
+
+       GTK_SOURCE_PROFILER_END_MARK ("GtkSourceBuffer::cursor-moved", NULL);
 }
 
 static void
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index 364270a9..f8bdbca6 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -34,26 +34,12 @@
 #include "gtksourcestyle.h"
 #include "gtksourcestylescheme.h"
 #include "gtksourceutils-private.h"
+#include "gtksourcetrace.h"
 
-#undef ENABLE_DEBUG
-#undef ENABLE_PROFILE
 #undef ENABLE_CHECK_TREE
 
-#ifdef ENABLE_DEBUG
-#define DEBUG(x) (x)
-#else
-#define DEBUG(x)
-#endif
-
-#ifdef ENABLE_PROFILE
-#define PROFILE(x) (x)
-#else
-#define PROFILE(x)
-#endif
-
-#if defined (ENABLE_DEBUG) || defined (ENABLE_PROFILE) || \
-    defined (ENABLE_CHECK_TREE)
-#define NEED_DEBUG_ID
+#if defined (GTK_SOURCE_PROFILER_ENABLED) || defined (ENABLE_CHECK_TREE)
+# define NEED_DEBUG_ID
 #endif
 
 /* Priority of one-time idle which is installed after buffer is modified. */
@@ -1301,7 +1287,7 @@ add_invalid (GtkSourceContextEngine *ce,
                                                   segment,
                                                   (GCompareFunc) segment_cmp);
 
-       DEBUG (g_print ("%d invalid\n", g_slist_length (ce->invalid)));
+       GTK_SOURCE_PROFILER_LOG ("%d invalid", g_slist_length (ce->invalid));
 }
 
 /**
@@ -1805,14 +1791,16 @@ invalidate_region (GtkSourceContextEngine *ce,
                region->delta += length;
        }
 
-       DEBUG (({
+#ifdef DEVELOPMENT_BUILD
+       {
                gint start, end;
                gtk_text_buffer_get_iter_at_mark (buffer, &iter, region->start);
                start = gtk_text_iter_get_offset (&iter);
                gtk_text_buffer_get_iter_at_mark (buffer, &iter, region->end);
                end = gtk_text_iter_get_offset (&iter);
                g_assert (start <= end - region->delta);
-       }));
+       }
+#endif
 
        CHECK_TREE (ce);
 
@@ -3302,7 +3290,7 @@ context_unref (Context *context)
        if (context == NULL || --context->ref_count != 0)
                return;
 
-       DEBUG (g_print ("destroying context %s\n", context->definition->id));
+       GTK_SOURCE_PROFILER_LOG ("destroying context %s\n", context->definition->id);
 
        children = context->children;
        context->children = NULL;
@@ -5563,9 +5551,9 @@ update_syntax (GtkSourceContextEngine *ce,
 
        refresh_range (ce, &start_iter, &end_iter);
 
-       PROFILE (g_print ("analyzed %d chars from %d to %d in %fms\n",
-                         analyzed_end - start_offset, start_offset, analyzed_end,
-                         g_timer_elapsed (timer, NULL) * 1000));
+       GTK_SOURCE_PROFILER_LOG ("analyzed %d chars from %d to %d in %fms",
+                                analyzed_end - start_offset, start_offset, analyzed_end,
+                                g_timer_elapsed (timer, NULL) * 1000);
 
        g_timer_destroy (timer);
 
diff --git a/gtksourceview/gtksourceprintcompositor.c b/gtksourceview/gtksourceprintcompositor.c
index a07438ce..f5441c5e 100644
--- a/gtksourceview/gtksourceprintcompositor.c
+++ b/gtksourceview/gtksourceprintcompositor.c
@@ -30,6 +30,7 @@
 #include "gtksourceview.h"
 #include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
+#include "gtksourcetrace.h"
 
 /**
  * SECTION:printcompositor
@@ -50,27 +51,6 @@
  * the printed area is not clipped.
  */
 
-/*
-#define ENABLE_DEBUG
-#define ENABLE_PROFILE
-*/
-
-#undef ENABLE_DEBUG
-#undef ENABLE_PROFILE
-
-#ifdef ENABLE_DEBUG
-#define DEBUG(x) (x)
-#else
-#define DEBUG(x)
-#endif
-
-#ifdef ENABLE_PROFILE
-#define PROFILE(x) (x)
-static GTimer *pagination_timer = NULL;
-#else
-#define PROFILE(x)
-#endif
-
 #define DEFAULT_TAB_WIDTH              8
 #define MAX_TAB_WIDTH                  32
 
@@ -173,6 +153,10 @@ typedef struct
        PangoLanguage           *language; /* must not be freed */
 
        GtkTextMark             *pagination_mark;
+
+#ifdef GTK_SOURCE_PROFILER_ENABLED
+       gint64                   pagination_timer;
+#endif
 } GtkSourcePrintCompositorPrivate;
 
 enum
@@ -2064,14 +2048,11 @@ calculate_line_numbers_layout_size (GtkSourcePrintCompositor *compositor,
                priv->line_numbers_width = 0.0;
                priv->line_numbers_height = 0.0;
 
-               DEBUG ({
-                       g_debug ("line_numbers_width: %f points (%f mm)",
-                                priv->line_numbers_width,
-                                convert_to_mm (priv->line_numbers_width, GTK_UNIT_POINTS));
-                       g_debug ("line_numbers_height: %f points (%f mm)",
-                                priv->line_numbers_height,
-                                convert_to_mm (priv->line_numbers_height, GTK_UNIT_POINTS));
-               });
+               GTK_SOURCE_PROFILER_LOG ("line_numbers_width: %f points (%f mm), line_numbers_height: %f 
points (%f mm)",
+                                        priv->line_numbers_width,
+                                        convert_to_mm (priv->line_numbers_width, GTK_UNIT_POINTS),
+                                        priv->line_numbers_height,
+                                        convert_to_mm (priv->line_numbers_height, GTK_UNIT_POINTS));
 
                return;
        }
@@ -2086,14 +2067,11 @@ calculate_line_numbers_layout_size (GtkSourcePrintCompositor *compositor,
                         &priv->line_numbers_width,
                         &priv->line_numbers_height);
 
-       DEBUG ({
-               g_debug ("line_numbers_width: %f points (%f mm)",
-                        priv->line_numbers_width,
-                        convert_to_mm (priv->line_numbers_width, GTK_UNIT_POINTS));
-               g_debug ("line_numbers_height: %f points (%f mm)",
-                        priv->line_numbers_height,
-                        convert_to_mm (priv->line_numbers_height, GTK_UNIT_POINTS));
-       });
+       GTK_SOURCE_PROFILER_LOG ("line_numbers_width: %f points (%f mm), line_numbers_height: %f points (%f 
mm)",
+                                priv->line_numbers_width,
+                                convert_to_mm (priv->line_numbers_width, GTK_UNIT_POINTS),
+                                priv->line_numbers_height,
+                                convert_to_mm (priv->line_numbers_height, GTK_UNIT_POINTS));
 }
 
 static gdouble
@@ -2137,11 +2115,9 @@ calculate_header_height (GtkSourcePrintCompositor *compositor,
        {
                priv->header_height = 0.0;
 
-               DEBUG ({
-                       g_debug ("header_height: %f points (%f mm)",
-                                priv->header_height,
-                                convert_to_mm (priv->header_height, GTK_UNIT_POINTS));
-               });
+               GTK_SOURCE_PROFILER_LOG ("header_height: %f points (%f mm)",
+                                        priv->header_height,
+                                        convert_to_mm (priv->header_height, GTK_UNIT_POINTS));
 
                return;
        }
@@ -2153,11 +2129,9 @@ calculate_header_height (GtkSourcePrintCompositor *compositor,
                                                                          priv->header_font,
                                                                          NULL);
 
-       DEBUG ({
-               g_debug ("header_height: %f points (%f mm)",
-                        priv->header_height,
-                        convert_to_mm (priv->header_height, GTK_UNIT_POINTS));
-       });
+       GTK_SOURCE_PROFILER_LOG ("header_height: %f points (%f mm)",
+                                priv->header_height,
+                                convert_to_mm (priv->header_height, GTK_UNIT_POINTS));
 }
 
 static void
@@ -2170,12 +2144,9 @@ calculate_footer_height (GtkSourcePrintCompositor *compositor,
        {
                priv->footer_height = 0.0;
 
-               DEBUG ({
-                       g_debug ("footer_height: %f points (%f mm)",
-                                priv->footer_height,
-                                convert_to_mm (priv->footer_height, GTK_UNIT_POINTS));
-               });
-
+               GTK_SOURCE_PROFILER_LOG ("footer_height: %f points (%f mm)",
+                                        priv->footer_height,
+                                        convert_to_mm (priv->footer_height, GTK_UNIT_POINTS));
 
                return;
        }
@@ -2188,11 +2159,9 @@ calculate_footer_height (GtkSourcePrintCompositor *compositor,
                                                                          priv->footer_font,
                                                                          &priv->footer_font_descent);
 
-       DEBUG ({
-               g_debug ("footer_height: %f points (%f mm)",
-                        priv->footer_height,
-                        convert_to_mm (priv->footer_height, GTK_UNIT_POINTS));
-       });
+       GTK_SOURCE_PROFILER_LOG ("footer_height: %f points (%f mm)",
+                                priv->footer_height,
+                                convert_to_mm (priv->footer_height, GTK_UNIT_POINTS));
 }
 
 static void
@@ -2224,39 +2193,34 @@ calculate_page_size_and_margins (GtkSourcePrintCompositor *compositor,
        priv->real_margin_right = MAX (gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_POINTS),
                                                   convert_from_mm (priv->margin_right, GTK_UNIT_POINTS));
 
-       DEBUG ({
-               g_debug ("real_margin_top: %f points (%f mm)",
-                        priv->real_margin_top,
-                        convert_to_mm (priv->real_margin_top, GTK_UNIT_POINTS));
-               g_debug ("real_margin_bottom: %f points (%f mm)",
-                        priv->real_margin_bottom,
-                        convert_to_mm (priv->real_margin_bottom, GTK_UNIT_POINTS));
-               g_debug ("real_margin_left: %f points (%f mm)",
-                        priv->real_margin_left,
-                        convert_to_mm (priv->real_margin_left, GTK_UNIT_POINTS));
-               g_debug ("real_margin_righ: %f points (%f mm)",
-                        priv->real_margin_right,
-                        convert_to_mm (priv->real_margin_right, GTK_UNIT_POINTS));
-       });
+       GTK_SOURCE_PROFILER_LOG ("real_margin_top: %f points (%f mm), "
+                                "real_margin_bottom: %f points (%f mm), "
+                                "real_margin_left: %f points (%f mm), "
+                                "real_margin_righ: %f points (%f mm)",
+                                priv->real_margin_top,
+                                convert_to_mm (priv->real_margin_top, GTK_UNIT_POINTS),
+                                priv->real_margin_bottom,
+                                convert_to_mm (priv->real_margin_bottom, GTK_UNIT_POINTS),
+                                priv->real_margin_left,
+                                convert_to_mm (priv->real_margin_left, GTK_UNIT_POINTS),
+                                priv->real_margin_right,
+                                convert_to_mm (priv->real_margin_right, GTK_UNIT_POINTS));
 
        priv->paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
        priv->paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
 
-       DEBUG ({
-               gdouble text_width;
-               gdouble text_height;
-               g_debug ("paper_width: %f points (%f mm)",
-                        priv->paper_width,
-                        convert_to_mm (priv->paper_width, GTK_UNIT_POINTS));
-               g_debug ("paper_heigth: %f points (%f mm)",
-                        priv->paper_height,
-                        convert_to_mm (priv->paper_height, GTK_UNIT_POINTS));
-               text_width = get_text_width (compositor);
-               text_height = get_text_height (compositor);
-               g_debug ("text_width: %f points (%f mm)", text_width, convert_to_mm (text_width, 
GTK_UNIT_POINTS));
-               g_debug ("text_height: %f points (%f mm)", text_height, convert_to_mm (text_height, 
GTK_UNIT_POINTS));
-
-       });
+       GTK_SOURCE_PROFILER_LOG ("paper_width: %f points (%f mm), "
+                                "paper_heigth: %f points (%f mm), "
+                                "text_width: %f points (%f mm), "
+                                "text_height: %f points (%f mm)",
+                                priv->paper_width,
+                                convert_to_mm (priv->paper_width, GTK_UNIT_POINTS),
+                                priv->paper_height,
+                                convert_to_mm (priv->paper_height, GTK_UNIT_POINTS),
+                                get_text_width (compositor),
+                                convert_to_mm (get_text_width (compositor), GTK_UNIT_POINTS),
+                                get_text_height (compositor),
+                                convert_to_mm (get_text_height (compositor), GTK_UNIT_POINTS));
 }
 
 /* TODO: maybe we should have a public api to set
@@ -2614,12 +2578,10 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
 
        if (priv->state == INIT)
        {
-               PROFILE ({
-                       if (pagination_timer != NULL)
-                               g_timer_destroy (pagination_timer);
-
-                       pagination_timer = g_timer_new ();
-               });
+               if (GTK_SOURCE_PROFILER_ACTIVE)
+               {
+                       priv->pagination_timer = GTK_SOURCE_PROFILER_CURRENT_TIME;
+               }
 
                g_return_val_if_fail (priv->pages == NULL, TRUE);
 
@@ -2662,9 +2624,7 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                                                  priv->pagination_mark);
        }
 
-       DEBUG ({
-               g_debug ("Start paginating at %d", gtk_text_iter_get_offset (&start));
-       });
+       GTK_SOURCE_PROFILER_LOG ("Start paginating at %d", gtk_text_iter_get_offset (&start));
 
        gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (priv->buffer), &end);
 
@@ -2799,17 +2759,17 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
 
        if (done)
        {
-               PROFILE ({
-                       g_debug ("Paginated in %f seconds:\n", g_timer_elapsed (pagination_timer, NULL));
-
-                       g_timer_destroy (pagination_timer);
-                       pagination_timer = NULL;
-               });
 
-               DEBUG ({
-                       int i;
+#ifdef GTK_SOURCE_PROFILER_ENABLED
+               if (GTK_SOURCE_PROFILER_ACTIVE)
+               {
+                       gint64 duration = GTK_SOURCE_PROFILER_CURRENT_TIME - priv->pagination_timer;
+                       char *message = g_strdup_printf ("Paginated in %lf seconds",
+                                                        (duration / 1000L) / (double)G_USEC_PER_SEC);
+                       GTK_SOURCE_PROFILER_MARK (duration, "Print Pagination", message);
+                       g_free (message);
 
-                       for (i = 0; i < priv->pages->len; i += 1)
+                       for (guint i = 0; i < priv->pages->len; i += 1)
                        {
                                gint offset;
                                GtkTextIter iter;
@@ -2817,9 +2777,11 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                                offset = g_array_index (priv->pages, int, i);
                                gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (priv->buffer), &iter, 
offset);
 
-                               g_debug ("  page %d starts at line %d (offset %d)\n", i, 
gtk_text_iter_get_line (&iter), offset);
+                               GTK_SOURCE_PROFILER_LOG ("page %d starts at line %d (offset %d)",
+                                                        i, gtk_text_iter_get_line (&iter), offset);
                        }
-               });
+               }
+#endif
 
                priv->state = DONE;
 
@@ -2921,7 +2883,9 @@ print_header_string (GtkSourcePrintCompositor *compositor,
                                break;
                }
 
-               DEBUG ({
+#if 0
+               /* Debug Margins */
+               {
                        cairo_save (cr);
 
                        cairo_set_line_width (cr, 1.);
@@ -2934,7 +2898,8 @@ print_header_string (GtkSourcePrintCompositor *compositor,
                        cairo_stroke (cr);
 
                        cairo_restore (cr);
-               });
+               }
+#endif
 
                line = pango_layout_iter_get_line_readonly (iter);
 
@@ -3040,7 +3005,9 @@ print_footer_string (GtkSourcePrintCompositor *compositor,
                /* Print only the first line */
                line = pango_layout_get_line (priv->footer_layout, 0);
 
-               DEBUG ({
+#if 0
+               /* Debug Footer Line */
+               {
                        gdouble w;
                        gdouble h;
 
@@ -3056,12 +3023,12 @@ print_footer_string (GtkSourcePrintCompositor *compositor,
                                         layout_height);
                        cairo_stroke (cr);
                        cairo_restore (cr);
-               });
+               }
+#endif
 
                cairo_move_to (cr,
-                              x,
-                              priv->paper_height -
-                               priv->real_margin_bottom - priv->footer_font_descent);
+                              x,
+                              priv->paper_height - priv->real_margin_bottom - priv->footer_font_descent);
 
                pango_cairo_show_layout_line (cr, line);
 
@@ -3184,7 +3151,9 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
        y = get_text_y (compositor);
        ln_x = get_line_numbers_x (compositor);
 
-       DEBUG ({
+#if 0
+       /* Debug Page Drawing */
+       {
                cairo_save (cr);
 
                cairo_set_line_width (cr, 1.);
@@ -3220,7 +3189,8 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
                cairo_stroke (cr);
 
                cairo_restore (cr);
-       });
+       }
+#endif
 
        g_return_if_fail (priv->layout != NULL);
        pango_cairo_update_layout (cr, priv->layout);
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index 9f4793b2..9644d2ff 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -32,6 +32,7 @@
 #include "gtksourcestylescheme.h"
 #include "gtksourcestylescheme-private.h"
 #include "gtksourcetag.h"
+#include "gtksourcetrace.h"
 #include "gtksourceview.h"
 
 /**
@@ -88,12 +89,6 @@
  * default with a DVD of Matrix, in case the astronauts are bored.
  */
 
-#if 0
-# define ENABLE_PROFILE
-#else
-# undef ENABLE_PROFILE
-#endif
-
 typedef enum
 {
        DRAW_TAB,
@@ -1217,16 +1212,6 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
        GtkTextIter line_end;
        gboolean is_wrapping;
 
-#ifdef ENABLE_PROFILE
-       static GTimer *timer = NULL;
-       if (timer == NULL)
-       {
-               timer = g_timer_new ();
-       }
-
-       g_timer_start (timer);
-#endif
-
        g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
@@ -1245,6 +1230,8 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
                return;
        }
 
+       GTK_SOURCE_PROFILER_BEGIN_MARK;
+
        gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible);
 
        is_wrapping = gtk_text_view_get_wrap_mode (text_view) != GTK_WRAP_NONE;
@@ -1328,12 +1315,5 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
                }
        };
 
-#ifdef ENABLE_PROFILE
-       g_timer_stop (timer);
-
-       /* Same indentation as similar features in gtksourceview.c. */
-       g_print ("    %s time: %g (sec * 1000)\n",
-                G_STRFUNC,
-                g_timer_elapsed (timer, NULL) * 1000);
-#endif
+       GTK_SOURCE_PROFILER_END_MARK ("GtkSourceSpaceDrawer::draw", NULL);
 }
diff --git a/gtksourceview/gtksourcetrace.h b/gtksourceview/gtksourcetrace.h
index afee58f3..8679fee2 100644
--- a/gtksourceview/gtksourcetrace.h
+++ b/gtksourceview/gtksourcetrace.h
@@ -34,6 +34,9 @@
 G_BEGIN_DECLS
 
 #ifdef HAVE_SYSPROF
+# define GTK_SOURCE_PROFILER_ENABLED 1
+# define GTK_SOURCE_PROFILER_CURRENT_TIME SYSPROF_CAPTURE_CURRENT_TIME
+# define GTK_SOURCE_PROFILER_ACTIVE (sysprof_collector_is_active())
 # define GTK_SOURCE_PROFILER_BEGIN_MARK \
   G_STMT_START { \
     gint64 __begin_time = SYSPROF_CAPTURE_CURRENT_TIME;
@@ -46,13 +49,22 @@ G_BEGIN_DECLS
 # define GTK_SOURCE_PROFILER_MARK(duration, name, message) \
   G_STMT_START { \
     sysprof_collector_mark (SYSPROF_CAPTURE_CURRENT_TIME - duration, \
-                            duration, "GtkSourceView", name, message) \
+                            duration, "GtkSourceView", name, message); \
+  } G_STMT_END
+# define GTK_SOURCE_PROFILER_LOG(format, ...) \
+  G_STMT_START { \
+    if (GTK_SOURCE_PROFILER_ACTIVE) \
+      sysprof_collector_log_printf(G_LOG_LEVEL_DEBUG, G_LOG_DOMAIN, format, __VA_ARGS__); \
   } G_STMT_END
 #else
+# undef GTK_SOURCE_PROFILER_ENABLED
+# define GTK_SOURCE_PROFILER_ACTIVE (0)
+# define GTK_SOURCE_PROFILER_CURRENT_TIME 0
 # define GTK_SOURCE_PROFILER_MARK(duration, name, message) \
   G_STMT_START { } G_STMT_END
 # define GTK_SOURCE_PROFILER_BEGIN_MARK G_STMT_START {
 # define GTK_SOURCE_PROFILER_END_MARK(name, message) } G_STMT_END
+# define GTK_SOURCE_PROFILER_LOG(format, ...) G_STMT_START { } G_STMT_END
 #endif
 
 G_END_DECLS
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 8edc1494..5a579783 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -52,6 +52,7 @@
 #include "gtksourcespacedrawer-private.h"
 #include "gtksourcesnippet.h"
 #include "gtksourcesnippetcontext.h"
+#include "gtksourcetrace.h"
 
 /**
  * SECTION:view
@@ -116,28 +117,6 @@
  * the default font set in CSS.
  */
 
-/*
-#define ENABLE_DEBUG
-*/
-#undef ENABLE_DEBUG
-
-/*
-#define ENABLE_PROFILE
-*/
-#undef ENABLE_PROFILE
-
-#ifdef ENABLE_DEBUG
-#define DEBUG(x) (x)
-#else
-#define DEBUG(x)
-#endif
-
-#ifdef ENABLE_PROFILE
-#define PROFILE(x) (x)
-#else
-#define PROFILE(x)
-#endif
-
 #define GUTTER_PIXMAP                   16
 #define DEFAULT_TAB_WIDTH               8
 #define MAX_TAB_WIDTH                   32
@@ -2275,12 +2254,15 @@ gtk_source_view_ensure_redrawn_rect_is_highlighted (GtkSourceView *view,
        gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter2, clip->y + clip->height, NULL);
        gtk_text_iter_forward_line (&iter2);
 
-       DEBUG ({
-               g_print ("    draw area: %d - %d\n", clip->y, clip->y + clip->height);
-               g_print ("    lines to update: %d - %d\n",
-                        gtk_text_iter_get_line (&iter1),
-                        gtk_text_iter_get_line (&iter2));
-       });
+       if (GTK_SOURCE_PROFILER_ACTIVE)
+       {
+               char *message = g_strdup_printf ("Area: Y=%d Height=%d BeginLine=%d EndLine=%d",
+                                                clip->y, clip->height,
+                                                gtk_text_iter_get_line (&iter1),
+                                                gtk_text_iter_get_line (&iter2));
+               GTK_SOURCE_PROFILER_MARK (0, "GtkSourceView::IsHighlighted", message);
+               g_free (message);
+       }
 
        _gtk_source_buffer_update_syntax_highlight (priv->source_buffer,
                                                    &iter1, &iter2, FALSE);
@@ -2451,11 +2433,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
                count = 1;
        }
 
-       DEBUG ({
-               g_print ("    Painting marks background for line numbers %d - %d\n",
-                        g_array_index (numbers, gint, 0),
-                        g_array_index (numbers, gint, count - 1));
-       });
+       GTK_SOURCE_PROFILER_BEGIN_MARK;
 
        for (i = 0; i < count; ++i)
        {
@@ -2503,6 +2481,8 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
                }
        }
 
+       GTK_SOURCE_PROFILER_END_MARK ("GtkSourceView::paint-marks-background", NULL);
+
        g_array_free (heights, TRUE);
        g_array_free (pixels, TRUE);
        g_array_free (numbers, TRUE);
@@ -2517,19 +2497,10 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
        GdkRectangle visible_rect;
        gdouble x;
 
-#ifdef ENABLE_PROFILE
-       static GTimer *timer = NULL;
-
-       if (timer == NULL)
-       {
-               timer = g_timer_new ();
-       }
-
-       g_timer_start (timer);
-#endif
-
        g_return_if_fail (priv->right_margin_line_color_set);
 
+       GTK_SOURCE_PROFILER_BEGIN_MARK;
+
         gtk_text_view_get_visible_rect (text_view, &visible_rect);
 
        if (priv->cached_right_margin_pos < 0)
@@ -2563,12 +2534,7 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
 
        gtk_snapshot_restore (snapshot);
 
-       PROFILE ({
-               g_timer_stop (timer);
-               g_print ("    gtk_source_view_paint_right_margin time: "
-                        "%g (sec * 1000)\n",
-                        g_timer_elapsed (timer, NULL) * 1000);
-       });
+       GTK_SOURCE_PROFILER_END_MARK ("GtkSourceView::paint-right-margin", NULL);
 }
 
 static gint


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