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.
This commit is contained in:
Alexander Larsson 2020-02-12 11:05:01 +01:00
parent cc643df88b
commit 01d5ad2056
18 changed files with 48 additions and 33 deletions

View File

@ -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
}

View File

@ -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));

View File

@ -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");

View File

@ -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)
{

View File

@ -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);

View File

@ -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;

View File

@ -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");
}

View File

@ -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);
}

View File

@ -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 */
}

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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", "");

View File

@ -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);

View File

@ -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)");

View File

@ -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);
}

View File

@ -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 ();

View File

@ -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", "");