diff options
author | Thiago Macieira <[email protected]> | 2024-09-19 16:57:32 -0700 |
---|---|---|
committer | Thiago Macieira <[email protected]> | 2024-10-11 11:52:19 -0700 |
commit | 31b4150dc3a789ffaf3f660151971127ac86510d (patch) | |
tree | aa9236e2822b58681ced8ce54256611ec9019061 | |
parent | f566b09ed7b71f47c477f8dfd306e568dac1936f (diff) |
QBenchmarkPerfEventsMeasurer: move the perf_event_attr data to the stack
There's no need for it to be a global variable. It needed to be global
because we configured the event globally before start(), but in commit
4731baf6d3a18857e86cc16de000bc42e84bf6de (6.5.0) we instead introduced
the Q_GLOBAL_STATIC with a QList containing the globally-configured
events.
This is using designated initializers despite their being a C++20
feature, because GCC and Clang have supported them as an extension to C+
+ for a long time. This file has needed that extension since that commit
anyway.
Pick-to: 6.8
Change-Id: I1c9080d23df9f7ba3cbafffd7eae7bd57cd69b67
Reviewed-by: Tor Arne Vestbø <[email protected]>
-rw-r--r-- | src/testlib/qbenchmarkperfevents.cpp | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp index 98224615f30..b42789ce590 100644 --- a/src/testlib/qbenchmarkperfevents.cpp +++ b/src/testlib/qbenchmarkperfevents.cpp @@ -53,26 +53,8 @@ struct PerfEvent quint32 type; quint64 config; }; -static perf_event_attr attr; Q_GLOBAL_STATIC(QList<PerfEvent>, eventTypes); -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 - - done = true; - } -} - static QList<PerfEvent> defaultCounters() { return { @@ -407,7 +389,6 @@ static QTest::QBenchmarkMetric metricForEvent(PerfEvent counter) void QBenchmarkPerfEventsMeasurer::setCounter(const char *name) { - initPerf(); eventTypes->clear(); std::string_view input = name; if (qsizetype idx = input.find(':'); idx >= 0) @@ -473,7 +454,18 @@ void QBenchmarkPerfEventsMeasurer::init() void QBenchmarkPerfEventsMeasurer::start() { - initPerf(); + QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers") + QT_WARNING_DISABLE_CLANG("-Wmissing-field-initializers") + perf_event_attr attr = { + .size = sizeof attr, + .read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING, + .disabled = true, // we'll enable later + .inherit = true, // let children processes inherit the monitoring + .pinned = true, // keep it running in the hardware + .inherit_stat = true, // aggregate all the info from child processes + .task = true, // trace fork/exits + }; + QList<PerfEvent> &counters = *eventTypes; if (counters.isEmpty()) counters = defaultCounters(); |