diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-30 12:26:40 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-30 12:26:40 +0300 |
commit | fbc8bdac6efb0c63a73c5105bbf4ecb304187e44 (patch) | |
tree | fa5116b264d2880841044f5aa18542c465f7f97b | |
parent | 5a1f674eecba607ffa328484ca34c598690ff8d2 (diff) | |
download | tagr-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.c | 14 | ||||
-rw-r--r-- | src/grid.c | 30 | ||||
-rw-r--r-- | src/output.c | 5 | ||||
-rw-r--r-- | src/readconfig.c | 7 | ||||
-rw-r--r-- | src/tagr.h | 10 |
5 files changed, 34 insertions, 32 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, | |||
89 | int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1]; | 89 | int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1]; |
90 | int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; | 90 | int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; |
91 | grid_t grid; | 91 | grid_t grid; |
92 | unsigned long ymax = mon->max_rate; | 92 | double ymax = mon->max_rate; |
93 | 93 | ||
94 | yscale = (double) graph_ysize / ymax; | 94 | yscale = (double) graph_ysize / ymax; |
95 | xscale = (double) graph_xsize / xmax; | 95 | xscale = (double) graph_xsize / xmax; |
@@ -210,16 +210,16 @@ draw_graph (FILE *fp, | |||
210 | grid = grid_create (ygrid, dataq, 0, ymax, mon); | 210 | grid = grid_create (ygrid, dataq, 0, ymax, mon); |
211 | if (grid) | 211 | if (grid) |
212 | { | 212 | { |
213 | unsigned long i; | 213 | double d; |
214 | char *str = NULL; | 214 | char *str = NULL; |
215 | 215 | ||
216 | draw_vtext (graph, i_grid, | 216 | draw_vtext (graph, i_grid, |
217 | mon->rate_unit ? mon->rate_unit : rate_unit); | 217 | mon->rate_unit ? mon->rate_unit : rate_unit); |
218 | 218 | ||
219 | /* Draw vertical grid */ | 219 | /* Draw vertical grid */ |
220 | while ((i = grid_next (grid, &str, NULL)) < ymax) | 220 | while ((d = grid_next (grid, &str, NULL)) < ymax) |
221 | { | 221 | { |
222 | int y = ytr (i); | 222 | int y = ytr (d); |
223 | 223 | ||
224 | /* Left tick */ | 224 | /* Left tick */ |
225 | gdImageLine (graph, | 225 | gdImageLine (graph, |
@@ -247,13 +247,13 @@ draw_graph (FILE *fp, | |||
247 | grid = grid_create (xgrid, dataq, 0, xmax, &start); | 247 | grid = grid_create (xgrid, dataq, 0, xmax, &start); |
248 | if (grid) | 248 | if (grid) |
249 | { | 249 | { |
250 | unsigned long i; | 250 | double d; |
251 | char *str = NULL; | 251 | char *str = NULL; |
252 | int mark; | 252 | int mark; |
253 | 253 | ||
254 | while ((i = grid_next (grid, &str, &mark)) < xmax) | 254 | while ((d = grid_next (grid, &str, &mark)) < xmax) |
255 | { | 255 | { |
256 | int x = xtr (i); | 256 | int x = xtr (d); |
257 | 257 | ||
258 | /* Tick */ | 258 | /* Tick */ |
259 | gdImageLine (graph, | 259 | gdImageLine (graph, |
@@ -25,16 +25,16 @@ struct grid | |||
25 | { | 25 | { |
26 | struct grid_class *class; | 26 | struct grid_class *class; |
27 | queue_t *q; | 27 | queue_t *q; |
28 | unsigned long vmin; | 28 | double vmin; |
29 | unsigned long vmax; | 29 | double vmax; |
30 | unsigned long cur; | 30 | double cur; |
31 | char *str; | 31 | char *str; |
32 | void *data; | 32 | void *data; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | grid_t | 35 | grid_t |
36 | grid_create (struct grid_class *class, queue_t *q, | 36 | grid_create (struct grid_class *class, queue_t *q, |
37 | unsigned long vmin, unsigned long vmax, void *cdata) | 37 | double vmin, double vmax, void *cdata) |
38 | { | 38 | { |
39 | grid_t grid; | 39 | grid_t grid; |
40 | 40 | ||
@@ -54,7 +54,7 @@ grid_create (struct grid_class *class, queue_t *q, | |||
54 | return grid; | 54 | return grid; |
55 | } | 55 | } |
56 | 56 | ||
57 | unsigned long | 57 | double |
58 | grid_next (grid_t grid, char **str, int *mark) | 58 | grid_next (grid_t grid, char **str, int *mark) |
59 | { | 59 | { |
60 | return grid->class->next (grid, str, mark); | 60 | return grid->class->next (grid, str, mark); |
@@ -87,7 +87,7 @@ size_t number_suffix_count = sizeof (short_suffix) / sizeof (short_suffix[0]); | |||
87 | 87 | ||
88 | struct ygrid_data | 88 | struct ygrid_data |
89 | { | 89 | { |
90 | unsigned long step; | 90 | double step; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | static void * | 93 | static void * |
@@ -99,7 +99,7 @@ ygrid_create (grid_t grid, void *cdata) | |||
99 | return gr; | 99 | return gr; |
100 | } | 100 | } |
101 | 101 | ||
102 | static unsigned long | 102 | static double |
103 | ygrid_next (grid_t grid, char **str, int *mark) | 103 | ygrid_next (grid_t grid, char **str, int *mark) |
104 | { | 104 | { |
105 | struct ygrid_data *gr = grid->data; | 105 | struct ygrid_data *gr = grid->data; |
@@ -154,11 +154,11 @@ xgrid_2h_create (grid_t grid, void *cdata) | |||
154 | return gr; | 154 | return gr; |
155 | } | 155 | } |
156 | 156 | ||
157 | static unsigned long | 157 | static double |
158 | xgrid_2h_next (grid_t grid, char **str, int *mark) | 158 | xgrid_2h_next (grid_t grid, char **str, int *mark) |
159 | { | 159 | { |
160 | struct xgrid_data *gr = grid->data; | 160 | struct xgrid_data *gr = grid->data; |
161 | unsigned long ret = gr->off; | 161 | double ret = gr->off; |
162 | 162 | ||
163 | if (grid->str) | 163 | if (grid->str) |
164 | { | 164 | { |
@@ -200,11 +200,11 @@ xgrid_wday_create (grid_t grid, void *cdata) | |||
200 | return gr; | 200 | return gr; |
201 | } | 201 | } |
202 | 202 | ||
203 | static unsigned long | 203 | static double |
204 | xgrid_wday_next (grid_t grid, char **str, int *mark) | 204 | xgrid_wday_next (grid_t grid, char **str, int *mark) |
205 | { | 205 | { |
206 | struct xgrid_data *gr = grid->data; | 206 | struct xgrid_data *gr = grid->data; |
207 | unsigned long ret = gr->off; | 207 | double ret = gr->off; |
208 | char buf[80]; | 208 | char buf[80]; |
209 | struct tm *tm = localtime (&gr->start); | 209 | struct tm *tm = localtime (&gr->start); |
210 | 210 | ||
@@ -250,11 +250,11 @@ xgrid_week_create (grid_t grid, void *cdata) | |||
250 | return gr; | 250 | return gr; |
251 | } | 251 | } |
252 | 252 | ||
253 | static unsigned long | 253 | static double |
254 | xgrid_week_next (grid_t grid, char **str, int *mark) | 254 | xgrid_week_next (grid_t grid, char **str, int *mark) |
255 | { | 255 | { |
256 | struct xgrid_data *gr = grid->data; | 256 | struct xgrid_data *gr = grid->data; |
257 | unsigned long ret = gr->off; | 257 | double ret = gr->off; |
258 | struct tm *tm = localtime (&gr->start); | 258 | struct tm *tm = localtime (&gr->start); |
259 | 259 | ||
260 | if (tm->tm_mday && tm->tm_mday < 7 && mark && gr->unit == 0) | 260 | if (tm->tm_mday && tm->tm_mday < 7 && mark && gr->unit == 0) |
@@ -307,11 +307,11 @@ xgrid_month_create (grid_t grid, void *cdata) | |||
307 | return gr; | 307 | return gr; |
308 | } | 308 | } |
309 | 309 | ||
310 | static unsigned long | 310 | static double |
311 | xgrid_month_next (grid_t grid, char **str, int *mark) | 311 | xgrid_month_next (grid_t grid, char **str, int *mark) |
312 | { | 312 | { |
313 | struct xgrid_data *gr = grid->data; | 313 | struct xgrid_data *gr = grid->data; |
314 | unsigned long ret = gr->off; | 314 | double ret = gr->off; |
315 | unsigned long frac; | 315 | unsigned long frac; |
316 | struct tm *tm = localtime (&gr->start); | 316 | struct tm *tm = localtime (&gr->start); |
317 | int mon; | 317 | 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,8 +114,8 @@ add_stats (pp_tab_t **ptab, struct monitor *mon, queue_t *q, | |||
114 | int i, n = queue_count (q); | 114 | int i, n = queue_count (q); |
115 | struct traffic_history *tptr, th; | 115 | struct traffic_history *tptr, th; |
116 | 116 | ||
117 | if (!n) | 117 | if (n) |
118 | return; | 118 | { |
119 | for (i = 0; i < n; i++) | 119 | for (i = 0; i < n; i++) |
120 | { | 120 | { |
121 | tptr = queue_get_ptr (q, i); | 121 | tptr = queue_get_ptr (q, i); |
@@ -136,6 +136,7 @@ add_stats (pp_tab_t **ptab, struct monitor *mon, queue_t *q, | |||
136 | scale_sample (mon, tptr, &th); | 136 | scale_sample (mon, tptr, &th); |
137 | val[curin_name] = th.inrate; | 137 | val[curin_name] = th.inrate; |
138 | val[curout_name] = th.outrate; | 138 | val[curout_name] = th.outrate; |
139 | } | ||
139 | 140 | ||
140 | for (i = 0; i < sizeof (val) / sizeof (val[0]); i++) | 141 | for (i = 0; i < sizeof (val) / sizeof (val[0]); i++) |
141 | add_numeric_value (ptab, symname[i], val[i]); | 142 | 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, | |||
100 | mon = xzalloc (sizeof (*mon)); | 100 | mon = xzalloc (sizeof (*mon)); |
101 | mon->id = strdup (value->v.string); | 101 | mon->id = strdup (value->v.string); |
102 | mon->scale = 1.0; | 102 | mon->scale = 1.0; |
103 | mon->ystep = 100; | 103 | mon->ystep = 100.; |
104 | *pdata = mon; | 104 | *pdata = mon; |
105 | break; | 105 | break; |
106 | 106 | ||
@@ -179,8 +179,9 @@ static struct grecs_keyword monitor_kw[] = { | |||
179 | { "scale", N_("arg: double"), N_("Scaling factor"), | 179 | { "scale", N_("arg: double"), N_("Scaling factor"), |
180 | grecs_type_string, NULL, offsetof(struct monitor, scale), | 180 | grecs_type_string, NULL, offsetof(struct monitor, scale), |
181 | cb_double }, | 181 | cb_double }, |
182 | { "y-step", NULL, N_("Step for Y axis"), | 182 | { "y-step", N_("arg: double"), N_("Step for Y axis"), |
183 | grecs_type_ulong, NULL, offsetof(struct monitor, ystep) }, | 183 | grecs_type_string, NULL, offsetof(struct monitor, ystep), |
184 | cb_double}, | ||
184 | { "swap", NULL, N_("Swap in and out rates"), | 185 | { "swap", NULL, N_("Swap in and out rates"), |
185 | grecs_type_bool, NULL, offsetof(struct monitor, swap) }, | 186 | grecs_type_bool, NULL, offsetof(struct monitor, swap) }, |
186 | { NULL } |