/* darkstat 3
- * copyright (c) 2006-2011 Emil Mikulic.
+ * copyright (c) 2006-2014 Emil Mikulic.
*
* graph_db.c: round robin database for graph data
*
};
static unsigned int graph_db_size = sizeof(graph_db)/sizeof(*graph_db);
-static long start_mono, start_real, last_real;
+static time_t start_mono, start_real, last_real;
void graph_init(void) {
unsigned int i;
graph_db[i]->in = xmalloc(sizeof(uint64_t) * graph_db[i]->num_bars);
graph_db[i]->out = xmalloc(sizeof(uint64_t) * graph_db[i]->num_bars);
}
- start_mono = now_mono();
- start_real = now_real();
graph_reset();
}
for (i=0; i<graph_db_size; i++)
zero_graph(graph_db[i]);
+
+ /* Reset starting time. */
+ start_mono = now_mono();
+ start_real = now_real();
last_real = 0;
+
+ /* Clear counters. */
+ acct_total_bytes = 0;
+ acct_total_packets = 0;
}
void graph_free(void) {
memcpy(g->out, tmp, size);
free(tmp);
+ assert(g->num_bars > 0);
assert(pos == ( (g->pos + ofs) % g->num_bars ));
g->pos = pos;
}
}
void graph_rotate(void) {
- long t, td;
+ time_t t, td;
struct tm *tm;
unsigned int i;
struct str *buf, *rf;
unsigned int i;
char start_when[100];
- long d_real, d_mono;
+ time_t d_real, d_mono;
buf = str_make();
html_open(buf, "Graphs", /*path_depth=*/0, /*want_graph_js=*/1);
d_mono = now_mono() - start_mono;
d_real = now_real() - start_real;
str_append(buf, "<p>\n");
- str_append(buf, "<b>Running for</b> <span id=\"rf\">");
+ str_append(buf, "<b>Measuring for</b> <span id=\"rf\">");
rf = length_of_time(d_mono);
str_appendstr(buf, rf);
str_free(rf);
str_append(buf, "</span>");
- if (abs(d_real - d_mono) > 1)
+ if (labs((long)(d_real - d_mono)) > 1)
str_appendf(buf, " (real time is off by %qd sec)",
- (int64_t)d_real - (int64_t)d_mono);
+ (qd)(d_real - d_mono));
if (strftime(start_when, sizeof(start_when),
"%Y-%m-%d %H:%M:%S %Z%z", localtime(&start_real)) != 0)
str_appendf(buf, "<b>, since</b> %s", start_when);
str_appendf(buf,"<b>.</b><br>\n"
- "<b>Total</b> <span id=\"tb\">%'qu</span> <b>bytes, "
+ "<b>Seen</b> <span id=\"tb\">%'qu</span> <b>bytes, "
"in</b> <span id=\"tp\">%'qu</span> <b>packets.</b> "
"(<span id=\"pc\">%'u</span> <b>captured,</b> "
"<span id=\"pd\">%'u</span> <b>dropped)</b><br>\n"
"</p>\n",
- acct_total_bytes,
- acct_total_packets,
- cap_pkts_recv, cap_pkts_drop);
+ (qu)acct_total_bytes,
+ (qu)acct_total_packets,
+ cap_pkts_recv,
+ cap_pkts_drop);
str_append(buf,
"<div id=\"graphs\">\n"
struct str *buf = str_make(), *rf;
str_appendf(buf, "<graphs tp=\"%qu\" tb=\"%qu\" pc=\"%u\" pd=\"%u\" rf=\"",
- acct_total_packets, acct_total_bytes, cap_pkts_recv, cap_pkts_drop);
+ (qu)acct_total_packets,
+ (qu)acct_total_bytes,
+ cap_pkts_recv,
+ cap_pkts_drop);
rf = length_of_time(now_real() - start_real);
str_appendstr(buf, rf);
str_free(rf);
j = (j + 1) % g->num_bars;
/* <element pos="" in="" out=""/> */
str_appendf(buf, "<e p=\"%u\" i=\"%qu\" o=\"%qu\"/>\n",
- g->offset + j, g->in[j], g->out[j]);
+ g->offset + j,
+ (qu)g->in[j],
+ (qu)g->out[j]);
} while (j != g->pos);
str_appendf(buf, "</%s>\n", g->unit);
}