From: Donald Sharp Date: Wed, 23 Feb 2022 15:14:53 +0000 (-0500) Subject: lib, vtysh: Add `show thread timers` command X-Git-Tag: pim6-testing-20220430~272^2~3 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=22f31b8c525bb73a8c2e7602c6a6996b608913f5;p=matthieu%2Ffrr.git lib, vtysh: Add `show thread timers` command Add the ability to inspect the timers and when they will pop per daemon: sharpd@eva ~/frr (thread_return_null)> vtysh -c "show thread timers" Thread timers for zebra: Showing timers for default -------------------------- rtadv_timer 00:00:00.520 if_zebra_speed_update 00:00:02.745 if_zebra_speed_update 00:00:02.745 if_zebra_speed_update 00:00:02.745 if_zebra_speed_update 00:00:02.745 if_zebra_speed_update 00:00:02.745 if_zebra_speed_update 00:00:02.745 if_zebra_speed_update 00:00:02.746 if_zebra_speed_update 00:00:02.744 if_zebra_speed_update 00:00:02.745 Showing timers for Zebra dplane thread -------------------------------------- Signed-off-by: Donald Sharp --- diff --git a/lib/thread.c b/lib/thread.c index bc3bfe89d4..6d91ca497b 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -498,6 +498,41 @@ DEFUN (clear_thread_cpu, return CMD_SUCCESS; } +static void show_thread_timers_helper(struct vty *vty, struct thread_master *m) +{ + const char *name = m->name ? m->name : "main"; + char underline[strlen(name) + 1]; + struct thread *thread; + + memset(underline, '-', sizeof(underline)); + underline[sizeof(underline) - 1] = '\0'; + + vty_out(vty, "\nShowing timers for %s\n", name); + vty_out(vty, "-------------------%s\n", underline); + + frr_each (thread_timer_list, &m->timer, thread) { + vty_out(vty, " %-50s%pTH\n", thread->hist->funcname, thread); + } +} + +DEFPY_NOSH (show_thread_timers, + show_thread_timers_cmd, + "show thread timers", + SHOW_STR + "Thread information\n" + "Show all timers and how long they have in the system\n") +{ + struct listnode *node; + struct thread_master *m; + + frr_with_mutex (&masters_mtx) { + for (ALL_LIST_ELEMENTS_RO(masters, node, m)) + show_thread_timers_helper(vty, m); + } + + return CMD_SUCCESS; +} + void thread_cmd_init(void) { install_element(VIEW_NODE, &show_thread_cpu_cmd); @@ -509,6 +544,8 @@ void thread_cmd_init(void) install_element(CONFIG_NODE, &no_service_cputime_warning_cmd); install_element(CONFIG_NODE, &service_walltime_warning_cmd); install_element(CONFIG_NODE, &no_service_walltime_warning_cmd); + + install_element(VIEW_NODE, &show_thread_timers_cmd); } /* CLI end ------------------------------------------------------------------ */ diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index fe7a2e73ff..a1cb02f316 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2715,6 +2715,16 @@ static int show_one_daemon(struct vty *vty, struct cmd_token **argv, int argc, return ret; } +DEFUN (vtysh_show_thread_timer, + vtysh_show_thread_timer_cmd, + "show thread timers", + SHOW_STR + "Thread information\n" + "Show all timers and how long they have in the system\n") +{ + return show_per_daemon(vty, argv, argc, "Thread timers for %s:\n"); +} + DEFUN (vtysh_show_poll, vtysh_show_poll_cmd, "show thread poll", @@ -4508,6 +4518,7 @@ void vtysh_init_vty(void) install_element(VIEW_NODE, &vtysh_show_work_queues_daemon_cmd); install_element(VIEW_NODE, &vtysh_show_thread_cmd); install_element(VIEW_NODE, &vtysh_show_poll_cmd); + install_element(VIEW_NODE, &vtysh_show_thread_timer_cmd); /* Logging */ install_element(VIEW_NODE, &vtysh_show_logging_cmd);