summaryrefslogtreecommitdiff
path: root/simpleperf/RecordFilter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'simpleperf/RecordFilter.cpp')
-rw-r--r--simpleperf/RecordFilter.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/simpleperf/RecordFilter.cpp b/simpleperf/RecordFilter.cpp
index 7818d32b..34054286 100644
--- a/simpleperf/RecordFilter.cpp
+++ b/simpleperf/RecordFilter.cpp
@@ -248,8 +248,8 @@ RecordFilter::~RecordFilter() {}
bool RecordFilter::ParseOptions(OptionValueMap& options) {
for (bool exclude : {true, false}) {
std::string prefix = exclude ? "--exclude-" : "--include-";
- for (const OptionValue& value : options.PullValues(prefix + "pid")) {
- if (auto pids = GetTidsFromString(*value.str_value, false); pids) {
+ if (auto strs = options.PullStringValues(prefix + "pid"); !strs.empty()) {
+ if (auto pids = GetPidsFromStrings(strs, false, false); pids) {
AddPids(pids.value(), exclude);
} else {
return false;
@@ -263,10 +263,14 @@ bool RecordFilter::ParseOptions(OptionValueMap& options) {
}
}
for (const OptionValue& value : options.PullValues(prefix + "process-name")) {
- AddProcessNameRegex(*value.str_value, exclude);
+ if (!AddProcessNameRegex(*value.str_value, exclude)) {
+ return false;
+ }
}
for (const OptionValue& value : options.PullValues(prefix + "thread-name")) {
- AddThreadNameRegex(*value.str_value, exclude);
+ if (!AddThreadNameRegex(*value.str_value, exclude)) {
+ return false;
+ }
}
for (const OptionValue& value : options.PullValues(prefix + "uid")) {
if (auto uids = ParseUintVector<uint32_t>(*value.str_value); uids) {
@@ -296,16 +300,24 @@ void RecordFilter::AddTids(const std::set<pid_t>& tids, bool exclude) {
cond.tids.insert(tids.begin(), tids.end());
}
-void RecordFilter::AddProcessNameRegex(const std::string& process_name, bool exclude) {
+bool RecordFilter::AddProcessNameRegex(const std::string& process_name, bool exclude) {
RecordFilterCondition& cond = GetCondition(exclude);
cond.used = true;
- cond.process_name_regs.emplace_back(process_name, std::regex::optimize);
+ if (auto regex = RegEx::Create(process_name); regex != nullptr) {
+ cond.process_name_regs.emplace_back(std::move(regex));
+ return true;
+ }
+ return false;
}
-void RecordFilter::AddThreadNameRegex(const std::string& thread_name, bool exclude) {
+bool RecordFilter::AddThreadNameRegex(const std::string& thread_name, bool exclude) {
RecordFilterCondition& cond = GetCondition(exclude);
cond.used = true;
- cond.thread_name_regs.emplace_back(thread_name, std::regex::optimize);
+ if (auto regex = RegEx::Create(thread_name); regex != nullptr) {
+ cond.thread_name_regs.emplace_back(std::move(regex));
+ return true;
+ }
+ return false;
}
void RecordFilter::AddUids(const std::set<uint32_t>& uids, bool exclude) {
@@ -382,9 +394,10 @@ bool RecordFilter::CheckCondition(const SampleRecord* r, const RecordFilterCondi
return false;
}
-bool RecordFilter::SearchInRegs(const std::string& s, const std::vector<std::regex>& regs) {
+bool RecordFilter::SearchInRegs(std::string_view s,
+ const std::vector<std::unique_ptr<RegEx>>& regs) {
for (auto& reg : regs) {
- if (std::regex_search(s, reg)) {
+ if (reg->Search(s)) {
return true;
}
}