From: Donald Sharp Date: Sat, 16 Jun 2018 22:12:54 +0000 (-0400) Subject: lib, vtysh: Add 'show thread poll' command X-Git-Tag: frr-6.1-dev~295^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=8872626bb4b8f5d9d06ea2b5e513e5ecb6a541aa;p=matthieu%2Ffrr.git lib, vtysh: Add 'show thread poll' command Add a 'show thread poll' command that displays the poll information and fd's setup. Signed-off-by: Donald Sharp --- diff --git a/lib/thread.c b/lib/thread.c index 18e1c92280..1c5e838772 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -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 ------------------------------------------------------------------ */ diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index c6e060500b..4ac7448394 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -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);