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 <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2018-06-16 18:12:54 -04:00
parent 65c4ceac44
commit 8872626bb4
2 changed files with 66 additions and 0 deletions

View 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 ------------------------------------------------------------------ */

View 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);