]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib, vtysh: Add 'show thread poll' command
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 16 Jun 2018 22:12:54 +0000 (18:12 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 17 Jun 2018 00:09:45 +0000 (20:09 -0400)
Add a 'show thread poll' command that displays the
poll information and fd's setup.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/thread.c
vtysh/vtysh.c

index 18e1c922804cf43faad3302a2860582835ab79e2..1c5e8387729774dc9bf355b47055c6a736e97383 100644 (file)
@@ -296,6 +296,47 @@ DEFUN (show_thread_cpu,
        return CMD_SUCCESS;
 }
 
+static void show_thread_poll_helper(struct vty *vty, struct thread_master *m)
+{
+       const char *name = m->name ? m->name : "main";
+       char underline[strlen(name) + 1];
+       uint32_t i;
+
+       memset(underline, '-', sizeof(underline));
+       underline[sizeof(underline) - 1] = '\0';
+
+       vty_out(vty, "\nShowing poll FD's for %s\n", name);
+       vty_out(vty, "----------------------%s\n", underline);
+       vty_out(vty, "Count: %u\n", (uint32_t)m->handler.pfdcount);
+       for (i = 0; i < m->handler.pfdcount; i++)
+               vty_out(vty, "\t%6d fd:%6d events:%2d revents:%2d\n", i,
+                       m->handler.pfds[i].fd,
+                       m->handler.pfds[i].events,
+                       m->handler.pfds[i].revents);
+}
+
+DEFUN (show_thread_poll,
+       show_thread_poll_cmd,
+       "show thread poll",
+       SHOW_STR
+       "Thread information\n"
+       "Show poll FD's and information\n")
+{
+       struct listnode *node;
+       struct thread_master *m;
+
+       pthread_mutex_lock(&masters_mtx);
+       {
+               for (ALL_LIST_ELEMENTS_RO(masters, node, m)) {
+                       show_thread_poll_helper(vty, m);
+               }
+       }
+       pthread_mutex_unlock(&masters_mtx);
+
+       return CMD_SUCCESS;
+}
+
+
 DEFUN (clear_thread_cpu,
        clear_thread_cpu_cmd,
        "clear thread cpu [FILTER]",
@@ -325,6 +366,7 @@ DEFUN (clear_thread_cpu,
 void thread_cmd_init(void)
 {
        install_element(VIEW_NODE, &show_thread_cpu_cmd);
+       install_element(VIEW_NODE, &show_thread_poll_cmd);
        install_element(ENABLE_NODE, &clear_thread_cpu_cmd);
 }
 /* CLI end ------------------------------------------------------------------ */
index c6e060500b83a4e4b72da761ae4999e2bfad557e..4ac7448394a3ca70411956ff87b187c06005704f 100644 (file)
@@ -2136,6 +2136,29 @@ DEFUNSH(VTYSH_INTERFACE, vtysh_quit_interface, vtysh_quit_interface_cmd, "quit",
        return vtysh_exit_interface(self, vty, argc, argv);
 }
 
+DEFUN (vtysh_show_poll,
+       vtysh_show_poll_cmd,
+       "show thread poll",
+       SHOW_STR
+       "Thread information\n"
+       "Thread Poll Information\n")
+{
+       unsigned int i;
+       int idx = 0;
+       int ret = CMD_SUCCESS;
+       char line[100];
+
+       snprintf(line, sizeof(line), "do show thread poll\n");
+       for (i = 0; i < array_size(vtysh_client); i++)
+               if (vtysh_client[i].fd >= 0) {
+                       vty_out(vty, "Thread statistics for %s:\n",
+                               vtysh_client[i].name);
+                       ret = vtysh_client_execute(&vtysh_client[i], line);
+                       vty_out(vty, "\n");
+               }
+       return ret;
+}
+
 DEFUN (vtysh_show_thread,
        vtysh_show_thread_cmd,
        "show thread cpu [FILTER]",
@@ -3720,6 +3743,7 @@ void vtysh_init_vty(void)
        install_element(VIEW_NODE, &vtysh_show_work_queues_cmd);
        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);
 
        /* Logging */
        install_element(VIEW_NODE, &vtysh_show_logging_cmd);