[sysprof/wip/chergert/sysprof-3] libsysprof-ui: add format helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/sysprof-3] libsysprof-ui: add format helper
- Date: Sat, 18 May 2019 01:27:54 +0000 (UTC)
commit 13bf4917df455d5b70973908c92e7e6c3e4dc92d
Author: Christian Hergert <chergert redhat com>
Date: Fri May 17 18:25:38 2019 -0700
libsysprof-ui: add format helper
src/libsysprof-ui/sysprof-ui-private.h | 1 +
src/libsysprof-ui/sysprof-zoom-manager.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
---
diff --git a/src/libsysprof-ui/sysprof-ui-private.h b/src/libsysprof-ui/sysprof-ui-private.h
index d6982c1..31e6fc3 100644
--- a/src/libsysprof-ui/sysprof-ui-private.h
+++ b/src/libsysprof-ui/sysprof-ui-private.h
@@ -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)
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.c b/src/libsysprof-ui/sysprof-zoom-manager.c
index b903aca..fc82bfe 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.c
+++ b/src/libsysprof-ui/sysprof-zoom-manager.c
@@ -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));
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]