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.
This commit is contained in:
Christian Hergert
2019-07-18 10:22:46 -07:00
parent 991e03ba67
commit c2728b8ada
9 changed files with 42 additions and 53 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -24,8 +24,6 @@
#include "sysprof-time-label.h"
#define NSEC_PER_SEC (G_USEC_PER_SEC * 1000L)
struct _SysprofTimeLabel
{
GtkBox parent;

View File

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

View File

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