The discovered bit in PGCCSR register indicates if the device has been
[linux-2.6/next.git] / tools / kvm / builtin-stat.c
blobbe12d15a16aeeef023a00a38669d9755163e298c
1 #include <kvm/util.h>
2 #include <kvm/kvm-cmd.h>
3 #include <kvm/builtin-stat.h>
4 #include <kvm/kvm.h>
5 #include <kvm/parse-options.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <signal.h>
11 static bool mem;
12 static bool all;
13 static pid_t instance_pid;
14 static const char *instance_name;
16 static const char * const stat_usage[] = {
17 "kvm stat [command] [--all] [-n name] [-p pid]",
18 NULL
21 static const struct option stat_options[] = {
22 OPT_GROUP("Commands options:"),
23 OPT_BOOLEAN('m', "memory", &mem, "Display memory statistics"),
24 OPT_GROUP("Instance options:"),
25 OPT_BOOLEAN('a', "all", &all, "All instances"),
26 OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
27 OPT_INTEGER('p', "pid", &instance_pid, "Instance pid"),
28 OPT_END()
31 static void parse_stat_options(int argc, const char **argv)
33 while (argc != 0) {
34 argc = parse_options(argc, argv, stat_options, stat_usage,
35 PARSE_OPT_STOP_AT_NON_OPTION);
36 if (argc != 0)
37 kvm_stat_help();
41 void kvm_stat_help(void)
43 usage_with_options(stat_usage, stat_options);
46 static int do_memstat(const char *name, int pid)
48 printf("Sending memstat command to %s, output should be on the targets' terminal.\n", name);
49 return kill(pid, SIGKVMMEMSTAT);
52 int kvm_cmd_stat(int argc, const char **argv, const char *prefix)
54 parse_stat_options(argc, argv);
56 if (!mem)
57 usage_with_options(stat_usage, stat_options);
59 if (mem && all)
60 return kvm__enumerate_instances(do_memstat);
62 if (instance_name == NULL &&
63 instance_pid == 0)
64 kvm_stat_help();
66 if (instance_name)
67 instance_pid = kvm__get_pid_by_instance(instance_name);
69 if (instance_pid <= 0)
70 die("Failed locating instance");
72 if (mem) {
73 printf("Sending memstat command to designated instance, output should be on the targets' terminal.\n");
75 return kill(instance_pid, SIGKVMMEMSTAT);
78 return 0;