kvm tools: Add 'kvm stat' command

This patch adds 'kvm stat' command that allows retrieving statistics out of
a running guest.

Currently the only supported statistics are memory statistics, available using the
'--memory' parameter.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Sasha Levin
2011-08-15 17:32:59 +03:00
committed by Will Deacon
parent 7a6144aa71
commit bc10d2c1c8
8 changed files with 214 additions and 4 deletions
+79
View File
@@ -0,0 +1,79 @@
#include <kvm/util.h>
#include <kvm/kvm-cmd.h>
#include <kvm/builtin-stat.h>
#include <kvm/kvm.h>
#include <kvm/parse-options.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
static bool mem;
static bool all;
static u64 instance_pid;
static const char *instance_name;
static const char * const stat_usage[] = {
"kvm stat [command] [--all] [-n name] [-p pid]",
NULL
};
static const struct option stat_options[] = {
OPT_GROUP("Commands options:"),
OPT_BOOLEAN('m', "memory", &mem, "Display memory statistics"),
OPT_GROUP("Instance options:"),
OPT_BOOLEAN('a', "all", &all, "All instances"),
OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
OPT_U64('p', "pid", &instance_pid, "Instance pid"),
OPT_END()
};
static void parse_stat_options(int argc, const char **argv)
{
while (argc != 0) {
argc = parse_options(argc, argv, stat_options, stat_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
if (argc != 0)
kvm_stat_help();
}
}
void kvm_stat_help(void)
{
usage_with_options(stat_usage, stat_options);
}
static int do_memstat(const char *name, int pid)
{
printf("Sending memstat command to %s, output should be on the targets' terminal.\n", name);
return kill(pid, SIGKVMMEMSTAT);
}
int kvm_cmd_stat(int argc, const char **argv, const char *prefix)
{
parse_stat_options(argc, argv);
if (!mem)
usage_with_options(stat_usage, stat_options);
if (mem && all)
return kvm__enumerate_instances(do_memstat);
if (instance_name == NULL &&
instance_pid == 0)
kvm_stat_help();
if (instance_name)
instance_pid = kvm__get_pid_by_instance(instance_name);
if (instance_pid <= 0)
die("Failed locating instance");
if (mem) {
printf("Sending memstat command to designated instance, output should be on the targets' terminal.\n");
return kill(instance_pid, SIGKVMMEMSTAT);
}
return 0;
}