summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2021-05-13 00:24:34 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-05-13 00:24:34 +0000
commit11e23c2b352a87399141d999889c093465adbf8c (patch)
treee83a04e32583b5616eb2e25cab9b367953e56ff4
parent447d6d09dcd4bbe4a4609c7c5ad0b22fba607f95 (diff)
parente24743149158721c49d57b08978b561d586e6884 (diff)
downloadextras-11e23c2b352a87399141d999889c093465adbf8c.tar.gz
Merge changes If4c37940,I009c8bef am: f071884b31 am: 2e3eec2b76 am: 706411fa75 am: e247431491
Original change: https://android-review.googlesource.com/c/platform/system/extras/+/1704686 Change-Id: Ia149dd4dc20099a09b28dd20390fc11d3e6b01fb
-rw-r--r--simpleperf/cmd_monitor.cpp2
-rw-r--r--simpleperf/cmd_record.cpp17
-rw-r--r--simpleperf/cmd_record_impl.h2
-rw-r--r--simpleperf/cmd_record_test.cpp41
-rw-r--r--simpleperf/environment.cpp29
-rw-r--r--simpleperf/environment.h10
6 files changed, 83 insertions, 18 deletions
diff --git a/simpleperf/cmd_monitor.cpp b/simpleperf/cmd_monitor.cpp
index 2c9dea0c..50f055e1 100644
--- a/simpleperf/cmd_monitor.cpp
+++ b/simpleperf/cmd_monitor.cpp
@@ -470,7 +470,7 @@ bool MonitorCommand::AdjustPerfEventLimit() {
set_prop = true;
}
- if (GetAndroidVersion() >= kAndroidVersionP + 1 && set_prop) {
+ if (GetAndroidVersion() >= kAndroidVersionQ && set_prop) {
return SetPerfEventLimits(std::max(max_sample_freq_, cur_max_freq), cpu_time_max_percent_,
std::max(mlock_kb, cur_mlock_kb));
}
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index 34a8c0c5..2e646bb4 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -281,6 +281,7 @@ RECORD_FILTER_OPTION_HELP_MSG
"--symfs <dir> Look for files with symbols relative to this directory.\n"
" This option is used to provide files with symbol table and\n"
" debug information, which are used for unwinding and dumping symbols.\n"
+"--add-meta-info key=value Add extra meta info, which will be stored in the recording file.\n"
"\n"
"Other options:\n"
"--exit-with-parent Stop recording when the process starting\n"
@@ -432,6 +433,8 @@ RECORD_FILTER_OPTION_HELP_MSG
std::optional<MapRecordReader> map_record_reader_;
std::optional<MapRecordThread> map_record_thread_;
+
+ std::unordered_map<std::string, std::string> extra_meta_info_;
};
bool RecordCommand::Run(const std::vector<std::string>& args) {
@@ -799,6 +802,16 @@ bool RecordCommand::ParseOptions(const std::vector<std::string>& args,
// Process options.
system_wide_collection_ = options.PullBoolValue("-a");
+ for (const OptionValue& value : options.PullValues("--add-meta-info")) {
+ const std::string& s = *value.str_value;
+ auto split_pos = s.find('=');
+ if (split_pos == std::string::npos || split_pos == 0 || split_pos + 1 == s.size()) {
+ LOG(ERROR) << "invalid meta-info: " << s;
+ return false;
+ }
+ extra_meta_info_[s.substr(0, split_pos)] = s.substr(split_pos + 1);
+ }
+
if (auto value = options.PullValue("--addr-filter"); value) {
auto filters = ParseAddrFilterOption(*value->str_value);
if (filters.empty()) {
@@ -1149,7 +1162,7 @@ bool RecordCommand::AdjustPerfEventLimit() {
set_prop = true;
}
- if (GetAndroidVersion() >= kAndroidVersionP + 1 && set_prop && !in_app_context_) {
+ if (GetAndroidVersion() >= kAndroidVersionQ && set_prop && !in_app_context_) {
return SetPerfEventLimits(std::max(max_sample_freq_, cur_max_freq), cpu_time_max_percent_,
std::max(mlock_kb, cur_mlock_kb));
}
@@ -1888,7 +1901,7 @@ bool RecordCommand::DumpFileFeature() {
}
bool RecordCommand::DumpMetaInfoFeature(bool kernel_symbols_available) {
- std::unordered_map<std::string, std::string> info_map;
+ std::unordered_map<std::string, std::string> info_map = extra_meta_info_;
info_map["simpleperf_version"] = GetSimpleperfVersion();
info_map["system_wide_collection"] = system_wide_collection_ ? "true" : "false";
info_map["trace_offcpu"] = trace_offcpu_ ? "true" : "false";
diff --git a/simpleperf/cmd_record_impl.h b/simpleperf/cmd_record_impl.h
index 6753ab92..6164297a 100644
--- a/simpleperf/cmd_record_impl.h
+++ b/simpleperf/cmd_record_impl.h
@@ -33,6 +33,8 @@ inline const OptionFormatMap& GetRecordCmdOptionFormats() {
if (option_formats.empty()) {
option_formats = {
{"-a", {OptionValueType::NONE, OptionType::SINGLE, AppRunnerType::NOT_ALLOWED}},
+ {"--add-meta-info",
+ {OptionValueType::STRING, OptionType::MULTIPLE, AppRunnerType::ALLOWED}},
{"--addr-filter", {OptionValueType::STRING, OptionType::SINGLE, AppRunnerType::ALLOWED}},
{"--app", {OptionValueType::STRING, OptionType::SINGLE, AppRunnerType::NOT_ALLOWED}},
{"--aux-buffer-size", {OptionValueType::UINT, OptionType::SINGLE, AppRunnerType::ALLOWED}},
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index fa719b45..3e0b9e1a 100644
--- a/simpleperf/cmd_record_test.cpp
+++ b/simpleperf/cmd_record_test.cpp
@@ -720,7 +720,7 @@ class RecordingAppHelper {
TemporaryFile perf_data_file_;
};
-static void TestRecordingApps(const std::string& app_name) {
+static void TestRecordingApps(const std::string& app_name, const std::string& app_type) {
RecordingAppHelper helper;
// Bring the app to foreground to avoid no samples.
ASSERT_TRUE(helper.StartApp("am start " + app_name + "/.MainActivity"));
@@ -736,20 +736,32 @@ static void TestRecordingApps(const std::string& app_name) {
strstr(name, expected_method_name.c_str()) != nullptr;
};
ASSERT_TRUE(helper.CheckData(process_symbol));
+
+ // Check app_package_name and app_type.
+ auto reader = RecordFileReader::CreateInstance(helper.GetDataPath());
+ ASSERT_TRUE(reader);
+ const std::unordered_map<std::string, std::string>& meta_info = reader->GetMetaInfoFeature();
+ auto it = meta_info.find("app_package_name");
+ ASSERT_NE(it, meta_info.end());
+ ASSERT_EQ(it->second, app_name);
+ it = meta_info.find("app_type");
+ ASSERT_NE(it, meta_info.end());
+ ASSERT_EQ(it->second, app_type);
}
TEST(record_cmd, app_option_for_debuggable_app) {
TEST_REQUIRE_APPS();
SetRunInAppToolForTesting(true, false);
- TestRecordingApps("com.android.simpleperf.debuggable");
+ TestRecordingApps("com.android.simpleperf.debuggable", "debuggable");
SetRunInAppToolForTesting(false, true);
- TestRecordingApps("com.android.simpleperf.debuggable");
+ // Although the app is actually debuggable, we profile the app using simpleperf_app_runner.
+ TestRecordingApps("com.android.simpleperf.debuggable", "profileable");
}
TEST(record_cmd, app_option_for_profileable_app) {
TEST_REQUIRE_APPS();
SetRunInAppToolForTesting(false, true);
- TestRecordingApps("com.android.simpleperf.profileable");
+ TestRecordingApps("com.android.simpleperf.profileable", "profileable");
}
#if defined(__ANDROID__)
@@ -1144,3 +1156,24 @@ TEST(record_cmd, kernel_address_warning) {
ASSERT_NE(pos, std::string::npos);
ASSERT_EQ(output.find(warning_msg, pos + warning_msg.size()), std::string::npos);
}
+
+TEST(record_cmd, add_meta_info_option) {
+ TemporaryFile tmpfile;
+ ASSERT_TRUE(RunRecordCmd({"--add-meta-info", "key1=value1", "--add-meta-info", "key2=value2"},
+ tmpfile.path));
+ auto reader = RecordFileReader::CreateInstance(tmpfile.path);
+ ASSERT_TRUE(reader);
+
+ const std::unordered_map<std::string, std::string>& meta_info = reader->GetMetaInfoFeature();
+ auto it = meta_info.find("key1");
+ ASSERT_NE(it, meta_info.end());
+ ASSERT_EQ(it->second, "value1");
+ it = meta_info.find("key2");
+ ASSERT_NE(it, meta_info.end());
+ ASSERT_EQ(it->second, "value2");
+
+ // Report error for invalid meta info.
+ ASSERT_FALSE(RunRecordCmd({"--add-meta-info", "key1"}, tmpfile.path));
+ ASSERT_FALSE(RunRecordCmd({"--add-meta-info", "key1="}, tmpfile.path));
+ ASSERT_FALSE(RunRecordCmd({"--add-meta-info", "=value1"}, tmpfile.path));
+}
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index 4bd992c6..4fe908fa 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -674,14 +674,21 @@ class RunAs : public InAppRunner {
protected:
std::vector<std::string> GetPrefixArgs(const std::string& cmd) {
- return {"run-as",
- package_name_,
- "--user",
- user_id_,
- simpleperf_copied_in_app_ ? "./simpleperf" : simpleperf_path_,
- cmd,
- "--app",
- package_name_};
+ std::vector<std::string> args = {"run-as",
+ package_name_,
+ "--user",
+ user_id_,
+ simpleperf_copied_in_app_ ? "./simpleperf" : simpleperf_path_,
+ cmd,
+ "--app",
+ package_name_};
+ if (cmd == "record") {
+ if (simpleperf_copied_in_app_ || GetAndroidVersion() >= kAndroidVersionS) {
+ args.emplace_back("--add-meta-info");
+ args.emplace_back("app_type=debuggable");
+ }
+ }
+ return args;
}
bool simpleperf_copied_in_app_ = false;
@@ -717,7 +724,7 @@ class SimpleperfAppRunner : public InAppRunner {
public:
SimpleperfAppRunner(int user_id, const std::string& package_name)
: InAppRunner(user_id, package_name) {}
- bool Prepare() override { return GetAndroidVersion() >= kAndroidVersionP + 1; }
+ bool Prepare() override { return GetAndroidVersion() >= kAndroidVersionQ; }
protected:
std::vector<std::string> GetPrefixArgs(const std::string& cmd) {
@@ -727,6 +734,10 @@ class SimpleperfAppRunner : public InAppRunner {
args.emplace_back(user_id_);
}
args.emplace_back(cmd);
+ if (cmd == "record" && GetAndroidVersion() >= kAndroidVersionS) {
+ args.emplace_back("--add-meta-info");
+ args.emplace_back("app_type=profileable");
+ }
return args;
}
};
diff --git a/simpleperf/environment.h b/simpleperf/environment.h
index f653a049..665a7c53 100644
--- a/simpleperf/environment.h
+++ b/simpleperf/environment.h
@@ -114,12 +114,18 @@ class ScopedTempFiles {
};
bool SignalIsIgnored(int signo);
+
+enum {
+ kAndroidVersionP = 9,
+ kAndroidVersionQ = 10,
+ kAndroidVersionR = 11,
+ kAndroidVersionS = 12,
+};
+
// Return 0 if no android version.
int GetAndroidVersion();
std::optional<std::pair<int, int>> GetKernelVersion();
-constexpr int kAndroidVersionP = 9;
-
std::string GetHardwareFromCpuInfo(const std::string& cpu_info);
bool MappedFileOnlyExistInMemory(const char* filename);