diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-10-21 13:15:05 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-09 02:18:45 -0700 |
commit | 3cafd26c1d26cbcacbb62e69acc8735e637c6e0a (patch) | |
tree | e488441c22b92a31eb52be7db3120dfc0ff892a0 /src | |
parent | 4731baf6d3a18857e86cc16de000bc42e84bf6de (diff) |
QBenchlib/Perf: parse multiple counters from -perfcounter
Change-Id: I3c79b7e08fa346988dfefffd17202ec98947308e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qbenchmarkperfevents.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp index 6808d465e2..9688836d81 100644 --- a/src/testlib/qbenchmarkperfevents.cpp +++ b/src/testlib/qbenchmarkperfevents.cpp @@ -409,27 +409,38 @@ void QBenchmarkPerfEventsMeasurer::setCounter(const char *name) { initPerf(); eventTypes->clear(); - 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 = strncmp(name, eventlist_strings + ptr->offset, n); - if (c == 0) + std::string_view input = name; + if (qsizetype idx = input.find(':'); idx >= 0) + input = input.substr(0, idx); + + while (!input.empty()) { + std::string_view countername = input; + if (qsizetype idx = countername.find(','); idx >= 0) + countername = countername.substr(0, idx); + + for (const Events *ptr = eventlist; ptr->type != PERF_TYPE_MAX; ++ptr) { + int c = countername.compare(eventlist_strings + ptr->offset); + if (c > 0) + continue; + if (c < 0) { + fprintf(stderr, "ERROR: Performance counter type '%.*s' is unknown\n", + int(countername.size()), countername.data()); + exit(1); + } + eventTypes->append({ ptr->type, ptr->event_id }); break; - if (c < 0) { - fprintf(stderr, "ERROR: Performance counter type '%s' is unknown\n", name); - exit(1); } - } - *eventTypes = { { ptr->type, ptr->event_id } }; + if (countername.size() == input.size()) + input = {}; + else + input.remove_prefix(countername.size() + 1); + } // We used to support attributes, but our code was the opposite of what // perf(1) does, plus QBenchlib isn't exactly expected to be used to // profile Linux kernel code or launch guest VMs as part of the workload. // So we keep accepting the colon as a delimiter but ignore it. - if (!colon) - return; } void QBenchmarkPerfEventsMeasurer::listCounters() |