summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-04-09 18:22:38 -0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-06 21:50:28 +0100
commit3963ab9d7370083445e7f0ff506ab196669ae267 (patch)
tree69a43d2dd9bb57364ffd040cb304287d46c0f6ce /src
parent914b56dbf5f8ff96981cff58d5b9293e6463e379 (diff)
Store the performance counter attributes globally
This will allow us to modify more attributes from the command-line Change-Id: I84d4933cbfa2b69c4e1009eaf3e005cfc3e7e01c Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qbenchmarkperfevents.cpp49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp
index 3fd8ea92fb..f5dae0bf5a 100644
--- a/src/testlib/qbenchmarkperfevents.cpp
+++ b/src/testlib/qbenchmarkperfevents.cpp
@@ -84,8 +84,28 @@
QT_BEGIN_NAMESPACE
-static quint32 event_type = PERF_TYPE_HARDWARE;
-static quint64 event_id = PERF_COUNT_HW_CPU_CYCLES;
+static perf_event_attr attr;
+
+static void initPerf()
+{
+ static bool done;
+ if (!done) {
+ memset(&attr, 0, sizeof attr);
+ attr.size = sizeof attr;
+ attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
+ attr.disabled = true; // we'll enable later
+ attr.inherit = true; // let children processes inherit the monitoring
+ attr.pinned = true; // keep it running in the hardware
+ attr.inherit_stat = true; // aggregate all the info from child processes
+ attr.task = true; // trace fork/exits
+
+ // set a default performance counter: CPU cycles
+ attr.type = PERF_TYPE_HARDWARE;
+ attr.config = PERF_COUNT_HW_CPU_CYCLES; // default
+
+ done = true;
+ }
+}
/*!
\class QBenchmarkPerfEvents
@@ -397,6 +417,7 @@ QTest::QBenchmarkMetric QBenchmarkPerfEventsMeasurer::metricForEvent(quint32 typ
void QBenchmarkPerfEventsMeasurer::setCounter(const char *name)
{
+ initPerf();
const Events *ptr = eventlist;
for ( ; ptr->type != PERF_TYPE_MAX; ++ptr) {
int c = strcmp(name, eventlist_strings + ptr->offset);
@@ -408,8 +429,8 @@ void QBenchmarkPerfEventsMeasurer::setCounter(const char *name)
}
}
- ::event_type = ptr->type;
- ::event_id = ptr->event_id;
+ attr.type = ptr->type;
+ attr.config = ptr->event_id;
}
void QBenchmarkPerfEventsMeasurer::listCounters()
@@ -445,24 +466,8 @@ void QBenchmarkPerfEventsMeasurer::init()
void QBenchmarkPerfEventsMeasurer::start()
{
- perf_event_attr attr;
- memset(&attr, 0, sizeof attr);
-
- // common init
- attr.size = sizeof attr;
- attr.sample_period = 0;
- attr.sample_type = 0;
- attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
- attr.disabled = true; // start disabled, we'll enable later
- attr.inherit = true; // let children inherit, if the benchmark has child processes
- attr.pinned = true; // keep it running on the PMU
- attr.inherit_stat = true; // collapse all the info from child processes
- attr.task = true; // trace fork and exit
-
- // our event type
- attr.type = ::event_type;
- attr.config = ::event_id;
+ initPerf();
// pid == 0 -> attach to the current process
// cpu == -1 -> monitor on all CPUs
// group_fd == -1 -> this is the group leader
@@ -512,7 +517,7 @@ int QBenchmarkPerfEventsMeasurer::adjustMedianCount(int)
QTest::QBenchmarkMetric QBenchmarkPerfEventsMeasurer::metricType()
{
- return metricForEvent(event_type, event_id);
+ return metricForEvent(attr.type, attr.config);
}
static quint64 rawReadValue(int fd)