Merge pull request #316 from simonduq/contrib/log-enabled

Only use LOG_*_ENABLED flags from within C 'if' statements
This commit is contained in:
George Oikonomou 2018-02-25 18:46:30 +00:00 committed by GitHub
commit 7dfb590a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 82 deletions

View File

@ -671,8 +671,8 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
int ext_hdr_len; int ext_hdr_len;
struct uip_udp_hdr *udp_buf; struct uip_udp_hdr *udp_buf;
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
{ uint16_t ndx; uint16_t ndx;
LOG_DBG("before compression (%d): ", UIP_IP_BUF->len[1]); LOG_DBG("before compression (%d): ", UIP_IP_BUF->len[1]);
for(ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) { for(ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) {
uint8_t data = ((uint8_t *) (UIP_IP_BUF))[ndx]; uint8_t data = ((uint8_t *) (UIP_IP_BUF))[ndx];
@ -680,7 +680,6 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
} }
LOG_DBG("\n"); LOG_DBG("\n");
} }
#endif /* LOG_DBG_ENABLED */
hc06_ptr = PACKETBUF_IPHC_BUF + 2; hc06_ptr = PACKETBUF_IPHC_BUF + 2;
/* /*
@ -996,8 +995,8 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
PACKETBUF_IPHC_BUF[0] = iphc0; PACKETBUF_IPHC_BUF[0] = iphc0;
PACKETBUF_IPHC_BUF[1] = iphc1; PACKETBUF_IPHC_BUF[1] = iphc1;
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
{ uint16_t ndx; uint16_t ndx;
LOG_DBG("after compression %d: ", (int)(hc06_ptr - packetbuf_ptr)); LOG_DBG("after compression %d: ", (int)(hc06_ptr - packetbuf_ptr));
for(ndx = 0; ndx < hc06_ptr - packetbuf_ptr; ndx++) { for(ndx = 0; ndx < hc06_ptr - packetbuf_ptr; ndx++) {
uint8_t data = ((uint8_t *) packetbuf_ptr)[ndx]; uint8_t data = ((uint8_t *) packetbuf_ptr)[ndx];
@ -1005,7 +1004,6 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
} }
LOG_DBG("\n"); LOG_DBG("\n");
} }
#endif
packetbuf_hdr_len = hc06_ptr - packetbuf_ptr; packetbuf_hdr_len = hc06_ptr - packetbuf_ptr;
} }
@ -1906,8 +1904,7 @@ input(void)
LOG_INFO("input: IP packet ready (length %d)\n", LOG_INFO("input: IP packet ready (length %d)\n",
uip_len); uip_len);
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
{
uint16_t ndx; uint16_t ndx;
LOG_DBG("after decompression %u:", UIP_IP_BUF->len[1]); LOG_DBG("after decompression %u:", UIP_IP_BUF->len[1]);
for (ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) { for (ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) {
@ -1916,7 +1913,6 @@ input(void)
} }
LOG_DBG("\n"); LOG_DBG("\n");
} }
#endif /* LOG_DBG_ENABLED */
/* if callback is set then set attributes and call */ /* if callback is set then set attributes and call */
if(callback) { if(callback) {

View File

@ -103,7 +103,6 @@ LIST(notificationlist);
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if LOG_DBG_ENABLED
static void static void
assert_nbr_routes_list_sane(void) assert_nbr_routes_list_sane(void)
{ {
@ -131,7 +130,6 @@ assert_nbr_routes_list_sane(void)
} }
#endif /* (UIP_MAX_ROUTES != 0) */ #endif /* (UIP_MAX_ROUTES != 0) */
} }
#endif /* LOG_DBG_ENABLED */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if UIP_DS6_NOTIFICATIONS #if UIP_DS6_NOTIFICATIONS
static void static void
@ -330,9 +328,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
uip_ds6_route_t *r; uip_ds6_route_t *r;
struct uip_ds6_route_neighbor_route *nbrr; struct uip_ds6_route_neighbor_route *nbrr;
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
if(ipaddr == NULL || nexthop == NULL) { if(ipaddr == NULL || nexthop == NULL) {
return NULL; return NULL;
@ -473,9 +471,9 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop); call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_ADD, ipaddr, nexthop);
#endif #endif
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
return r; return r;
#else /* (UIP_MAX_ROUTES != 0) */ #else /* (UIP_MAX_ROUTES != 0) */
@ -489,9 +487,11 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
{ {
#if (UIP_MAX_ROUTES != 0) #if (UIP_MAX_ROUTES != 0)
struct uip_ds6_route_neighbor_route *neighbor_route; struct uip_ds6_route_neighbor_route *neighbor_route;
#if LOG_DBG_ENABLED
if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
if(route != NULL && route->neighbor_routes != NULL) { if(route != NULL && route->neighbor_routes != NULL) {
LOG_INFO("Rm: removing route: "); LOG_INFO("Rm: removing route: ");
@ -541,9 +541,9 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
#endif #endif
} }
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
#endif /* (UIP_MAX_ROUTES != 0) */ #endif /* (UIP_MAX_ROUTES != 0) */
return; return;
@ -553,9 +553,10 @@ uip_ds6_route_rm(uip_ds6_route_t *route)
static void static void
rm_routelist(struct uip_ds6_route_neighbor_routes *routes) rm_routelist(struct uip_ds6_route_neighbor_routes *routes)
{ {
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
if(routes != NULL && routes->route_list != NULL) { if(routes != NULL && routes->route_list != NULL) {
struct uip_ds6_route_neighbor_route *r; struct uip_ds6_route_neighbor_route *r;
r = list_head(routes->route_list); r = list_head(routes->route_list);
@ -565,9 +566,10 @@ rm_routelist(struct uip_ds6_route_neighbor_routes *routes)
} }
nbr_table_remove(nbr_routes, routes); nbr_table_remove(nbr_routes, routes);
} }
#if LOG_DBG_ENABLED
if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -603,9 +605,9 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
{ {
uip_ds6_defrt_t *d; uip_ds6_defrt_t *d;
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
if(ipaddr == NULL) { if(ipaddr == NULL) {
return NULL; return NULL;
@ -643,9 +645,9 @@ uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr); call_route_callback(UIP_DS6_NOTIFICATION_DEFRT_ADD, ipaddr, ipaddr);
#endif #endif
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
return d; return d;
} }
@ -655,9 +657,9 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt)
{ {
uip_ds6_defrt_t *d; uip_ds6_defrt_t *d;
#if LOG_DBG_ENABLED if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane(); assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */ }
/* Make sure that the defrt is in the list before we remove it. */ /* Make sure that the defrt is in the list before we remove it. */
for(d = list_head(defaultrouterlist); for(d = list_head(defaultrouterlist);
@ -675,10 +677,10 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt)
return; return;
} }
} }
#if LOG_DBG_ENABLED
assert_nbr_routes_list_sane();
#endif /* LOG_DBG_ENABLED */
if(LOG_DBG_ENABLED) {
assert_nbr_routes_list_sane();
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
uip_ds6_defrt_t * uip_ds6_defrt_t *

View File

@ -217,13 +217,13 @@ uip_sr_periodic(unsigned seconds)
break; break;
} }
} }
#if LOG_INFO_ENABLED if(LOG_INFO_ENABLED) {
uip_ipaddr_t node_addr; uip_ipaddr_t node_addr;
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, l); NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, l);
LOG_INFO("NS: removing expired node "); LOG_INFO("NS: removing expired node ");
LOG_INFO_6ADDR(&node_addr); LOG_INFO_6ADDR(&node_addr);
LOG_INFO_("\n"); LOG_INFO_("\n");
#endif /* LOG_INFO_ENABLED */ }
/* No child found, deallocate node */ /* No child found, deallocate node */
list_remove(nodelist, l); list_remove(nodelist, l);
memb_free(&nodememb, l); memb_free(&nodememb, l);

View File

@ -185,9 +185,9 @@ rpl_global_repair(const char *str)
if(rpl_dag_root_is_root()) { if(rpl_dag_root_is_root()) {
LOG_WARN("initiating global repair (%s), version %u, rank %u)\n", LOG_WARN("initiating global repair (%s), version %u, rank %u)\n",
str, curr_instance.dag.version, curr_instance.dag.rank); str, curr_instance.dag.version, curr_instance.dag.rank);
#if LOG_INFO_ENABLED if(LOG_INFO_ENABLED) {
rpl_neighbor_print_list("Global repair (before)"); rpl_neighbor_print_list("Global repair (before)");
#endif /* LOG_INFO_ENABLED */ }
/* Initiate global repair */ /* Initiate global repair */
RPL_LOLLIPOP_INCREMENT(curr_instance.dag.version); /* New DAG version */ RPL_LOLLIPOP_INCREMENT(curr_instance.dag.version); /* New DAG version */
@ -202,9 +202,9 @@ global_repair_non_root(rpl_dio_t *dio)
if(!rpl_dag_root_is_root()) { if(!rpl_dag_root_is_root()) {
LOG_WARN("participating in global repair, version %u, rank %u)\n", LOG_WARN("participating in global repair, version %u, rank %u)\n",
curr_instance.dag.version, curr_instance.dag.rank); curr_instance.dag.version, curr_instance.dag.rank);
#if LOG_INFO_ENABLED if(LOG_INFO_ENABLED) {
rpl_neighbor_print_list("Global repair (before)"); rpl_neighbor_print_list("Global repair (before)");
#endif /* LOG_INFO_ENABLED */ }
/* Re-initialize configuration from DIO */ /* Re-initialize configuration from DIO */
init_dag_from_dio(dio); init_dag_from_dio(dio);
rpl_local_repair("Global repair"); rpl_local_repair("Global repair");
@ -325,9 +325,9 @@ rpl_dag_update_state(void)
rpl_timers_schedule_leaving(); rpl_timers_schedule_leaving();
} }
#if LOG_INFO_ENABLED if(LOG_INFO_ENABLED) {
rpl_neighbor_print_list("Parent switch"); rpl_neighbor_print_list("Parent switch");
#endif /* LOG_INFO_ENABLED */ }
} }
} }

View File

@ -65,19 +65,7 @@ static int num_parents; /* all nodes that are possible parents */
static int num_free; static int num_free;
static linkaddr_t *worst_rank_nbr_lladdr; /* lladdr of the the neighbor with the worst rank */ static linkaddr_t *worst_rank_nbr_lladdr; /* lladdr of the the neighbor with the worst rank */
static rpl_rank_t worst_rank; static rpl_rank_t worst_rank;
/*---------------------------------------------------------------------------*/
#if LOG_DBG_ENABLED
/* Print out state periodically */
static void update_state(void);
static struct ctimer periodic_timer;
static int timer_init = 0;
static void
handle_periodic_timer(void *ptr)
{
update_state();
ctimer_restart(&periodic_timer);
}
#endif /* LOG_DBG_ENABLED */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
update_state(void) update_state(void)
@ -87,14 +75,6 @@ update_state(void)
rpl_rank_t nbr_rank; rpl_rank_t nbr_rank;
int num_used = 0; int num_used = 0;
#if LOG_DBG_ENABLED
if(!timer_init) {
timer_init = 1;
ctimer_set(&periodic_timer, 60 * CLOCK_SECOND,
&handle_periodic_timer, NULL);
}
#endif /* LOG_DBG_ENABLED */
worst_rank = 0; worst_rank = 0;
worst_rank_nbr_lladdr = NULL; worst_rank_nbr_lladdr = NULL;
num_parents = 0; num_parents = 0;

View File

@ -514,9 +514,9 @@ handle_periodic_timer(void *ptr)
the meaning of last_advertised_rank changes with time */ the meaning of last_advertised_rank changes with time */
rpl_dag_update_state(); rpl_dag_update_state();
#if LOG_INFO_ENABLED if(LOG_INFO_ENABLED) {
rpl_neighbor_print_list("Periodic"); rpl_neighbor_print_list("Periodic");
#endif /* LOG_INFO_ENABLED */ }
ctimer_reset(&periodic_timer); ctimer_reset(&periodic_timer);
} }

View File

@ -165,7 +165,12 @@ extern struct log_module all_modules[];
#define LOG_INFO_6ADDR(...) LOG_6ADDR(LOG_LEVEL_INFO, __VA_ARGS__) #define LOG_INFO_6ADDR(...) LOG_6ADDR(LOG_LEVEL_INFO, __VA_ARGS__)
#define LOG_DBG_6ADDR(...) LOG_6ADDR(LOG_LEVEL_DBG, __VA_ARGS__) #define LOG_DBG_6ADDR(...) LOG_6ADDR(LOG_LEVEL_DBG, __VA_ARGS__)
/* For testing log level */ /* For checking log level.
As this builds on curr_log_level variables, this should not be used
in pre-processor macros. Use in a C 'if' statement instead, e.g.:
if(LOG_INFO_ENABLED) { ... }
Note that most compilers will still be able to strip the code out
for low enough log levels configurations. */
#define LOG_ERR_ENABLED ((LOG_LEVEL) >= LOG_LEVEL_ERR) #define LOG_ERR_ENABLED ((LOG_LEVEL) >= LOG_LEVEL_ERR)
#define LOG_WARN_ENABLED ((LOG_LEVEL) >= LOG_LEVEL_WARN) #define LOG_WARN_ENABLED ((LOG_LEVEL) >= LOG_LEVEL_WARN)
#define LOG_INFO_ENABLED ((LOG_LEVEL) >= LOG_LEVEL_INFO) #define LOG_INFO_ENABLED ((LOG_LEVEL) >= LOG_LEVEL_INFO)