net: stats: Simplify periodic statistics printing
Use modular arithmetic in statistics prints so that wraparounds are automatically handled. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
af34779510
commit
fbbef6f436
@ -12,6 +12,7 @@
|
||||
|
||||
#include <kernel.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <net/net_core.h>
|
||||
|
||||
@ -54,16 +55,19 @@ static const char *priority2str(enum net_priority priority)
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline s64_t cmp_val(u64_t val1, u64_t val2)
|
||||
{
|
||||
return (s64_t)(val1 - val2);
|
||||
}
|
||||
|
||||
static inline void stats(struct net_if *iface)
|
||||
{
|
||||
static s64_t next_print;
|
||||
s64_t curr = k_uptime_get();
|
||||
static u64_t next_print;
|
||||
u64_t curr = k_uptime_get();
|
||||
s64_t cmp = cmp_val(curr, next_print);
|
||||
int i;
|
||||
|
||||
if (!next_print || (next_print < curr &&
|
||||
(!((curr - next_print) > PRINT_STATISTICS_INTERVAL)))) {
|
||||
s64_t new_print;
|
||||
|
||||
if (!next_print || (abs(cmp) > PRINT_STATISTICS_INTERVAL)) {
|
||||
if (iface) {
|
||||
NET_INFO("Interface %p [%d]", iface,
|
||||
net_if_get_by_iface(iface));
|
||||
@ -217,14 +221,7 @@ static inline void stats(struct net_if *iface)
|
||||
ARG_UNUSED(i);
|
||||
#endif /* NET_TC_COUNT > 1 */
|
||||
|
||||
new_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||
if (new_print > curr) {
|
||||
next_print = new_print;
|
||||
} else {
|
||||
/* Overflow */
|
||||
next_print = PRINT_STATISTICS_INTERVAL -
|
||||
(LLONG_MAX - curr);
|
||||
}
|
||||
next_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user