Skip to content

Commit 6d250fb

Browse files
authored
Merge pull request #9 from Liteom/dev
Fixed bug in EventProvider (Some configuration file have leading whitespaces: closes #8)
2 parents 75e5f62 + 2c2f8b6 commit 6d250fb

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/event_provider.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <perfcpp/time_event.h>
1111
#include <regex>
1212
#include <sstream>
13+
#include <cctype>
1314

1415
void
1516
perf::PerfSubsystemEventProvider::add_events(perf::CounterDefinition& counter_definition)
@@ -331,18 +332,21 @@ perf::SystemSpecificEventProvider::parse_event_file_descriptor_format(std::files
331332
std::optional<std::uint64_t>
332333
perf::SystemSpecificEventProvider::parse_integer(const std::string& value)
333334
{
334-
if (value.empty()) {
335+
std::string copied_str = value;
336+
copied_str.erase(std::remove_if(copied_str.begin(), copied_str.end(), [](unsigned char c){return std::isspace(c);}), copied_str.end());
337+
338+
if (copied_str.empty()) {
335339
return std::nullopt;
336340
}
337341

338342
/// Strings starting with '0x' are considered hex numbers.
339-
if (value.rfind("0x", 0ULL) == 0ULL) {
340-
return std::stoull(value.substr(2ULL), nullptr, 16);
343+
if (copied_str.rfind("0x", 0ULL) == 0ULL) {
344+
return std::stoull(copied_str.substr(2ULL), nullptr, 16);
341345
}
342346

343347
/// Strings containing digits are considered dec numbers.
344-
if (std::all_of(value.begin(), value.end(), [](const auto c) { return std::isdigit(c); })) {
345-
return std::stoull(value, nullptr, 0);
348+
if (std::all_of(copied_str.begin(), copied_str.end(), [](const auto c) { return std::isdigit(c); })) {
349+
return std::stoull(copied_str, nullptr, 0);
346350
}
347351

348352
return std::nullopt;
@@ -482,7 +486,7 @@ perf::CsvFileEventProvider::add_events(perf::CounterDefinition& counter_definiti
482486
auto line_stream = std::istringstream{ line };
483487

484488
std::string name;
485-
489+
486490
/// Read name.
487491
if (std::getline(line_stream, name, ','); !name.empty()) {
488492

@@ -522,4 +526,4 @@ perf::CsvFileEventProvider::add_events(perf::CounterDefinition& counter_definiti
522526
}
523527
}
524528
}
525-
}
529+
}

0 commit comments

Comments
 (0)