diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-04-09 18:35:49 -0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-06 21:50:28 +0100 |
commit | 408fa1e2b9c4c9310279388285342cb25ccbda17 (patch) | |
tree | 09977cd7499beb6004c89aec2af5f55cd04f71a7 /src/testlib/qbenchmarkperfevents.cpp | |
parent | 3963ab9d7370083445e7f0ff506ab196669ae267 (diff) |
Add support for attributes in the -perfcounter argument
Five attributes are supported, matching what the perf(1) tool
supports. The 'p' attribute (precise IP reporting) wasn't added
because we don't do assembly-level debugging with benchlib.
Change-Id: I726f735a5bcc0c97e62cde0fbe0843597068ad7c
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/testlib/qbenchmarkperfevents.cpp')
-rw-r--r-- | src/testlib/qbenchmarkperfevents.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp index f5dae0bf5a..e3034d1f94 100644 --- a/src/testlib/qbenchmarkperfevents.cpp +++ b/src/testlib/qbenchmarkperfevents.cpp @@ -53,6 +53,7 @@ #include <errno.h> #include <fcntl.h> #include <string.h> +#include <stdio.h> #include <sys/syscall.h> #include <sys/ioctl.h> @@ -418,9 +419,11 @@ QTest::QBenchmarkMetric QBenchmarkPerfEventsMeasurer::metricForEvent(quint32 typ void QBenchmarkPerfEventsMeasurer::setCounter(const char *name) { initPerf(); + const char *colon = strchr(name, ':'); + int n = colon ? colon - name : strlen(name); const Events *ptr = eventlist; for ( ; ptr->type != PERF_TYPE_MAX; ++ptr) { - int c = strcmp(name, eventlist_strings + ptr->offset); + int c = strncmp(name, eventlist_strings + ptr->offset, n); if (c == 0) break; if (c < 0) { @@ -431,6 +434,32 @@ void QBenchmarkPerfEventsMeasurer::setCounter(const char *name) attr.type = ptr->type; attr.config = ptr->event_id; + + // now parse the attributes + if (!colon) + return; + while (*++colon) { + switch (*colon) { + case 'u': + attr.exclude_user = true; + break; + case 'k': + attr.exclude_kernel = true; + break; + case 'h': + attr.exclude_hv = true; + break; + case 'G': + attr.exclude_guest = true; + break; + case 'H': + attr.exclude_host = true; + break; + default: + fprintf(stderr, "ERROR: Unknown attribute '%c'\n", *colon); + exit(1); + } + } } void QBenchmarkPerfEventsMeasurer::listCounters() @@ -448,6 +477,14 @@ void QBenchmarkPerfEventsMeasurer::listCounters() ptr->type == PERF_TYPE_SOFTWARE ? "software" : ptr->type == PERF_TYPE_HW_CACHE ? "cache" : "other"); } + + printf("\nAttributes can be specified by adding a colon and the following:\n" + " u - exclude measuring in the userspace\n" + " k - exclude measuring in kernel mode\n" + " h - exclude measuring in the hypervisor\n" + " G - exclude measuring when running virtualized (guest VM)\n" + " H - exclude measuring when running non-virtualized (host system)\n" + "Attributes can be combined, for example: -perfcounter branch-mispredicts:kh\n"); } QBenchmarkPerfEventsMeasurer::QBenchmarkPerfEventsMeasurer() |