2 #include <kvm/kvm-cmd.h>
3 #include <kvm/builtin-stat.h>
5 #include <kvm/parse-options.h>
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]",
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"),
31 static void parse_stat_options(int argc
, const char **argv
)
34 argc
= parse_options(argc
, argv
, stat_options
, stat_usage
,
35 PARSE_OPT_STOP_AT_NON_OPTION
);
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
);
57 usage_with_options(stat_usage
, stat_options
);
60 return kvm__enumerate_instances(do_memstat
);
62 if (instance_name
== NULL
&&
67 instance_pid
= kvm__get_pid_by_instance(instance_name
);
69 if (instance_pid
<= 0)
70 die("Failed locating instance");
73 printf("Sending memstat command to designated instance, output should be on the targets' terminal.\n");
75 return kill(instance_pid
, SIGKVMMEMSTAT
);