[sysprof] cleanup: remove duplicated NSEC_PER_SEC macros



commit c2728b8adaddc4a05889f25175d0bb627f12b44a
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 18 10:22:46 2019 -0700

    cleanup: remove duplicated NSEC_PER_SEC macros
    
    This switches everything to using a single 64-bit constant for NSEC_PER_SEC
    that ensure we're doing 64-bit math everywhere.

 src/libsysprof-capture/sysprof-clock.h             |  4 ++-
 src/libsysprof-ui/sysprof-cell-renderer-duration.c |  2 --
 src/libsysprof-ui/sysprof-details-page.c           |  4 +--
 src/libsysprof-ui/sysprof-log-model.c              |  8 ++---
 src/libsysprof-ui/sysprof-marks-page.c             |  6 ++--
 src/libsysprof-ui/sysprof-time-label.c             |  2 --
 src/libsysprof-ui/sysprof-visualizer-ticks.c       | 39 +++++++++++-----------
 src/libsysprof-ui/sysprof-zoom-manager.c           | 12 +++----
 src/tools/sysprof-dump.c                           | 18 +++++-----
 9 files changed, 42 insertions(+), 53 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-clock.h b/src/libsysprof-capture/sysprof-clock.h
index c4c8af2..ac101a3 100644
--- a/src/libsysprof-capture/sysprof-clock.h
+++ b/src/libsysprof-capture/sysprof-clock.h
@@ -67,6 +67,8 @@ typedef gint SysprofClock;
 typedef gint64 SysprofTimeStamp;
 typedef gint32 SysprofTimeSysprofan;
 
+#define SYSPROF_NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
+
 SYSPROF_AVAILABLE_IN_ALL
 SysprofClock sysprof_clock;
 
@@ -80,7 +82,7 @@ sysprof_clock_get_current_time (void)
     clock = CLOCK_MONOTONIC;
   clock_gettime (clock, &ts);
 
-  return (ts.tv_sec * G_GINT64_CONSTANT (1000000000)) + ts.tv_nsec;
+  return (ts.tv_sec * SYSPROF_NSEC_PER_SEC) + ts.tv_nsec;
 }
 
 static inline SysprofTimeSysprofan
diff --git a/src/libsysprof-ui/sysprof-cell-renderer-duration.c 
b/src/libsysprof-ui/sysprof-cell-renderer-duration.c
index 462b83e..d1cebda 100644
--- a/src/libsysprof-ui/sysprof-cell-renderer-duration.c
+++ b/src/libsysprof-ui/sysprof-cell-renderer-duration.c
@@ -26,8 +26,6 @@
 #include "sysprof-ui-private.h"
 #include "sysprof-zoom-manager.h"
 
-#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
-
 typedef struct
 {
   gint64 capture_begin_time;
diff --git a/src/libsysprof-ui/sysprof-details-page.c b/src/libsysprof-ui/sysprof-details-page.c
index 13170f4..03963c5 100644
--- a/src/libsysprof-ui/sysprof-details-page.c
+++ b/src/libsysprof-ui/sysprof-details-page.c
@@ -33,8 +33,6 @@
 #include "sysprof-details-page.h"
 #include "sysprof-ui-private.h"
 
-#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
-
 struct _SysprofDetailsPage
 {
   SysprofPage   parent_instance;
@@ -231,7 +229,7 @@ sysprof_details_page_set_reader (SysprofDetailsPage   *self,
 
   duration = sysprof_capture_reader_get_end_time (reader) -
              sysprof_capture_reader_get_start_time (reader);
-  duration_str = g_strdup_printf (_("%0.4lf seconds"), duration / (gdouble)NSEC_PER_SEC);
+  duration_str = g_strdup_printf (_("%0.4lf seconds"), duration / (gdouble)SYSPROF_NSEC_PER_SEC);
   gtk_label_set_label (self->duration, duration_str);
 
   if (sysprof_capture_reader_get_stat (reader, &st_buf))
diff --git a/src/libsysprof-ui/sysprof-log-model.c b/src/libsysprof-ui/sysprof-log-model.c
index d5abfed..c7b3183 100644
--- a/src/libsysprof-ui/sysprof-log-model.c
+++ b/src/libsysprof-ui/sysprof-log-model.c
@@ -28,8 +28,6 @@
 
 #include "sysprof-log-model.h"
 
-#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
-
 struct _SysprofLogModel
 {
   GObject       parent_instance;
@@ -189,9 +187,9 @@ sysprof_log_model_get_value (GtkTreeModel *model,
     case SYSPROF_LOG_MODEL_COLUMN_TIME_STRING:
       {
         gint64 offset = item->time - self->begin_time;
-        gint min = offset / (NSEC_PER_SEC * 60L);
-        gint seconds = (offset - (min * NSEC_PER_SEC)) / NSEC_PER_SEC;
-        gint msec = (offset % NSEC_PER_SEC) / (NSEC_PER_SEC / 1000L);
+        gint min = offset / SYSPROF_NSEC_PER_SEC / 60L;
+        gint seconds = (offset - (min * SYSPROF_NSEC_PER_SEC)) / SYSPROF_NSEC_PER_SEC;
+        gint msec = (offset % SYSPROF_NSEC_PER_SEC) / (SYSPROF_NSEC_PER_SEC / 1000L);
 
         g_value_init (value, G_TYPE_STRING);
         g_value_take_string (value,
diff --git a/src/libsysprof-ui/sysprof-marks-page.c b/src/libsysprof-ui/sysprof-marks-page.c
index a0e0ae5..5ceff30 100644
--- a/src/libsysprof-ui/sysprof-marks-page.c
+++ b/src/libsysprof-ui/sysprof-marks-page.c
@@ -28,8 +28,6 @@
 #include "sysprof-ui-private.h"
 #include "sysprof-zoom-manager.h"
 
-#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
-
 typedef struct
 {
   SysprofMarksModelKind        kind;
@@ -245,9 +243,9 @@ sysprof_marks_page_tree_view_query_tooltip_cb (SysprofMarksPage *self,
           durationstr = _sysprof_format_duration (duration);
 
           if (duration != 0)
-            timestr = g_strdup_printf ("%0.4lf (%s)", begin_time / (gdouble)NSEC_PER_SEC, durationstr);
+            timestr = g_strdup_printf ("%0.4lf (%s)", begin_time / (gdouble)SYSPROF_NSEC_PER_SEC, 
durationstr);
           else
-            timestr = g_strdup_printf ("%0.4lf", begin_time / (gdouble)NSEC_PER_SEC);
+            timestr = g_strdup_printf ("%0.4lf", begin_time / (gdouble)SYSPROF_NSEC_PER_SEC);
 
           tooltip_text = g_strdup_printf ("%s: %s", timestr, text);
 
diff --git a/src/libsysprof-ui/sysprof-time-label.c b/src/libsysprof-ui/sysprof-time-label.c
index eac8898..2ce58e7 100644
--- a/src/libsysprof-ui/sysprof-time-label.c
+++ b/src/libsysprof-ui/sysprof-time-label.c
@@ -24,8 +24,6 @@
 
 #include "sysprof-time-label.h"
 
-#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
-
 struct _SysprofTimeLabel
 {
   GtkBox parent;
diff --git a/src/libsysprof-ui/sysprof-visualizer-ticks.c b/src/libsysprof-ui/sysprof-visualizer-ticks.c
index fc3a60a..af55c0c 100644
--- a/src/libsysprof-ui/sysprof-visualizer-ticks.c
+++ b/src/libsysprof-ui/sysprof-visualizer-ticks.c
@@ -27,11 +27,10 @@
 
 #include "sysprof-visualizer-ticks.h"
 
-#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
-#define NSEC_PER_DAY (NSEC_PER_SEC * 60L * 60L * 24L)
-#define NSEC_PER_HOUR (NSEC_PER_SEC * 60L * 60L)
-#define NSEC_PER_MIN (NSEC_PER_SEC * 60L)
-#define NSEC_PER_MSEC (NSEC_PER_SEC/G_GINT64_CONSTANT(1000))
+#define NSEC_PER_DAY (SYSPROF_NSEC_PER_SEC * 60L * 60L * 24L)
+#define NSEC_PER_HOUR (SYSPROF_NSEC_PER_SEC * 60L * 60L)
+#define NSEC_PER_MIN (SYSPROF_NSEC_PER_SEC * 60L)
+#define NSEC_PER_MSEC (SYSPROF_NSEC_PER_SEC/G_GINT64_CONSTANT(1000))
 #define MIN_TICK_DISTANCE 20
 #define LABEL_HEIGHT_PX 10
 
@@ -64,16 +63,16 @@ struct {
   gint height;
   gint64 span;
 } tick_sizing[N_TICKS] = {
-  { 1, 12, NSEC_PER_SEC * 60 },
-  { 1, 11, NSEC_PER_SEC * 30 },
-  { 1, 10, NSEC_PER_SEC * 5 },
-  { 1, 9, NSEC_PER_SEC },
-  { 1, 8, NSEC_PER_SEC / 2 },
-  { 1, 6, NSEC_PER_SEC / 4 },
-  { 1, 5, NSEC_PER_SEC / 10 },
-  { 1, 4, NSEC_PER_SEC / 100 },
-  { 1, 3, NSEC_PER_SEC / 1000 },
-  { 1, 1, NSEC_PER_SEC / 10000 },
+  { 1, 12, SYSPROF_NSEC_PER_SEC * 60 },
+  { 1, 11, SYSPROF_NSEC_PER_SEC * 30 },
+  { 1, 10, SYSPROF_NSEC_PER_SEC * 5 },
+  { 1, 9, SYSPROF_NSEC_PER_SEC },
+  { 1, 8, SYSPROF_NSEC_PER_SEC / 2 },
+  { 1, 6, SYSPROF_NSEC_PER_SEC / 4 },
+  { 1, 5, SYSPROF_NSEC_PER_SEC / 10 },
+  { 1, 4, SYSPROF_NSEC_PER_SEC / 100 },
+  { 1, 3, SYSPROF_NSEC_PER_SEC / 1000 },
+  { 1, 1, SYSPROF_NSEC_PER_SEC / 10000 },
 };
 
 G_DEFINE_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, GTK_TYPE_DRAWING_AREA)
@@ -93,7 +92,7 @@ update_label_text (PangoLayout *layout,
 
   g_assert (PANGO_IS_LAYOUT (layout));
 
-  tmp = time % NSEC_PER_SEC;
+  tmp = time % SYSPROF_NSEC_PER_SEC;
   time -= tmp;
   msec = tmp / 100000L;
 
@@ -115,10 +114,10 @@ update_label_text (PangoLayout *layout,
       time %= NSEC_PER_MIN;
     }
 
-  if (time >= NSEC_PER_SEC)
+  if (time >= SYSPROF_NSEC_PER_SEC)
     {
-      sec = time / NSEC_PER_SEC;
-      time %= NSEC_PER_SEC;
+      sec = time / SYSPROF_NSEC_PER_SEC;
+      time %= SYSPROF_NSEC_PER_SEC;
     }
 
   if (want_msec || (!hours && !min && !sec && msec))
@@ -204,7 +203,7 @@ draw_ticks (SysprofVisualizerTicks *self,
       /* If we are operating on smaller than seconds here, then we want
        * to ensure we include msec with the timestamps.
        */
-      want_msec = tick_sizing[ticks].span < NSEC_PER_SEC;
+      want_msec = tick_sizing[ticks].span < SYSPROF_NSEC_PER_SEC;
 
       for (gint64 t = self->begin_time - x_offset;
            t <= self->end_time;
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.c b/src/libsysprof-ui/sysprof-zoom-manager.c
index 25df51f..b636b32 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.c
+++ b/src/libsysprof-ui/sysprof-zoom-manager.c
@@ -25,11 +25,11 @@
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 #include <math.h>
+#include <sysprof-capture.h>
 
 #include "sysprof-zoom-manager.h"
 
 #define DEFAULT_PIXELS_PER_SEC (20.0)
-#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
 
 struct _SysprofZoomManager
 {
@@ -584,7 +584,7 @@ sysprof_zoom_manager_get_duration_for_width (SysprofZoomManager *self,
 {
   g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0);
 
-  return NSEC_PER_SEC * ((gdouble)width / (DEFAULT_PIXELS_PER_SEC * self->zoom));
+  return SYSPROF_NSEC_PER_SEC * ((gdouble)width / (DEFAULT_PIXELS_PER_SEC * self->zoom));
 }
 
 gint
@@ -593,7 +593,7 @@ sysprof_zoom_manager_get_width_for_duration (SysprofZoomManager *self,
 {
   g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0);
 
-  return (gdouble)duration / (gdouble)NSEC_PER_SEC * DEFAULT_PIXELS_PER_SEC * self->zoom;
+  return (gdouble)duration / (gdouble)SYSPROF_NSEC_PER_SEC * DEFAULT_PIXELS_PER_SEC * self->zoom;
 }
 
 gdouble
@@ -605,7 +605,7 @@ sysprof_zoom_manager_fit_zoom_for_duration (SysprofZoomManager *self,
   g_return_val_if_fail (duration >= 0, 1.0);
   g_return_val_if_fail (width >= 0, 1.0);
 
-  return (width / DEFAULT_PIXELS_PER_SEC) / (duration / (gdouble)NSEC_PER_SEC);
+  return (width / DEFAULT_PIXELS_PER_SEC) / (duration / (gdouble)SYSPROF_NSEC_PER_SEC);
 }
 
 gdouble
@@ -633,14 +633,14 @@ _sysprof_format_duration (gint64 duration)
 
   duration = ABS (duration);
 
-  if (duration < NSEC_PER_SEC)
+  if (duration < SYSPROF_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));
+                            (duration / (gdouble)SYSPROF_NSEC_PER_SEC));
 }
 
 /**
diff --git a/src/tools/sysprof-dump.c b/src/tools/sysprof-dump.c
index 719e38c..f93a177 100644
--- a/src/tools/sysprof-dump.c
+++ b/src/tools/sysprof-dump.c
@@ -24,8 +24,6 @@
 #include <stdlib.h>
 #include <sysprof-capture.h>
 
-#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
-
 static gboolean list_files = FALSE;
 static const GOptionEntry main_entries[] = {
   { "list-files", 'l', 0, G_OPTION_ARG_NONE, &list_files, "List files within the capture" },
@@ -86,7 +84,7 @@ main (gint argc,
   end_time = sysprof_capture_reader_get_end_time (reader);
 
   g_print ("Capture Time Range: %"G_GUINT64_FORMAT" to %"G_GUINT64_FORMAT" (%lf)\n",
-           begin_time, end_time, (end_time - begin_time) / (gdouble)NSEC_PER_SEC);
+           begin_time, end_time, (end_time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC);
 
   while (sysprof_capture_reader_peek_type (reader, &type))
     {
@@ -138,7 +136,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_LOG:
           {
             const SysprofCaptureLog *log = sysprof_capture_reader_read_log (reader);
-            gdouble ptime = (log->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (log->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
 
             g_print ("LOG: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n"
                      " severity = %d\n"
@@ -169,7 +167,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_FILE_CHUNK:
           {
             const SysprofCaptureFileChunk *file_chunk = sysprof_capture_reader_read_file (reader);
-            gdouble ptime = (file_chunk->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (file_chunk->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
 
             g_print ("FILE_CHUNK: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n"
                      "     path = %s\n"
@@ -184,7 +182,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_MARK:
           {
             const SysprofCaptureMark *mark = sysprof_capture_reader_read_mark (reader);
-            gdouble ptime = (mark->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (mark->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
 
             g_print ("MARK: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n"
                      "    group = %s\n"
@@ -200,7 +198,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_METADATA:
           {
             const SysprofCaptureMetadata *metadata = sysprof_capture_reader_read_metadata (reader);
-            gdouble ptime = (metadata->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (metadata->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
 
             g_print ("METADATA: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n"
                      "       id = %s\n"
@@ -226,7 +224,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_SAMPLE:
           {
             const SysprofCaptureSample *s =  sysprof_capture_reader_read_sample (reader);
-            gdouble ptime = (s->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (s->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
             guint i;
 
             g_print ("SAMPLE: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n", s->frame.pid, s->frame.time, ptime);
@@ -247,7 +245,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_CTRDEF:
           {
             const SysprofCaptureCounterDefine *def = sysprof_capture_reader_read_counter_define (reader);
-            gdouble ptime = (def->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (def->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
             guint i;
 
             g_print ("NEW COUNTERS: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n", def->frame.pid, 
def->frame.time, ptime);
@@ -273,7 +271,7 @@ main (gint argc,
         case SYSPROF_CAPTURE_FRAME_CTRSET:
           {
             const SysprofCaptureCounterSet *set = sysprof_capture_reader_read_counter_set (reader);
-            gdouble ptime = (set->frame.time - begin_time) / (gdouble)NSEC_PER_SEC;
+            gdouble ptime = (set->frame.time - begin_time) / (gdouble)SYSPROF_NSEC_PER_SEC;
             guint i;
 
             g_print ("SET COUNTERS: pid=%d time=%"G_GINT64_FORMAT" (%lf)\n", set->frame.pid, 
set->frame.time, ptime);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]