libsysprof-analyze: use doubles for reference data

We only want to move to float for the internal 0..1 positions which are
used to draw to the screen (to reduce how much data we hold on to). But for
the data we need to calculate those 0..1 positions, we want better
precision for large numbers. Use double for all of those.
This commit is contained in:
Christian Hergert
2023-06-20 11:48:51 -07:00
parent 72d489f786
commit d0d19cff39
3 changed files with 33 additions and 28 deletions

View File

@ -17,8 +17,11 @@
* *
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
#include "config.h" #include "config.h"
#include <math.h>
#include "sysprof-xy-series.h" #include "sysprof-xy-series.h"
struct _SysprofXYSeries struct _SysprofXYSeries
@ -30,14 +33,14 @@ struct _SysprofXYSeries
GArray *values; GArray *values;
/* Our bounds for non-normalized values */ /* Our bounds for non-normalized values */
float min_x; double min_x;
float min_y; double min_y;
float max_x; double max_x;
float max_y; double max_y;
/* Pre-calculated distance between min/max */ /* Pre-calculated distance between min/max */
float x_distance; double x_distance;
float y_distance; double y_distance;
/* Used for warning on items-changed */ /* Used for warning on items-changed */
gulong items_changed_handler; gulong items_changed_handler;
@ -73,10 +76,10 @@ warn_on_items_changed_cb (GListModel *model,
*/ */
SysprofXYSeries * SysprofXYSeries *
sysprof_xy_series_new (GListModel *model, sysprof_xy_series_new (GListModel *model,
float min_x, double min_x,
float min_y, double min_y,
float max_x, double max_x,
float max_y) double max_y)
{ {
SysprofXYSeries *self; SysprofXYSeries *self;
@ -89,6 +92,8 @@ sysprof_xy_series_new (GListModel *model,
self->min_y = min_y; self->min_y = min_y;
self->max_x = max_x; self->max_x = max_x;
self->max_y = max_y; self->max_y = max_y;
self->x_distance = max_x - min_x;
self->y_distance = max_y - min_y;
self->items_changed_handler = self->items_changed_handler =
g_signal_connect (self->model, g_signal_connect (self->model,
"items-changed", "items-changed",
@ -121,8 +126,8 @@ sysprof_xy_series_unref (SysprofXYSeries *self)
void void
sysprof_xy_series_add (SysprofXYSeries *self, sysprof_xy_series_add (SysprofXYSeries *self,
float x, double x,
float y, double y,
guint index) guint index)
{ {
SysprofXYSeriesValue value; SysprofXYSeriesValue value;
@ -158,7 +163,7 @@ sysprof_xy_series_get_model (SysprofXYSeries *self)
const SysprofXYSeriesValue * const SysprofXYSeriesValue *
sysprof_xy_series_get_values (const SysprofXYSeries *self, sysprof_xy_series_get_values (const SysprofXYSeries *self,
guint *n_values) guint *n_values)
{ {
*n_values = self->values->len; *n_values = self->values->len;
return &g_array_index (self->values, SysprofXYSeriesValue, 0); return &g_array_index (self->values, SysprofXYSeriesValue, 0);
@ -195,10 +200,10 @@ sysprof_xy_series_sort (SysprofXYSeries *self)
void void
sysprof_xy_series_get_range (SysprofXYSeries *self, sysprof_xy_series_get_range (SysprofXYSeries *self,
float *min_x, double *min_x,
float *min_y, double *min_y,
float *max_x, double *max_x,
float *max_y) double *max_y)
{ {
g_return_if_fail (self != NULL); g_return_if_fail (self != NULL);

View File

@ -42,18 +42,18 @@ SYSPROF_AVAILABLE_IN_ALL
GType sysprof_xy_series_get_type (void) G_GNUC_CONST; GType sysprof_xy_series_get_type (void) G_GNUC_CONST;
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofXYSeries *sysprof_xy_series_new (GListModel *model, SysprofXYSeries *sysprof_xy_series_new (GListModel *model,
float min_x, double min_x,
float min_y, double min_y,
float max_x, double max_x,
float max_y); double max_y);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
SysprofXYSeries *sysprof_xy_series_ref (SysprofXYSeries *self); SysprofXYSeries *sysprof_xy_series_ref (SysprofXYSeries *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_xy_series_unref (SysprofXYSeries *self); void sysprof_xy_series_unref (SysprofXYSeries *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_xy_series_add (SysprofXYSeries *self, void sysprof_xy_series_add (SysprofXYSeries *self,
float x, double x,
float y, double y,
guint index); guint index);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_xy_series_sort (SysprofXYSeries *self); void sysprof_xy_series_sort (SysprofXYSeries *self);
@ -64,10 +64,10 @@ const SysprofXYSeriesValue *sysprof_xy_series_get_values (const SysprofXYSeries
guint *n_values); guint *n_values);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
void sysprof_xy_series_get_range (SysprofXYSeries *self, void sysprof_xy_series_get_range (SysprofXYSeries *self,
float *min_x, double *min_x,
float *min_y, double *min_y,
float *max_x, double *max_x,
float *max_y); double *max_y);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofXYSeries, sysprof_xy_series_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofXYSeries, sysprof_xy_series_unref)

View File

@ -47,7 +47,7 @@ sysprof_depth_layer_snapshot (GtkWidget *widget,
SysprofDepthLayer *self = (SysprofDepthLayer *)widget; SysprofDepthLayer *self = (SysprofDepthLayer *)widget;
const SysprofXYSeriesValue *values; const SysprofXYSeriesValue *values;
guint n_values; guint n_values;
float min_x, max_x; double min_x, max_x;
int line_width; int line_width;
int width; int width;
int height; int height;