perf kvm: Do guest-only counting by default
Joerg Roedel [Wed, 4 Jan 2012 16:54:20 +0000 (17:54 +0100)]
Make use of exclude_guest and exlude_host in perf-kvm to do only
guest-only counting by default.

Cc: Gleb Natapov <gleb@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
[ committer note: Moved perf_{guest,host} & event_attr_init to util.c ]
[                 so as not to drag more stuff to the python binding]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

tools/perf/builtin-kvm.c
tools/perf/util/evlist.c
tools/perf/util/parse-events.c
tools/perf/util/util.c
tools/perf/util/util.h

index 032324a..9fc6e0f 100644 (file)
@@ -22,9 +22,6 @@
 static const char              *file_name;
 static char                    name_buffer[256];
 
-bool                           perf_host = 1;
-bool                           perf_guest;
-
 static const char * const kvm_usage[] = {
        "perf kvm [<options>] {top|record|report|diff|buildid-list}",
        NULL
@@ -107,7 +104,8 @@ static int __cmd_buildid_list(int argc, const char **argv)
 
 int cmd_kvm(int argc, const char **argv, const char *prefix __used)
 {
-       perf_host = perf_guest = 0;
+       perf_host  = 0;
+       perf_guest = 1;
 
        argc = parse_options(argc, argv, kvm_options, kvm_usage,
                        PARSE_OPT_STOP_AT_NON_OPTION);
index fa18370..3f16e08 100644 (file)
@@ -111,8 +111,11 @@ int perf_evlist__add_default(struct perf_evlist *evlist)
                .type = PERF_TYPE_HARDWARE,
                .config = PERF_COUNT_HW_CPU_CYCLES,
        };
-       struct perf_evsel *evsel = perf_evsel__new(&attr, 0);
+       struct perf_evsel *evsel;
+
+       event_attr_init(&attr);
 
+       evsel = perf_evsel__new(&attr, 0);
        if (evsel == NULL)
                goto error;
 
index 531c283..dcf999c 100644 (file)
@@ -838,6 +838,7 @@ int parse_events(struct perf_evlist *evlist , const char *str, int unset __used)
        for (;;) {
                ostr = str;
                memset(&attr, 0, sizeof(attr));
+               event_attr_init(&attr);
                ret = parse_event_symbols(evlist, &str, &attr);
                if (ret == EVT_FAILED)
                        return -1;
index 5b3ea49..8131410 100644 (file)
@@ -1,6 +1,21 @@
+#include "../perf.h"
 #include "util.h"
 #include <sys/mman.h>
 
+/*
+ * XXX We need to find a better place for these things...
+ */
+bool perf_host  = true;
+bool perf_guest = true;
+
+void event_attr_init(struct perf_event_attr *attr)
+{
+       if (!perf_host)
+               attr->exclude_host  = 1;
+       if (!perf_guest)
+               attr->exclude_guest = 1;
+}
+
 int mkdir_p(char *path, mode_t mode)
 {
        struct stat st;
index 37be34d..b9c530c 100644 (file)
@@ -242,6 +242,10 @@ int strtailcmp(const char *s1, const char *s2);
 unsigned long convert_unit(unsigned long value, char *unit);
 int readn(int fd, void *buf, size_t size);
 
+struct perf_event_attr;
+
+void event_attr_init(struct perf_event_attr *attr);
+
 #define _STR(x) #x
 #define STR(x) _STR(x)