Convert all profiler times from nsec to usec

usec is the scale of the monotonic timer which is where we get almost
all the times from. The only actual source of nsec is the opengl
GPU time (but who knows what the actual resulution of that is).

Changing this to usec allows us to get rid of " * 1000" in a *lot* of
places all over the codebase, which are ugly and confusing.
This commit is contained in:
Alexander Larsson 2020-02-12 10:44:17 +01:00
parent 13eedf1a9f
commit cc643df88b
19 changed files with 53 additions and 53 deletions

View File

@ -385,7 +385,7 @@ gdk_draw_context_end_frame (GdkDrawContext *context)
#ifdef G_ENABLE_DEBUG
if (gdk_profiler_is_running ())
gdk_profiler_set_int_counter (pixels_counter,
g_get_monotonic_time () * 1000,
g_get_monotonic_time (),
region_get_pixels (priv->frame_region));
#endif

View File

@ -654,7 +654,7 @@ _gdk_frame_clock_emit_flush_events (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "flush-events");
gdk_profiler_add_mark (before, (after - before), "frameclock", "flush-events");
}
}
@ -668,7 +668,7 @@ _gdk_frame_clock_emit_before_paint (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "before-paint");
gdk_profiler_add_mark (before, (after - before), "frameclock", "before-paint");
}
}
@ -682,7 +682,7 @@ _gdk_frame_clock_emit_update (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "update");
gdk_profiler_add_mark (before, (after - before), "frameclock", "update");
}
}
@ -696,7 +696,7 @@ _gdk_frame_clock_emit_layout (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "layout");
gdk_profiler_add_mark (before, (after - before), "frameclock", "layout");
}
}
@ -710,7 +710,7 @@ _gdk_frame_clock_emit_paint (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "paint");
gdk_profiler_add_mark (before, (after - before), "frameclock", "paint");
}
}
@ -724,7 +724,7 @@ _gdk_frame_clock_emit_after_paint (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "after-paint");
gdk_profiler_add_mark (before, (after - before), "frameclock", "after-paint");
}
}
@ -738,7 +738,7 @@ _gdk_frame_clock_emit_resume_events (GdkFrameClock *frame_clock)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "frameclock", "resume-events");
gdk_profiler_add_mark (before, (after - before), "frameclock", "resume-events");
}
}
@ -818,9 +818,9 @@ _gdk_frame_clock_add_timings_to_profiler (GdkFrameClock *clock,
{
if (timings->presentation_time != 0)
{
gdk_profiler_add_mark (timings->presentation_time * 1000, 0, "frameclock", "presentation");
gdk_profiler_add_mark (timings->presentation_time, 0, "frameclock", "presentation");
gdk_profiler_set_counter (fps_counter,
timings->presentation_time * 1000,
timings->presentation_time,
frame_clock_get_fps (clock));
}
}

View File

@ -502,7 +502,7 @@ gdk_frame_clock_paint_idle (void *data)
priv->sleep_serial = get_sleep_serial ();
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "frameclock", "paint_idle");
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "frameclock", "paint_idle");
return FALSE;
}
@ -599,8 +599,8 @@ gdk_frame_clock_idle_thaw (GdkFrameClock *clock)
if (priv->freeze_time != 0)
{
gint64 thaw_time = g_get_monotonic_time ();
gdk_profiler_add_mark (priv->freeze_time * 1000,
(thaw_time - priv->freeze_time) * 1000,
gdk_profiler_add_mark (priv->freeze_time,
(thaw_time - priv->freeze_time),
"frameclock freeze", "");
priv->freeze_time = 0;
}

View File

@ -94,9 +94,9 @@ gdk_profiler_add_mark (gint64 start,
return;
sysprof_capture_writer_add_mark (writer,
start,
start * 1000L,
-1, getpid (),
duration,
duration * 1000L,
"gtk", name, message);
}
@ -118,9 +118,9 @@ gdk_profiler_add_markf (gint64 start,
va_end (args);
sysprof_capture_writer_add_mark (writer,
start,
start * 1000L,
-1, getpid (),
duration,
duration * 1000L,
"gtk", name, message);
g_free (message);
}
@ -178,7 +178,7 @@ gdk_profiler_set_counter (guint id,
value.vdbl = val;
sysprof_capture_writer_set_counters (writer,
time,
time * 1000L,
-1, getpid (),
&id, &value, 1);
}
@ -195,7 +195,7 @@ gdk_profiler_set_int_counter (guint id,
value.v64 = val;
sysprof_capture_writer_set_counters (writer,
time,
time * 1000L,
-1, getpid (),
&id, &value, 1);
}

View File

@ -4103,9 +4103,9 @@ add_event_mark (GdkEvent *event,
}
if (kind != NULL && message != NULL)
gdk_profiler_add_markf (time * 1000L, duration * 1000L, "event", "%s %s", kind, message);
gdk_profiler_add_markf (time, duration, "event", "%s %s", kind, message);
else
gdk_profiler_add_mark (time * 1000L, duration * 1000L, "event", message ? message : kind);
gdk_profiler_add_mark (time, duration, "event", message ? message : kind);
g_free (message);
}

View File

@ -1155,7 +1155,7 @@ _gdk_wayland_display_load_cursor_theme (GdkWaylandDisplay *display_wayland)
if (gdk_profiler_is_running ())
{
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "wayland", "load cursor theme");
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "wayland", "load cursor theme");
}
}

View File

@ -239,7 +239,7 @@ gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
gdk_wayland_surface_sync (surface);
gdk_wayland_surface_request_frame (surface);
gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "swap buffers");
gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "swap buffers");
if (display_wayland->have_egl_swap_buffers_with_damage)
{
int i, j, n_rects = cairo_region_num_rectangles (painted);

View File

@ -357,7 +357,7 @@ frame_callback (void *data,
GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
GdkFrameTimings *timings;
gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "frame event");
gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "frame event");
GDK_DISPLAY_NOTE (GDK_DISPLAY (display_wayland), EVENTS, g_message ("frame %p", surface));
wl_callback_destroy (callback);
@ -478,7 +478,7 @@ on_frame_clock_after_paint (GdkFrameClock *clock,
* before we need to stage any changes, then we can take it back and
* use it again.
*/
gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "surface commit");
gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "surface commit");
wl_surface_commit (impl->display_server.wl_surface);
impl->pending_commit = FALSE;
@ -1510,7 +1510,7 @@ gdk_wayland_surface_create_xdg_toplevel (GdkSurface *surface)
if (impl->hint == GDK_SURFACE_TYPE_HINT_DIALOG)
_gdk_wayland_screen_add_orphan_dialog (surface);
gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "surface commit");
gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "surface commit");
wl_surface_commit (impl->display_server.wl_surface);
}
@ -2305,7 +2305,7 @@ gdk_wayland_surface_create_xdg_popup (GdkSurface *surface,
}
}
gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "wayland", "surface commit");
gdk_profiler_add_mark (g_get_monotonic_time (), 0, "wayland", "surface commit");
wl_surface_commit (impl->display_server.wl_surface);
impl->popup_parent = parent;

View File

@ -171,5 +171,5 @@ gsk_gl_profiler_end_gpu_region (GskGLProfiler *profiler)
else
elapsed = 0;
return elapsed;
return elapsed / 1000; /* Convert to usec to match other profiler APIs */
}

View File

@ -2858,7 +2858,7 @@ gsk_gl_renderer_realize (GskRenderer *renderer,
gsk_gl_shadow_cache_init (&self->shadow_cache);
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "gl renderer realize", NULL);
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gl renderer realize", NULL);
return TRUE;
}

View File

@ -262,7 +262,7 @@ gsk_profiler_timer_begin (GskProfiler *profiler,
return;
timer->in_flight = TRUE;
timer->start_time = g_get_monotonic_time () * 1000;
timer->start_time = g_get_monotonic_time ();
}
gint64
@ -289,7 +289,7 @@ gsk_profiler_timer_end (GskProfiler *profiler,
return 0;
}
diff = (g_get_monotonic_time () * 1000) - timer->start_time;
diff = g_get_monotonic_time () - timer->start_time;
timer->in_flight = FALSE;
timer->value += diff;
@ -360,7 +360,7 @@ gsk_profiler_timer_get (GskProfiler *profiler,
}
if (timer->invert)
return (gint64) (1000000000.0 / (double) timer->value);
return (gint64) (1000000.0 / (double) timer->value);
return timer->value;
}
@ -437,7 +437,7 @@ gsk_profiler_push_samples (GskProfiler *profiler)
s->id = timer->id;
if (timer->invert)
s->value = (gint64) (1000000000.0 / (double) timer->value);
s->value = (gint64) (1000000.0 / (double) timer->value);
else
s->value = timer->value;
}
@ -506,20 +506,19 @@ gsk_profiler_append_timers (GskProfiler *profiler,
{
NamedTimer *timer = value_p;
const char *unit = timer->invert ? "" : "usec";
double scale = timer->invert ? 1.0 : 1000.0;
g_string_append_printf (buffer, "%s (%s): %.2f",
timer->description,
unit,
(double) timer->value / scale);
(double) timer->value);
if (timer->n_samples > 1)
{
timer->avg_value = timer->avg_value / timer->n_samples;
g_string_append_printf (buffer, " Min: %.2f Avg: %.2f Max: %.2f (%" G_GINT64_FORMAT " samples)",
(double) timer->min_value / scale,
(double) timer->avg_value / scale,
(double) timer->max_value / scale,
(double) timer->min_value,
(double) timer->avg_value,
(double) timer->max_value,
timer->n_samples);
}

View File

@ -307,7 +307,7 @@ gtk_application_startup (GApplication *g_application)
before2 = g_get_monotonic_time ();
gtk_init ();
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (before2 * 1000, (g_get_monotonic_time () - before2) * 1000, "gtk init", NULL);
gdk_profiler_add_mark (before2, (g_get_monotonic_time () - before2), "gtk init", NULL);
priv->impl = gtk_application_impl_new (application, gdk_display_get_default ());
gtk_application_impl_startup (priv->impl, priv->register_session);
@ -315,7 +315,7 @@ gtk_application_startup (GApplication *g_application)
gtk_application_load_resources (application);
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "gtk application startup", NULL);
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "gtk application startup", NULL);
}
static void

View File

@ -1625,5 +1625,5 @@ _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
/* restore the original domain */
gtk_builder_set_translation_domain (builder, domain);
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "builder load", filename);
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "builder load", filename);
}

View File

@ -1354,9 +1354,9 @@ gtk_css_node_validate (GtkCssNode *cssnode)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "css validation", "");
gdk_profiler_set_int_counter (invalidated_nodes_counter, after * 1000, invalidated_nodes);
gdk_profiler_set_int_counter (created_styles_counter, after * 1000, created_styles);
gdk_profiler_add_mark (before, (after - before), "css validation", "");
gdk_profiler_set_int_counter (invalidated_nodes_counter, after, invalidated_nodes);
gdk_profiler_set_int_counter (created_styles_counter, after, created_styles);
invalidated_nodes = 0;
created_styles = 0;
}

View File

@ -1010,7 +1010,7 @@ gtk_css_provider_postprocess (GtkCssProvider *css_provider)
#endif
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "create selector tree", NULL);
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "create selector tree", NULL);
}
static void
@ -1071,7 +1071,7 @@ gtk_css_provider_load_internal (GtkCssProvider *self,
if (gdk_profiler_is_running ())
{
char *uri = g_file_get_uri (file);
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "theme load", uri);
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "theme load", uri);
g_free (uri);
}
}

View File

@ -466,7 +466,7 @@ populate_emoji_chooser (gpointer data)
if (now > start + 8000)
{
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (start * 1000, (now - start) * 1000, "emojichooser", "populate");
gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate");
return G_SOURCE_CONTINUE;
}
}
@ -479,7 +479,7 @@ populate_emoji_chooser (gpointer data)
if (gdk_profiler_is_running ())
{
now = g_get_monotonic_time ();
gdk_profiler_add_mark (start * 1000, (now - start) * 1000, "emojichooser", "populate (finish)");
gdk_profiler_add_mark (start, (now - start), "emojichooser", "populate (finish)");
}
return G_SOURCE_REMOVE;

View File

@ -1847,7 +1847,7 @@ ensure_valid_themes (GtkIconTheme *self,
load_themes (self);
if (gdk_profiler_is_running ())
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "icon theme load", self->current_theme);
gdk_profiler_add_mark (before, (g_get_monotonic_time () - before), "icon theme load", self->current_theme);
if (was_valid)
queue_theme_changed (self);
@ -3606,7 +3606,8 @@ icon_ensure_texture__locked (GtkIconPaintable *icon,
g_assert (icon->texture != NULL);
if (gdk_profiler_is_running ())
gdk_profiler_add_markf (before * 1000, (g_get_monotonic_time () - before) * 1000, in_thread ? "icon load (thread)" : "icon load" , "%s size %d@%d", icon->filename, icon->desired_size, icon->desired_scale);
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);
}
static GdkTexture *

View File

@ -12196,7 +12196,7 @@ gtk_widget_render (GtkWidget *widget,
if (gdk_profiler_is_running ())
{
after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "widget snapshot", "");
gdk_profiler_add_mark (before, (after - before), "widget snapshot", "");
}
if (root != NULL)
@ -12215,7 +12215,7 @@ gtk_widget_render (GtkWidget *widget,
{
before = after;
after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "widget render", "");
gdk_profiler_add_mark (before, (after - before), "widget render", "");
}
}
}

View File

@ -6319,7 +6319,7 @@ gtk_window_check_resize (GtkWindow *self)
if (gdk_profiler_is_running ())
{
gint64 after = g_get_monotonic_time ();
gdk_profiler_add_mark (before * 1000, (after - before) * 1000, "size allocation", "");
gdk_profiler_add_mark (before, (after - before), "size allocation", "");
}
}