forked from microsoft/WSL2-Linux-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: 'perf kvm' tool for monitoring guest performance from host
Here is the patch of userspace perf tool. Signed-off-by: Zhang Yanmin <yanmin_zhang@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
- Loading branch information
Showing
30 changed files
with
1,407 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
perf-kvm(1) | ||
============== | ||
|
||
NAME | ||
---- | ||
perf-kvm - Tool to trace/measure kvm guest os | ||
|
||
SYNOPSIS | ||
-------- | ||
[verse] | ||
'perf kvm' [--host] [--guest] [--guestmount=<path> | ||
[--guestkallsyms=<path> --guestmodules=<path> | --guestvmlinux=<path>]] | ||
{top|record|report|diff|buildid-list} | ||
'perf kvm' [--host] [--guest] [--guestkallsyms=<path> --guestmodules=<path> | ||
| --guestvmlinux=<path>] {top|record|report|diff|buildid-list} | ||
|
||
DESCRIPTION | ||
----------- | ||
There are a couple of variants of perf kvm: | ||
|
||
'perf kvm [options] top <command>' to generates and displays | ||
a performance counter profile of guest os in realtime | ||
of an arbitrary workload. | ||
|
||
'perf kvm record <command>' to record the performance couinter profile | ||
of an arbitrary workload and save it into a perf data file. If both | ||
--host and --guest are input, the perf data file name is perf.data.kvm. | ||
If there is no --host but --guest, the file name is perf.data.guest. | ||
If there is no --guest but --host, the file name is perf.data.host. | ||
|
||
'perf kvm report' to display the performance counter profile information | ||
recorded via perf kvm record. | ||
|
||
'perf kvm diff' to displays the performance difference amongst two perf.data | ||
files captured via perf record. | ||
|
||
'perf kvm buildid-list' to display the buildids found in a perf data file, | ||
so that other tools can be used to fetch packages with matching symbol tables | ||
for use by perf report. | ||
|
||
OPTIONS | ||
------- | ||
--host=:: | ||
Collect host side perforamnce profile. | ||
--guest=:: | ||
Collect guest side perforamnce profile. | ||
--guestmount=<path>:: | ||
Guest os root file system mount directory. Users mounts guest os | ||
root directories under <path> by a specific filesystem access method, | ||
typically, sshfs. For example, start 2 guest os. The one's pid is 8888 | ||
and the other's is 9999. | ||
#mkdir ~/guestmount; cd ~/guestmount | ||
#sshfs -o allow_other,direct_io -p 5551 localhost:/ 8888/ | ||
#sshfs -o allow_other,direct_io -p 5552 localhost:/ 9999/ | ||
#perf kvm --host --guest --guestmount=~/guestmount top | ||
--guestkallsyms=<path>:: | ||
Guest os /proc/kallsyms file copy. 'perf' kvm' reads it to get guest | ||
kernel symbols. Users copy it out from guest os. | ||
--guestmodules=<path>:: | ||
Guest os /proc/modules file copy. 'perf' kvm' reads it to get guest | ||
kernel module information. Users copy it out from guest os. | ||
--guestvmlinux=<path>:: | ||
Guest os kernel vmlinux. | ||
|
||
SEE ALSO | ||
-------- | ||
linkperf:perf-top[1] perf-record[1] perf-report[1] perf-diff[1] perf-buildid-list[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "builtin.h" | ||
#include "perf.h" | ||
|
||
#include "util/util.h" | ||
#include "util/cache.h" | ||
#include "util/symbol.h" | ||
#include "util/thread.h" | ||
#include "util/header.h" | ||
#include "util/session.h" | ||
|
||
#include "util/parse-options.h" | ||
#include "util/trace-event.h" | ||
|
||
#include "util/debug.h" | ||
|
||
#include <sys/prctl.h> | ||
|
||
#include <semaphore.h> | ||
#include <pthread.h> | ||
#include <math.h> | ||
|
||
static char *file_name; | ||
static char name_buffer[256]; | ||
|
||
int perf_host = 1; | ||
int perf_guest; | ||
|
||
static const char * const kvm_usage[] = { | ||
"perf kvm [<options>] {top|record|report|diff|buildid-list}", | ||
NULL | ||
}; | ||
|
||
static const struct option kvm_options[] = { | ||
OPT_STRING('i', "input", &file_name, "file", | ||
"Input file name"), | ||
OPT_STRING('o', "output", &file_name, "file", | ||
"Output file name"), | ||
OPT_BOOLEAN(0, "guest", &perf_guest, | ||
"Collect guest os data"), | ||
OPT_BOOLEAN(0, "host", &perf_host, | ||
"Collect guest os data"), | ||
OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", | ||
"guest mount directory under which every guest os" | ||
" instance has a subdir"), | ||
OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name, | ||
"file", "file saving guest os vmlinux"), | ||
OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms, | ||
"file", "file saving guest os /proc/kallsyms"), | ||
OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, | ||
"file", "file saving guest os /proc/modules"), | ||
OPT_END() | ||
}; | ||
|
||
static int __cmd_record(int argc, const char **argv) | ||
{ | ||
int rec_argc, i = 0, j; | ||
const char **rec_argv; | ||
|
||
rec_argc = argc + 2; | ||
rec_argv = calloc(rec_argc + 1, sizeof(char *)); | ||
rec_argv[i++] = strdup("record"); | ||
rec_argv[i++] = strdup("-o"); | ||
rec_argv[i++] = strdup(file_name); | ||
for (j = 1; j < argc; j++, i++) | ||
rec_argv[i] = argv[j]; | ||
|
||
BUG_ON(i != rec_argc); | ||
|
||
return cmd_record(i, rec_argv, NULL); | ||
} | ||
|
||
static int __cmd_report(int argc, const char **argv) | ||
{ | ||
int rec_argc, i = 0, j; | ||
const char **rec_argv; | ||
|
||
rec_argc = argc + 2; | ||
rec_argv = calloc(rec_argc + 1, sizeof(char *)); | ||
rec_argv[i++] = strdup("report"); | ||
rec_argv[i++] = strdup("-i"); | ||
rec_argv[i++] = strdup(file_name); | ||
for (j = 1; j < argc; j++, i++) | ||
rec_argv[i] = argv[j]; | ||
|
||
BUG_ON(i != rec_argc); | ||
|
||
return cmd_report(i, rec_argv, NULL); | ||
} | ||
|
||
static int __cmd_buildid_list(int argc, const char **argv) | ||
{ | ||
int rec_argc, i = 0, j; | ||
const char **rec_argv; | ||
|
||
rec_argc = argc + 2; | ||
rec_argv = calloc(rec_argc + 1, sizeof(char *)); | ||
rec_argv[i++] = strdup("buildid-list"); | ||
rec_argv[i++] = strdup("-i"); | ||
rec_argv[i++] = strdup(file_name); | ||
for (j = 1; j < argc; j++, i++) | ||
rec_argv[i] = argv[j]; | ||
|
||
BUG_ON(i != rec_argc); | ||
|
||
return cmd_buildid_list(i, rec_argv, NULL); | ||
} | ||
|
||
int cmd_kvm(int argc, const char **argv, const char *prefix __used) | ||
{ | ||
perf_host = perf_guest = 0; | ||
|
||
argc = parse_options(argc, argv, kvm_options, kvm_usage, | ||
PARSE_OPT_STOP_AT_NON_OPTION); | ||
if (!argc) | ||
usage_with_options(kvm_usage, kvm_options); | ||
|
||
if (!perf_host) | ||
perf_guest = 1; | ||
|
||
if (!file_name) { | ||
if (perf_host && !perf_guest) | ||
sprintf(name_buffer, "perf.data.host"); | ||
else if (!perf_host && perf_guest) | ||
sprintf(name_buffer, "perf.data.guest"); | ||
else | ||
sprintf(name_buffer, "perf.data.kvm"); | ||
file_name = name_buffer; | ||
} | ||
|
||
if (!strncmp(argv[0], "rec", 3)) | ||
return __cmd_record(argc, argv); | ||
else if (!strncmp(argv[0], "rep", 3)) | ||
return __cmd_report(argc, argv); | ||
else if (!strncmp(argv[0], "diff", 4)) | ||
return cmd_diff(argc, argv, NULL); | ||
else if (!strncmp(argv[0], "top", 3)) | ||
return cmd_top(argc, argv, NULL); | ||
else if (!strncmp(argv[0], "buildid-list", 12)) | ||
return __cmd_buildid_list(argc, argv); | ||
else | ||
usage_with_options(kvm_usage, kvm_options); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.