libsysprof-ui: add format helper

This commit is contained in:
Christian Hergert
2019-05-17 18:25:38 -07:00
parent 2212650b00
commit 5ccccce26e
2 changed files with 21 additions and 0 deletions

View File

@ -45,6 +45,7 @@ void _sysprof_rounded_rectangle (cairo_t
const GdkRectangle *rect,
gint x_radius,
gint y_radius);
gchar *_sysprof_format_duration (gint64 duration);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofMarkStat, _sysprof_mark_stat_free)

View File

@ -542,3 +542,23 @@ sysprof_zoom_manager_get_offset_at_time (SysprofZoomManager *self,
ratio = offset / (gdouble)full_duration;
return ratio * width;
}
gchar *
_sysprof_format_duration (gint64 duration)
{
gboolean negative = duration < 0;
if (duration == 0)
return g_strdup ("0");
duration = ABS (duration);
if (duration < NSEC_PER_SEC)
return g_strdup_printf ("%s%.2lf msec",
negative ? "-" : "",
(duration / 1000000.0));
else
return g_strdup_printf ("%s%.4lf seconds",
negative ? "-" : "",
(duration / (gdouble)NSEC_PER_SEC));
}