Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mxqps: Add new tool to list mxqd processes
  • Loading branch information
mariux committed Oct 24, 2015
1 parent cd27987 commit 0a6148d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ mxqadmin
mxqdump
mxqkill
mxqd
mxqps
test_mx_util
test_mx_log
test_mx_mysql
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Expand Up @@ -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
Expand Down
94 changes: 94 additions & 0 deletions mxqps.c
@@ -0,0 +1,94 @@

#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <unistd.h>

#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;

}

0 comments on commit 0a6148d

Please sign in to comment.