Fix stats counting overflow.

This commit is contained in:
Ian Gulliver
2016-02-23 16:30:30 -08:00
parent 819518e402
commit a33808cb33
2 changed files with 6 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ struct packet {
PACKET_TYPE_MODE_S_SHORT, PACKET_TYPE_MODE_S_SHORT,
PACKET_TYPE_MODE_S_LONG, PACKET_TYPE_MODE_S_LONG,
} type; } type;
#define NUM_TYPES 2 #define NUM_TYPES 3
uint8_t payload[PACKET_DATA_LEN_MAX]; uint8_t payload[PACKET_DATA_LEN_MAX];
uint64_t mlat_timestamp; uint64_t mlat_timestamp;
uint32_t rssi; uint32_t rssi;

View File

@@ -15,7 +15,7 @@ static struct stats_state {
} stats_state = { 0 }; } stats_state = { 0 };
void stats_init() { void stats_init() {
assert(clock_gettime(CLOCK_MONOTONIC, &stats_state.start) == 0); assert(!clock_gettime(CLOCK_MONOTONIC_COARSE, &stats_state.start));
} }
void stats_serialize(struct packet *packet, struct buf *buf) { void stats_serialize(struct packet *packet, struct buf *buf) {
@@ -28,10 +28,13 @@ void stats_serialize(struct packet *packet, struct buf *buf) {
} }
json_t *counts = json_object(); json_t *counts = json_object();
for (int i = 0; i < NUM_TYPES; i++) { for (int i = 0; i < NUM_TYPES; i++) {
if (i == PACKET_TYPE_NONE) {
continue;
}
json_object_set_new(counts, packet_type_names[i], json_integer(stats_state.type_count[i])); json_object_set_new(counts, packet_type_names[i], json_integer(stats_state.type_count[i]));
} }
struct timespec now; struct timespec now;
assert(clock_gettime(CLOCK_MONOTONIC_COARSE, &now) == 0); assert(!clock_gettime(CLOCK_MONOTONIC_COARSE, &now));
json_t *out = json_pack("{sIso}", json_t *out = json_pack("{sIso}",
"uptime_seconds", (json_int_t) (now.tv_sec - stats_state.start.tv_sec), "uptime_seconds", (json_int_t) (now.tv_sec - stats_state.start.tv_sec),
"packet_counts", counts); "packet_counts", counts);