]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib, vtysh: Add `show thread timers` command
authorDonald Sharp <sharpd@nvidia.com>
Wed, 23 Feb 2022 15:14:53 +0000 (10:14 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Mon, 28 Feb 2022 11:39:07 +0000 (06:39 -0500)
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 <sharpd@nvidia.com>
lib/thread.c
vtysh/vtysh.c

index bc3bfe89d48aa1e86087da89dcde1b1af5575d4e..6d91ca497b8462ac39daac26ee830df243445db7 100644 (file)
@@ -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 ------------------------------------------------------------------ */
 
index fe7a2e73ffce520aae83b195e5ff67402af3f485..a1cb02f316a581752bd79da30f5d8f2c28724c1a 100644 (file)
@@ -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);