aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-30 12:26:40 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-04-30 12:26:40 +0300
commitfbc8bdac6efb0c63a73c5105bbf4ecb304187e44 (patch)
treefa5116b264d2880841044f5aa18542c465f7f97b
parent5a1f674eecba607ffa328484ca34c598690ff8d2 (diff)
downloadtagr-fbc8bdac6efb0c63a73c5105bbf4ecb304187e44.tar.gz
tagr-fbc8bdac6efb0c63a73c5105bbf4ecb304187e44.tar.bz2
Grid step is double-precision.
* src/grid.c (struct grid): vmin, vmax and cur are double. All uses updated. * src/output.c (add_stats): Add zero stats if the queue is empty. * src/readconfig.c: The argument to y-step is double. * src/tagr.h (struct monitor.ystep): Change to double. (struct grid_class.next): Return double. (grid_next): Return double. (grid_create): Change proto. * src/graph.c: Update grid_next return values.
-rw-r--r--src/graph.c14
-rw-r--r--src/grid.c30
-rw-r--r--src/output.c41
-rw-r--r--src/readconfig.c7
-rw-r--r--src/tagr.h10
5 files changed, 52 insertions, 50 deletions
diff --git a/src/graph.c b/src/graph.c
index 02e0586..80b2a97 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -89,7 +89,7 @@ draw_graph (FILE *fp,
int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1];
int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1];
grid_t grid;
- unsigned long ymax = mon->max_rate;
+ double ymax = mon->max_rate;
yscale = (double) graph_ysize / ymax;
xscale = (double) graph_xsize / xmax;
@@ -210,16 +210,16 @@ draw_graph (FILE *fp,
grid = grid_create (ygrid, dataq, 0, ymax, mon);
if (grid)
{
- unsigned long i;
+ double d;
char *str = NULL;
draw_vtext (graph, i_grid,
mon->rate_unit ? mon->rate_unit : rate_unit);
/* Draw vertical grid */
- while ((i = grid_next (grid, &str, NULL)) < ymax)
+ while ((d = grid_next (grid, &str, NULL)) < ymax)
{
- int y = ytr (i);
+ int y = ytr (d);
/* Left tick */
gdImageLine (graph,
@@ -247,13 +247,13 @@ draw_graph (FILE *fp,
grid = grid_create (xgrid, dataq, 0, xmax, &start);
if (grid)
{
- unsigned long i;
+ double d;
char *str = NULL;
int mark;
- while ((i = grid_next (grid, &str, &mark)) < xmax)
+ while ((d = grid_next (grid, &str, &mark)) < xmax)
{
- int x = xtr (i);
+ int x = xtr (d);
/* Tick */
gdImageLine (graph,
diff --git a/src/grid.c b/src/grid.c
index 1671753..08e1c08 100644
--- a/src/grid.c
+++ b/src/grid.c
@@ -25,16 +25,16 @@ struct grid
{
struct grid_class *class;
queue_t *q;
- unsigned long vmin;
- unsigned long vmax;
- unsigned long cur;
+ double vmin;
+ double vmax;
+ double cur;
char *str;
void *data;
};
grid_t
grid_create (struct grid_class *class, queue_t *q,
- unsigned long vmin, unsigned long vmax, void *cdata)
+ double vmin, double vmax, void *cdata)
{
grid_t grid;
@@ -54,7 +54,7 @@ grid_create (struct grid_class *class, queue_t *q,
return grid;
}
-unsigned long
+double
grid_next (grid_t grid, char **str, int *mark)
{
return grid->class->next (grid, str, mark);
@@ -87,7 +87,7 @@ size_t number_suffix_count = sizeof (short_suffix) / sizeof (short_suffix[0]);
struct ygrid_data
{
- unsigned long step;
+ double step;
};
static void *
@@ -99,7 +99,7 @@ ygrid_create (grid_t grid, void *cdata)
return gr;
}
-static unsigned long
+static double
ygrid_next (grid_t grid, char **str, int *mark)
{
struct ygrid_data *gr = grid->data;
@@ -154,11 +154,11 @@ xgrid_2h_create (grid_t grid, void *cdata)
return gr;
}
-static unsigned long
+static double
xgrid_2h_next (grid_t grid, char **str, int *mark)
{
struct xgrid_data *gr = grid->data;
- unsigned long ret = gr->off;
+ double ret = gr->off;
if (grid->str)
{
@@ -200,11 +200,11 @@ xgrid_wday_create (grid_t grid, void *cdata)
return gr;
}
-static unsigned long
+static double
xgrid_wday_next (grid_t grid, char **str, int *mark)
{
struct xgrid_data *gr = grid->data;
- unsigned long ret = gr->off;
+ double ret = gr->off;
char buf[80];
struct tm *tm = localtime (&gr->start);
@@ -250,11 +250,11 @@ xgrid_week_create (grid_t grid, void *cdata)
return gr;
}
-static unsigned long
+static double
xgrid_week_next (grid_t grid, char **str, int *mark)
{
struct xgrid_data *gr = grid->data;
- unsigned long ret = gr->off;
+ double ret = gr->off;
struct tm *tm = localtime (&gr->start);
if (tm->tm_mday && tm->tm_mday < 7 && mark && gr->unit == 0)
@@ -307,11 +307,11 @@ xgrid_month_create (grid_t grid, void *cdata)
return gr;
}
-static unsigned long
+static double
xgrid_month_next (grid_t grid, char **str, int *mark)
{
struct xgrid_data *gr = grid->data;
- unsigned long ret = gr->off;
+ double ret = gr->off;
unsigned long frac;
struct tm *tm = localtime (&gr->start);
int mon;
diff --git a/src/output.c b/src/output.c
index e2e8b92..3c266b7 100644
--- a/src/output.c
+++ b/src/output.c
@@ -114,29 +114,30 @@ add_stats (pp_tab_t **ptab, struct monitor *mon, queue_t *q,
int i, n = queue_count (q);
struct traffic_history *tptr, th;
- if (!n)
- return;
- for (i = 0; i < n; i++)
+ if (n)
{
- tptr = queue_get_ptr (q, i);
- scale_sample (mon, tptr, &th);
+ for (i = 0; i < n; i++)
+ {
+ tptr = queue_get_ptr (q, i);
+ scale_sample (mon, tptr, &th);
+
+ val[avgin_name] += th.inrate;
+ if (th.inrate > val[maxin_name])
+ val[maxin_name] = th.inrate;
+
+ val[avgout_name] += th.outrate;
+ if (th.outrate > val[maxout_name])
+ val[maxout_name] = th.outrate;
+ }
+ val[avgin_name] /= n;
+ val[avgout_name] /= n;
- val[avgin_name] += th.inrate;
- if (th.inrate > val[maxin_name])
- val[maxin_name] = th.inrate;
-
- val[avgout_name] += th.outrate;
- if (th.outrate > val[maxout_name])
- val[maxout_name] = th.outrate;
+ tptr = queue_get_tail (q);
+ scale_sample (mon, tptr, &th);
+ val[curin_name] = th.inrate;
+ val[curout_name] = th.outrate;
}
- val[avgin_name] /= n;
- val[avgout_name] /= n;
-
- tptr = queue_get_tail (q);
- scale_sample (mon, tptr, &th);
- val[curin_name] = th.inrate;
- val[curout_name] = th.outrate;
-
+
for (i = 0; i < sizeof (val) / sizeof (val[0]); i++)
add_numeric_value (ptab, symname[i], val[i]);
}
diff --git a/src/readconfig.c b/src/readconfig.c
index a514691..1c22cb1 100644
--- a/src/readconfig.c
+++ b/src/readconfig.c
@@ -100,7 +100,7 @@ cb_monitor (enum grecs_callback_command cmd,
mon = xzalloc (sizeof (*mon));
mon->id = strdup (value->v.string);
mon->scale = 1.0;
- mon->ystep = 100;
+ mon->ystep = 100.;
*pdata = mon;
break;
@@ -179,8 +179,9 @@ static struct grecs_keyword monitor_kw[] = {
{ "scale", N_("arg: double"), N_("Scaling factor"),
grecs_type_string, NULL, offsetof(struct monitor, scale),
cb_double },
- { "y-step", NULL, N_("Step for Y axis"),
- grecs_type_ulong, NULL, offsetof(struct monitor, ystep) },
+ { "y-step", N_("arg: double"), N_("Step for Y axis"),
+ grecs_type_string, NULL, offsetof(struct monitor, ystep),
+ cb_double},
{ "swap", NULL, N_("Swap in and out rates"),
grecs_type_bool, NULL, offsetof(struct monitor, swap) },
{ NULL }
diff --git a/src/tagr.h b/src/tagr.h
index f32b014..5d7c3e0 100644
--- a/src/tagr.h
+++ b/src/tagr.h
@@ -49,7 +49,7 @@ struct monitor
char *rate_unit;
unsigned long max_rate;
double scale;
- unsigned long ystep;
+ double ystep;
int swap;
};
@@ -271,13 +271,13 @@ typedef struct grid *grid_t;
struct grid_class
{
void *(*create) (grid_t, void *);
- unsigned long (*next) (grid_t, char **, int *);
+ double (*next) (grid_t, char **, int *);
void (*dealloc) (void *);
};
-grid_t grid_create (struct grid_class *, queue_t *, unsigned long,
- unsigned long, void *);
-unsigned long grid_next (grid_t, char **, int *);
+grid_t grid_create (struct grid_class *, queue_t *, double,
+ double, void *);
+double grid_next (grid_t, char **, int *);
void grid_destroy (grid_t);
extern struct grid_class grid_class_y;

Return to:

Send suggestions and report system problems to the System administrator.