// Struct to collect server statistics
struct fireperf_server_stats {
+ struct timespec last_printed;
+
// Total number of open connections
unsigned int connections;
};
return NULL;
}
-static int dump_stats(struct fireperf_config* conf, const struct fireperf_server_stats* stats) {
+static unsigned long timespec_delta(struct timespec* t1, struct timespec* t2) {
+ // Compute delta in milliseconds
+ return (
+ ((t1->tv_sec * 1000) + (t1->tv_nsec / 1000000))
+ -
+ ((t2->tv_sec * 1000) + (t2->tv_nsec / 1000000))
+ ) / 1000.0;
+}
+
+static int dump_stats(struct fireperf_config* conf, struct fireperf_server_stats* stats) {
struct timespec now;
// Fetch the time
return 1;
}
+ double delta = timespec_delta(&now, &stats->last_printed);
+
// Format timestamp
const char* timestamp = format_timespec(&now);
- INFO(conf, "--- %s --------------------\n", timestamp);
- INFO(conf, " %-20s: %20u\n", "Open Connection(s)", stats->connections);
+ INFO( conf, "--- %s --------------------\n", timestamp);
+ DEBUG(conf, " %-20s: %19.4fs\n", "Delta", delta);
+ INFO( conf, " %-20s: %20u\n", "Open Connection(s)", stats->connections);
+
+ // Remember when this was printed last
+ stats->last_printed = now;
return 0;
}