Commit 546040dc authored by Balbir Singh's avatar Balbir Singh Committed by Linus Torvalds

make getdelays cgroupstats aware

Update the getdelays utility to become cgroupstats aware.  A new -C option has
been added.  It takes in a control group path and prints out a summary of the
states of tasks in the control group
Signed-off-by: default avatarBalbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dbc0e4ce
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/genetlink.h> #include <linux/genetlink.h>
#include <linux/taskstats.h> #include <linux/taskstats.h>
#include <linux/cgroupstats.h>
/* /*
* Generic macros for dealing with netlink sockets. Might be duplicated * Generic macros for dealing with netlink sockets. Might be duplicated
...@@ -78,6 +79,7 @@ static void usage(void) ...@@ -78,6 +79,7 @@ static void usage(void)
fprintf(stderr, " -i: print IO accounting (works only with -p)\n"); fprintf(stderr, " -i: print IO accounting (works only with -p)\n");
fprintf(stderr, " -l: listen forever\n"); fprintf(stderr, " -l: listen forever\n");
fprintf(stderr, " -v: debug on\n"); fprintf(stderr, " -v: debug on\n");
fprintf(stderr, " -C: container path\n");
} }
/* /*
...@@ -212,6 +214,14 @@ void task_context_switch_counts(struct taskstats *t) ...@@ -212,6 +214,14 @@ void task_context_switch_counts(struct taskstats *t)
t->nvcsw, t->nivcsw); t->nvcsw, t->nivcsw);
} }
void print_cgroupstats(struct cgroupstats *c)
{
printf("sleeping %llu, blocked %llu, running %llu, stopped %llu, "
"uninterruptible %llu\n", c->nr_sleeping, c->nr_io_wait,
c->nr_running, c->nr_stopped, c->nr_uninterruptible);
}
void print_ioacct(struct taskstats *t) void print_ioacct(struct taskstats *t)
{ {
printf("%s: read=%llu, write=%llu, cancelled_write=%llu\n", printf("%s: read=%llu, write=%llu, cancelled_write=%llu\n",
...@@ -239,11 +249,14 @@ int main(int argc, char *argv[]) ...@@ -239,11 +249,14 @@ int main(int argc, char *argv[])
int maskset = 0; int maskset = 0;
char *logfile = NULL; char *logfile = NULL;
int loop = 0; int loop = 0;
int containerset = 0;
char containerpath[1024];
int cfd = 0;
struct msgtemplate msg; struct msgtemplate msg;
while (1) { while (1) {
c = getopt(argc, argv, "qdiw:r:m:t:p:vl"); c = getopt(argc, argv, "qdiw:r:m:t:p:vlC:");
if (c < 0) if (c < 0)
break; break;
...@@ -260,6 +273,10 @@ int main(int argc, char *argv[]) ...@@ -260,6 +273,10 @@ int main(int argc, char *argv[])
printf("printing task/process context switch rates\n"); printf("printing task/process context switch rates\n");
print_task_context_switch_counts = 1; print_task_context_switch_counts = 1;
break; break;
case 'C':
containerset = 1;
strncpy(containerpath, optarg, strlen(optarg) + 1);
break;
case 'w': case 'w':
logfile = strdup(optarg); logfile = strdup(optarg);
printf("write to file %s\n", logfile); printf("write to file %s\n", logfile);
...@@ -334,6 +351,11 @@ int main(int argc, char *argv[]) ...@@ -334,6 +351,11 @@ int main(int argc, char *argv[])
} }
} }
if (tid && containerset) {
fprintf(stderr, "Select either -t or -C, not both\n");
goto err;
}
if (tid) { if (tid) {
rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET, rc = send_cmd(nl_sd, id, mypid, TASKSTATS_CMD_GET,
cmd_type, &tid, sizeof(__u32)); cmd_type, &tid, sizeof(__u32));
...@@ -344,6 +366,20 @@ int main(int argc, char *argv[]) ...@@ -344,6 +366,20 @@ int main(int argc, char *argv[])
} }
} }
if (containerset) {
cfd = open(containerpath, O_RDONLY);
if (cfd < 0) {
perror("error opening container file");
goto err;
}
rc = send_cmd(nl_sd, id, mypid, CGROUPSTATS_CMD_GET,
CGROUPSTATS_CMD_ATTR_FD, &cfd, sizeof(__u32));
if (rc < 0) {
perror("error sending cgroupstats command");
goto err;
}
}
do { do {
int i; int i;
...@@ -422,6 +458,9 @@ int main(int argc, char *argv[]) ...@@ -422,6 +458,9 @@ int main(int argc, char *argv[])
} }
break; break;
case CGROUPSTATS_TYPE_CGROUP_STATS:
print_cgroupstats(NLA_DATA(na));
break;
default: default:
fprintf(stderr, "Unknown nla_type %d\n", fprintf(stderr, "Unknown nla_type %d\n",
na->nla_type); na->nla_type);
...@@ -443,5 +482,7 @@ int main(int argc, char *argv[]) ...@@ -443,5 +482,7 @@ int main(int argc, char *argv[])
close(nl_sd); close(nl_sd);
if (fd) if (fd)
close(fd); close(fd);
if (cfd)
close(cfd);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment