]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
route: Guard free route list stats
authorRoy Marples <roy@marples.name>
Tue, 5 Mar 2019 20:59:42 +0000 (20:59 +0000)
committerRoy Marples <roy@marples.name>
Tue, 5 Mar 2019 20:59:42 +0000 (20:59 +0000)
And add a maximum free list size stat

src/route.c

index dbe2b5a51f9395b174a1ff9d5dad1b4563c84c31..5a50957ca20584eb25d9f03b67b4a9e48253b972 100644 (file)
         (N) = (S))
 #endif
 
-#ifdef RT_FREE_ROUTE_TABLE
+#ifdef RT_FREE_ROUTE_TABLE_STATS
+static size_t croutes;
 static size_t nroutes;
 static size_t froutes;
+static size_t mroutes;
 #endif
 
 /*
@@ -258,8 +260,11 @@ rt_dispose(struct dhcpcd_ctx *ctx)
        rt_headfree(&ctx->routes);
 #ifdef RT_FREE_ROUTE_TABLE
        rt_headfree(&ctx->froutes);
+#ifdef RT_FREE_ROUTE_TABLE_STATS
        logdebugx("free route list used %zu times", froutes);
-       logdebugx("new routes from free list %zu", nroutes);
+       logdebugx("new routes from route free list %zu", nroutes);
+       logdebugx("maximum route free list size %zu", mroutes);
+#endif
 #endif
 }
 
@@ -272,7 +277,10 @@ rt_new0(struct dhcpcd_ctx *ctx)
 #ifdef RT_FREE_ROUTE_TABLE
        if ((rt = RB_TREE_MIN(&ctx->froutes)) != NULL) {
                rb_tree_remove_node(&ctx->froutes, rt);
+#ifdef RT_FREE_ROUTE_TABLE_STATS
+               croutes--;
                nroutes++;
+#endif
        } else
 #endif
        if ((rt = malloc(sizeof(*rt))) == NULL) {
@@ -319,7 +327,12 @@ rt_free(struct rt *rt)
 
        ctx = rt->rt_ifp->ctx;
        rb_tree_insert_node(&ctx->froutes, rt);
+#ifdef RT_FREE_ROUTE_TABLE_STATS
+       croutes++;
        froutes++;
+       if (croutes > mroutes)
+               mroutes = croutes;
+#endif
 #else
        free(rt);
 #endif