[gtk: 6/14] profiler: Make profiler-is-running a macro
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 6/14] profiler: Make profiler-is-running a macro
- Date: Wed, 12 Feb 2020 14:32:56 +0000 (UTC)
commit 01d5ad2056f9c896246219eb04ca1ae807a45768
Author: Alexander Larsson <alexl redhat com>
Date: Wed Feb 12 11:05:01 2020 +0100
profiler: Make profiler-is-running a macro
When we use if (GDK_PROFILER_IS_RUNNING) this means we get an
inlined if (FALSE) when the compiler support is not compiled in, which
gets rid of all the related code completely.
We also expand to G_UNLIKELY(gdk_profiler_is_running ()) in the supported
case which might cause somewhat better code generation.
gdk/broadway/gdksurface-broadway.c | 2 +-
gdk/gdkdrawcontext.c | 2 +-
gdk/gdkframeclock.c | 14 +++++++-------
gdk/gdkframeclockidle.c | 6 +++---
gdk/gdkprofilerprivate.h | 15 +++++++++++++++
gdk/gdksurface.c | 2 +-
gdk/wayland/gdkdisplay-wayland.c | 2 +-
gdk/wayland/gdksurface-wayland.c | 2 +-
gdk/x11/gdkdisplay-x11.c | 2 +-
gsk/gl/gskglrenderer.c | 4 ++--
gsk/vulkan/gskvulkanrenderer.c | 2 +-
gtk/gtkapplication.c | 8 ++++----
gtk/gtkcssnode.c | 2 +-
gtk/gtkcssprovider.c | 4 ++--
gtk/gtkemojichooser.c | 4 ++--
gtk/gtkicontheme.c | 4 ++--
gtk/gtkwidget.c | 4 ++--
gtk/gtkwindow.c | 2 +-
18 files changed, 48 insertions(+), 33 deletions(-)
---
diff --git a/gdk/broadway/gdksurface-broadway.c b/gdk/broadway/gdksurface-broadway.c
index 5d2426b687..0f2411f63a 100644
--- a/gdk/broadway/gdksurface-broadway.c
+++ b/gdk/broadway/gdksurface-broadway.c
@@ -125,7 +125,7 @@ _gdk_broadway_roundtrip_notify (GdkSurface *surface,
if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
_gdk_frame_clock_debug_print_timings (clock, timings);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
_gdk_frame_clock_add_timings_to_profiler (clock, timings);
#endif
}
diff --git a/gdk/gdkdrawcontext.c b/gdk/gdkdrawcontext.c
index 5c25d87407..35a7fea282 100644
--- a/gdk/gdkdrawcontext.c
+++ b/gdk/gdkdrawcontext.c
@@ -383,7 +383,7 @@ gdk_draw_context_end_frame (GdkDrawContext *context)
GDK_DRAW_CONTEXT_GET_CLASS (context)->end_frame (context, priv->frame_region);
#ifdef G_ENABLE_DEBUG
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_set_int_counter (pixels_counter,
g_get_monotonic_time (),
region_get_pixels (priv->frame_region));
diff --git a/gdk/gdkframeclock.c b/gdk/gdkframeclock.c
index de5deb887a..7d3277f751 100644
--- a/gdk/gdkframeclock.c
+++ b/gdk/gdkframeclock.c
@@ -651,7 +651,7 @@ _gdk_frame_clock_emit_flush_events (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[FLUSH_EVENTS], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "flush-events");
@@ -665,7 +665,7 @@ _gdk_frame_clock_emit_before_paint (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[BEFORE_PAINT], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "before-paint");
@@ -679,7 +679,7 @@ _gdk_frame_clock_emit_update (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[UPDATE], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "update");
@@ -693,7 +693,7 @@ _gdk_frame_clock_emit_layout (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[LAYOUT], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "layout");
@@ -707,7 +707,7 @@ _gdk_frame_clock_emit_paint (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[PAINT], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "paint");
@@ -721,7 +721,7 @@ _gdk_frame_clock_emit_after_paint (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[AFTER_PAINT], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "after-paint");
@@ -735,7 +735,7 @@ _gdk_frame_clock_emit_resume_events (GdkFrameClock *frame_clock)
g_signal_emit (frame_clock, signals[RESUME_EVENTS], 0);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "frameclock", "resume-events");
diff --git a/gdk/gdkframeclockidle.c b/gdk/gdkframeclockidle.c
index b350924ce2..f7d03fa79a 100644
--- a/gdk/gdkframeclockidle.c
+++ b/gdk/gdkframeclockidle.c
@@ -501,7 +501,7 @@ gdk_frame_clock_paint_idle (void *data)
if (priv->freeze_count == 0)
priv->sleep_serial = get_sleep_serial ();
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "frameclock", "paint_idle");
return FALSE;
@@ -565,7 +565,7 @@ gdk_frame_clock_idle_freeze (GdkFrameClock *clock)
if (priv->freeze_count == 0)
{
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
priv->freeze_time = g_get_monotonic_time ();
}
@@ -594,7 +594,7 @@ gdk_frame_clock_idle_thaw (GdkFrameClock *clock)
priv->sleep_serial = get_sleep_serial ();
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
if (priv->freeze_time != 0)
{
diff --git a/gdk/gdkprofilerprivate.h b/gdk/gdkprofilerprivate.h
index 99558e3adf..1c68739e0e 100644
--- a/gdk/gdkprofilerprivate.h
+++ b/gdk/gdkprofilerprivate.h
@@ -23,6 +23,21 @@
G_BEGIN_DECLS
+/* Ensure we included config.h as needed for the below HAVE_SYSPROF_CAPTURE check */
+#ifndef GETTEXT_PACKAGE
+#error "config.h was not included before gdkprofilerprivate.h."
+#endif
+
+/* We make this a macro you use as if (GDK_PROFILER_IS_RUNNING) because that
+ * way we can ensure all the code is compiled out when not supported, and
+ * we can add a G_UNLIKELY() for better codegen if it is.
+ */
+#ifdef HAVE_SYSPROF_CAPTURE
+#define GDK_PROFILER_IS_RUNNING G_UNLIKELY (gdk_profiler_is_running ())
+#else
+#define GDK_PROFILER_IS_RUNNING FALSE
+#endif
+
void gdk_profiler_start (int fd);
void gdk_profiler_stop (void);
gboolean gdk_profiler_is_running (void);
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 9c95736aed..e8485f2034 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -4132,7 +4132,7 @@ gdk_surface_handle_event (GdkEvent *event)
g_signal_emit (gdk_event_get_surface (event), signals[EVENT], 0, event, &handled);
}
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
add_event_mark (event, begin_time, g_get_monotonic_time () - begin_time);
return handled;
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 59ffdea73c..2243440421 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -1153,7 +1153,7 @@ _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland)
gdk_wayland_display_set_cursor_theme (GDK_DISPLAY (display_wayland), name, size);
g_value_unset (&v);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "wayland", "load cursor theme");
}
diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c
index 58d94881a1..c93ec998b1 100644
--- a/gdk/wayland/gdksurface-wayland.c
+++ b/gdk/wayland/gdksurface-wayland.c
@@ -398,7 +398,7 @@ frame_callback (void *data,
_gdk_frame_clock_debug_print_timings (clock, timings);
#endif
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
_gdk_frame_clock_add_timings_to_profiler (clock, timings);
}
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index d270929cf0..e13f74b822 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -1284,7 +1284,7 @@ _gdk_wm_protocols_filter (const XEvent *xevent,
if (GDK_DISPLAY_DEBUG_CHECK (display, FRAMES))
_gdk_frame_clock_debug_print_timings (clock, timings);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
_gdk_frame_clock_add_timings_to_profiler (clock, timings);
#endif /* G_ENABLE_DEBUG */
}
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index b1556f831f..fac7f266c9 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -2857,7 +2857,7 @@ gsk_gl_renderer_realize (GskRenderer *renderer,
self->icon_cache = get_icon_cache_for_display (gdk_surface_get_display (surface), self->atlases);
gsk_gl_shadow_cache_init (&self->shadow_cache);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gl renderer realize", NULL);
return TRUE;
@@ -3561,7 +3561,7 @@ gsk_gl_renderer_do_render (GskRenderer *renderer,
gsk_profiler_push_samples (profiler);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (start_time, cpu_time, "GL render", "");
#endif
diff --git a/gsk/vulkan/gskvulkanrenderer.c b/gsk/vulkan/gskvulkanrenderer.c
index cd10a31857..7f3eeab9ae 100644
--- a/gsk/vulkan/gskvulkanrenderer.c
+++ b/gsk/vulkan/gskvulkanrenderer.c
@@ -211,7 +211,7 @@ gsk_vulkan_renderer_render_texture (GskRenderer *renderer,
gsk_profiler_push_samples (profiler);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gdk_profiler_add_mark (start_time, cpu_time, "render", "");
gdk_profiler_set_int_counter (texture_pixels_counter,
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 6885c4e44f..be3758376c 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -306,7 +306,7 @@ gtk_application_startup (GApplication *g_application)
before2 = g_get_monotonic_time ();
gtk_init ();
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (before2, (g_get_monotonic_time () - before2), "gtk init", NULL);
priv->impl = gtk_application_impl_new (application, gdk_display_get_default ());
@@ -314,7 +314,7 @@ gtk_application_startup (GApplication *g_application)
gtk_application_load_resources (application);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gtk application startup", NULL);
}
@@ -590,7 +590,7 @@ sysprof_profiler_method_call (GDBusConnection *connection,
int fd = -1;
int idx;
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
g_dbus_method_invocation_return_error (invocation,
G_DBUS_ERROR,
@@ -612,7 +612,7 @@ sysprof_profiler_method_call (GDBusConnection *connection,
}
else if (strcmp (method_name, "Stop") == 0)
{
- if (!gdk_profiler_is_running ())
+ if (!GDK_PROFILER_IS_RUNNING)
{
g_dbus_method_invocation_return_error (invocation,
G_DBUS_ERROR,
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 03fd29a795..081662b084 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1351,7 +1351,7 @@ gtk_css_node_validate (GtkCssNode *cssnode)
gtk_css_node_validate_internal (cssnode, &filter, timestamp);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "css validation", "");
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 986d38a40d..3747b35076 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1009,7 +1009,7 @@ gtk_css_provider_postprocess (GtkCssProvider *css_provider)
}
#endif
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "create selector tree", NULL);
}
@@ -1068,7 +1068,7 @@ gtk_css_provider_load_internal (GtkCssProvider *self,
g_bytes_unref (bytes);
}
- if (gdk_profiler_is_running ())
+ 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);
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index a82eaf9e2e..d317cfc0c5 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -465,7 +465,7 @@ populate_emoji_chooser (gpointer data)
now = g_get_monotonic_time ();
if (now > start + 8000)
{
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate");
return G_SOURCE_CONTINUE;
}
@@ -476,7 +476,7 @@ populate_emoji_chooser (gpointer data)
chooser->box = NULL;
chooser->populate_idle = 0;
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
now = g_get_monotonic_time ();
gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate (finish)");
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 398f5558de..38bb7c0f1a 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -1846,7 +1846,7 @@ ensure_valid_themes (GtkIconTheme *self,
load_themes (self);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "icon theme load",
self->current_theme);
if (was_valid)
@@ -3605,7 +3605,7 @@ icon_ensure_texture__locked (GtkIconPaintable *icon,
g_assert (icon->texture != NULL);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
gdk_profiler_add_markf (before, g_get_monotonic_time () - 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 294a5d6b19..9bcf7c0000 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -12193,7 +12193,7 @@ gtk_widget_render (GtkWidget *widget,
gtk_widget_snapshot (widget, snapshot);
root = gtk_snapshot_free_to_node (snapshot);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "widget snapshot", "");
@@ -12211,7 +12211,7 @@ gtk_widget_render (GtkWidget *widget,
gsk_render_node_unref (root);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
before = after;
after = g_get_monotonic_time ();
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 5f179d0c99..eb49687ebd 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6316,7 +6316,7 @@ gtk_window_check_resize (GtkWindow *self)
else if (gtk_widget_get_visible (widget))
gtk_window_move_resize (self);
- if (gdk_profiler_is_running ())
+ if (GDK_PROFILER_IS_RUNNING)
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before, (after - before), "size allocation", "");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]