From 0a6148d3af69c52c5cba3e5e8fc33cd24baef955 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 22 Oct 2015 16:01:47 +0200 Subject: [PATCH] mxqps: Add new tool to list mxqd processes --- .gitignore | 2 ++ Makefile | 15 +++++++++ mxqps.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 mxqps.c diff --git a/.gitignore b/.gitignore index f466977c..4509600b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ mx_flock.o mx_log.o mx_util.o mx_proc.o +mxqps.o mxq_group.o mxqadmin.o mxqdump.o @@ -22,6 +23,7 @@ mxqadmin mxqdump mxqkill mxqd +mxqps test_mx_util test_mx_log test_mx_mysql diff --git a/Makefile b/Makefile index ca31600f..a1a38766 100644 --- a/Makefile +++ b/Makefile @@ -495,6 +495,21 @@ clean: CLEAN += mxqkill install:: mxqkill $(call quiet-installforuser,$(SUID_MODE),$(UID_CLIENT),$(GID_CLIENT),mxqkill,${DESTDIR}${BINDIR}/mxqkill) +### mxqps ------------------------------------------------------------- + +mxqps.o: $(mx_proc.h) +mxqps.o: $(mx_util.h) + +clean: CLEAN += mxqps.o + +mxqps: mx_log.o +mxqps: mx_util.o +mxqps: mx_proc.o + +build: mxqps + +clean: CLEAN += mxqps + ######################################################################## fix: FIX += mxqdctl-hostconfig.sh diff --git a/mxqps.c b/mxqps.c new file mode 100644 index 00000000..5088edc0 --- /dev/null +++ b/mxqps.c @@ -0,0 +1,94 @@ + +#include +#include +#include +#include +#include +#include + +#include "mx_util.h" +#include "mx_log.h" +#include "mx_proc.h" + + +int filter(const struct dirent *d) +{ + if (!isdigit(d->d_name[0])) + return 0; + + return 1; +} + +#define MX_PROC_TREE_NODE_IS_KERNEL_THREAD(x) ((x)->pinfo.pstat->ppid == 0 && (x)->pinfo.sum_rss == 0) + +int mx_proc_tree_node_print_debug(struct mx_proc_tree_node *ptn, int lvl) +{ + assert(ptn); + + struct mx_proc_tree_node *current; + + current = ptn; + + long pagesize; + + pagesize = sysconf(_SC_PAGESIZE); + assert(pagesize); + + for (current = ptn; current; current=current->next) { + if (MX_PROC_TREE_NODE_IS_KERNEL_THREAD(current)) + continue; + + printf("%7lld %7lld %7lld %7lld %15lld %15lld %7lld", + current->pinfo.pstat->pid, + current->pinfo.pstat->ppid, + current->pinfo.pstat->pgrp, + current->pinfo.pstat->session, + current->pinfo.pstat->rss*pagesize/1024, + current->pinfo.sum_rss*pagesize/1024, + current->pinfo.pstat->num_threads); + + if (lvl>0) + printf("%*s", lvl*4, "\\_"); + assert(current->pinfo.pstat); + printf(" %s\n", current->pinfo.pstat->comm); + + if (!current->childs) + continue; + + mx_proc_tree_node_print_debug(current->childs, lvl+(current->parent != NULL)); + } + + return 0; +} + +int mx_proc_tree_print_debug(struct mx_proc_tree *pt) +{ + assert(pt); + printf("%7s %7s %7s %7s %15s %15s %7s COMMAND\n", + "PID", + "PPID", + "PGRP", + "SESSION", + "RSS", + "SUMRSS", + "THREADS"); + mx_proc_tree_node_print_debug(pt->root, 0); + return 0; +} + +int main(void) +{ + int res; + struct mx_proc_tree *pt = NULL; + + res = mx_proc_tree(&pt); + assert(res == 0); + + mx_proc_tree_print_debug(pt); + + mx_proc_tree_free(&pt); + + + return 0; + +}