Skip to content

Commit

Permalink
lib: Add ability to track time in individual routemaps
Browse files Browse the repository at this point in the history
Add the abilty to track how much time is spent in routemaps.
Example of the new output:

eva# show route-map
ZEBRA:
route-map: FOO Invoked: 1000000 (323 milliseconds total) Optimization: enabled Processed Change: false
 deny, sequence 10 Invoked 1000000 (320 milliseconds total)
  Match clauses:
  Set clauses:
  Call clause:
  Action:
    Exit routemap

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Sep 5, 2023
1 parent 92515dc commit 9243a30
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 27 deletions.
7 changes: 4 additions & 3 deletions doc/user/routemap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ cont

.. clicmd:: clear route-map counter [WORD]

Clear counters that are being stored about the route-map utilization
so that subsuquent show commands will indicate since the last clear.
If WORD is specified clear just that particular route-map's counters.
Clear counters as well as cpu time spent that are being stored about
the route-map utilization so that subsequent show commands will indicate
since the last clear. If WORD is specified clear just that particular
route-map's counters.

.. _route-map-command:

Expand Down
39 changes: 35 additions & 4 deletions lib/routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,13 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map,
json_object_boolean_add(json_rmap, "processedChange",
map->to_be_processed);
json_object_object_add(json_rmap, "rules", json_rules);
json_object_int_add(json_rmap, "cpuTimeMS", map->cputime / 1000);
} else {
vty_out(vty,
"route-map: %s Invoked: %" PRIu64
" Optimization: %s Processed Change: %s\n",
" (%zu milliseconds total) Optimization: %s Processed Change: %s\n",
map->name, map->applied - map->applied_clear,
map->cputime / 1000,
map->optimization_disabled ? "disabled" : "enabled",
map->to_be_processed ? "true" : "false");
}
Expand All @@ -967,6 +969,8 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map,
json_object_int_add(json_rule, "invoked",
index->applied
- index->applied_clear);
json_object_int_add(json_rule, "cpuTimeMS",
index->cputime / 1000);

/* Description */
if (index->description)
Expand Down Expand Up @@ -1018,9 +1022,12 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map,
json_object_string_add(json_rule, "action",
action);
} else {
vty_out(vty, " %s, sequence %d Invoked %" PRIu64 "\n",
vty_out(vty,
" %s, sequence %d Invoked %" PRIu64
" (%zu milliseconds total)\n",
route_map_type_str(index->type), index->pref,
index->applied - index->applied_clear);
index->applied - index->applied_clear,
index->cputime / 1000);

/* Description */
if (index->description)
Expand Down Expand Up @@ -2552,6 +2559,9 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
struct route_map_rule *set = NULL;
bool skip_match_clause = false;
struct prefix conv;
RUSAGE_T mbefore, mafter;
RUSAGE_T ibefore, iafter;
unsigned long cputime;

if (recursion > RMAP_RECURSION_LIMIT) {
if (map)
Expand All @@ -2574,6 +2584,8 @@ route_map_result_t route_map_apply_ext(struct route_map *map,

map->applied++;

GETRUSAGE(&mbefore);
ibefore = mbefore;
/*
* Handling for matching evpn_routes in the prefix table.
*
Expand Down Expand Up @@ -2601,6 +2613,12 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
index = route_map_get_index(map, prefix, match_object, &match_ret);
if (index) {
index->applied++;

GETRUSAGE(&iafter);
event_consumed_time(&iafter, &ibefore, &cputime);
index->cputime += cputime;
ibefore = iafter;

if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug(
"Best match route-map: %s, sequence: %d for pfx: %pFX, result: %s",
Expand Down Expand Up @@ -2740,6 +2758,10 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
goto route_map_apply_end;
}
}
GETRUSAGE(&iafter);
event_consumed_time(&iafter, &ibefore, &cputime);
index->cputime += cputime;
ibefore = iafter;
}

route_map_apply_end:
Expand All @@ -2755,6 +2777,12 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
*pref = 65536;
}

if (map) {
GETRUSAGE(&mafter);
event_consumed_time(&mafter, &mbefore, &cputime);
map->cputime += cputime;
}

return (ret);
}

Expand Down Expand Up @@ -3112,8 +3140,11 @@ static void clear_route_map_helper(struct route_map *map)
struct route_map_index *index;

map->applied_clear = map->applied;
for (index = map->head; index; index = index->next)
map->cputime = 0;
for (index = map->head; index; index = index->next) {
index->applied_clear = index->applied;
index->cputime = 0;
}
}

DEFPY (rmap_clear_counters,
Expand Down
2 changes: 2 additions & 0 deletions lib/routemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct route_map_index {
/* Keep track how many times we've try to apply */
uint64_t applied;
uint64_t applied_clear;
size_t cputime;

/* List of match/sets contexts. */
TAILQ_HEAD(, routemap_hook_context) rhclist;
Expand Down Expand Up @@ -210,6 +211,7 @@ struct route_map {
/* How many times have we applied this route-map */
uint64_t applied;
uint64_t applied_clear;
size_t cputime;

/* Counter to track active usage of this route-map */
uint16_t use_count;
Expand Down
30 changes: 15 additions & 15 deletions tests/topotests/all_protocol_startup/r1/show_route_map.ref
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
ZEBRA:
route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
route-map: LIES Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
interface notpresent
Set clauses:
Call clause:
Action:
Exit routemap
RIP:
route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
route-map: LIES Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
interface notpresent
Set clauses:
Call clause:
Action:
Exit routemap
RIPNG:
route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
route-map: LIES Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
interface notpresent
Set clauses:
Call clause:
Action:
Exit routemap
OSPF:
route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
route-map: LIES Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
interface notpresent
Set clauses:
Call clause:
Action:
Exit routemap
OSPF6:
route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
route-map: LIES Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
interface notpresent
Set clauses:
Call clause:
Action:
Exit routemap
BGP:
route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
route-map: LIES Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
interface notpresent
Set clauses:
Call clause:
Action:
Exit routemap
route-map: bgp-map Invoked: 0 Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 0
route-map: bgp-map Invoked: 0 (0 milliseconds total) Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 0 (0 milliseconds total)
Match clauses:
Set clauses:
community 100:100 additive
local-preference 100
Call clause:
Action:
Exit routemap
permit, sequence 20 Invoked 0
permit, sequence 20 Invoked 0 (0 milliseconds total)
Match clauses:
Set clauses:
metric 10
Expand Down
6 changes: 3 additions & 3 deletions tests/topotests/zebra_rib/r1/sharp_rmap.ref
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ZEBRA:
route-map: sharp Invoked: 500 Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 244
route-map: sharp Invoked: 500 (0 milliseconds total) Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 244 (0 milliseconds total)
Match clauses:
ip address 10
Set clauses:
src 192.168.214.1
Call clause:
Action:
Exit routemap
permit, sequence 20 Invoked 256
permit, sequence 20 Invoked 256 (0 milliseconds total)
Match clauses:
Set clauses:
src 192.168.213.1
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/zebra_rib/r1/static_rmap.ref
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ZEBRA:
route-map: static Invoked: 2 Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 2
route-map: static Invoked: 2 (0 milliseconds total) Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 2 (0 milliseconds total)
Match clauses:
Set clauses:
src 192.168.215.1
Expand Down

0 comments on commit 9243a30

Please sign in to comment.