summaryrefslogtreecommitdiff
path: root/simpleperf/utils.h
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2021-02-11 13:14:54 -0800
committerYabin Cui <yabinc@google.com>2021-02-12 12:10:44 -0800
commita89a374a357a915b4ea5083c32a3edd7097e1239 (patch)
tree5c9aee34c609b0c27555822783cbb55f6a75f86d /simpleperf/utils.h
parente5ad5804b3a25a0cbf9ea0750c66870b3e4b867e (diff)
downloadextras-a89a374a357a915b4ea5083c32a3edd7097e1239.tar.gz
simpleperf: add record filter options to record and monitor cmd.
The options support filtering records based on: process id, thread id, process name regex, thread name regex, and user id. Bug: 159157424 Test: run simpleperf_unit_test Test: run simpleperf manually Change-Id: Ife919d81cbe7672b5431dcdf60492956de2059a9
Diffstat (limited to 'simpleperf/utils.h')
-rw-r--r--simpleperf/utils.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/simpleperf/utils.h b/simpleperf/utils.h
index 1e3b52b3..3104cc2b 100644
--- a/simpleperf/utils.h
+++ b/simpleperf/utils.h
@@ -29,6 +29,8 @@
#include <android-base/logging.h>
#include <android-base/macros.h>
+#include <android-base/parseint.h>
+#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <ziparchive/zip_archive.h>
@@ -180,6 +182,20 @@ std::string GetSimpleperfVersion();
std::optional<std::set<int>> GetCpusFromString(const std::string& s);
std::optional<std::set<pid_t>> GetTidsFromString(const std::string& s, bool check_if_exists);
+template <typename T>
+std::optional<std::set<T>> ParseUintVector(const std::string& s) {
+ std::set<T> result;
+ T value;
+ for (const auto& p : android::base::Split(s, ",")) {
+ if (!android::base::ParseUint(p.c_str(), &value, std::numeric_limits<T>::max())) {
+ LOG(ERROR) << "Invalid Uint '" << p << "' in " << s;
+ return std::nullopt;
+ }
+ result.insert(value);
+ }
+ return result;
+}
+
// from boost::hash_combine
template <typename T>
static inline void HashCombine(size_t& seed, const T& val) {