summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Calin Juravle <calin@google.com> 2019-11-14 09:01:11 -0800
committer Calin Juravle <calin@google.com> 2019-11-16 13:37:39 +0000
commitc0200a984cacb6c0911d046a018cd11c7d20646b (patch)
tree03a2ab5ac9cf40188d273e37e7648308bf84618c
parent283bb322de84ac570b987c65a1015e2dbcbfad7c (diff)
Improve profile merging error logging
Do not log an error if the profile version differs. This can happen when switching boot image profiling on/off and can lead to unhelpful logs. Test: profile tests Bug: 139884006 Change-Id: I4cef4accb786041338aa8c8b82892b70a02a4e03
-rw-r--r--profman/profile_assistant.cc17
-rw-r--r--profman/profile_assistant.h13
-rw-r--r--profman/profile_assistant_test.cc30
3 files changed, 49 insertions, 11 deletions
diff --git a/profman/profile_assistant.cc b/profman/profile_assistant.cc
index 531bb270cf..7107944d70 100644
--- a/profman/profile_assistant.cc
+++ b/profman/profile_assistant.cc
@@ -60,9 +60,20 @@ ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfilesInternal(
LOG(WARNING) << "Could not load profile file at index " << i;
return kErrorBadProfiles;
}
- if (options.IsBootImageMerge() != cur_info.IsForBootImage()) {
- // The app profile was not configured for boot image merging. Ignore.
- continue;
+
+ // Check version mismatch.
+ // This may happen during profile analysis if one profile is regular and
+ // the other one is for the boot image. For example when switching on-off
+ // the boot image profiles.
+ if (!info.SameVersion(cur_info)) {
+ if (options.IsForceMerge()) {
+ // If we have to merge forcefully, ignore the current profile and
+ // continue to the next one.
+ continue;
+ } else {
+ // Otherwise, return an error.
+ return kErrorDifferentVersions;
+ }
}
if (!info.MergeWith(cur_info)) {
diff --git a/profman/profile_assistant.h b/profman/profile_assistant.h
index c1d1cc1d0d..9aa0768c01 100644
--- a/profman/profile_assistant.h
+++ b/profman/profile_assistant.h
@@ -30,12 +30,13 @@ class ProfileAssistant {
// These also serve as return codes of profman and are processed by installd
// (frameworks/native/cmds/installd/commands.cpp)
enum ProcessingResult {
- kCompile = 0,
- kSkipCompilation = 1,
- kErrorBadProfiles = 2,
- kErrorIO = 3,
- kErrorCannotLock = 4,
- kSuccess = 5, // Generic success code for non-analysis runs.
+ kSuccess = 0, // Generic success code for non-analysis runs.
+ kCompile = 1,
+ kSkipCompilation = 2,
+ kErrorBadProfiles = 3,
+ kErrorIO = 4,
+ kErrorCannotLock = 5,
+ kErrorDifferentVersions = 6,
};
class Options {
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index 17819f021e..1717dd1187 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -193,7 +193,7 @@ class ProfileAssistantTest : public CommonRuntimeTest {
int ProcessProfiles(
const std::vector<int>& profiles_fd,
int reference_profile_fd,
- std::vector<const std::string> extra_args = std::vector<const std::string>()) {
+ const std::vector<const std::string>& extra_args = std::vector<const std::string>()) {
std::string profman_cmd = GetProfmanCmd();
std::vector<std::string> argv_str;
argv_str.push_back(profman_cmd);
@@ -1195,7 +1195,7 @@ TEST_F(ProfileAssistantTest, MergeProfilesWithFilter) {
argv_str.push_back("--apk-fd=" + std::to_string(apk_fd.get()));
std::string error;
- EXPECT_EQ(ExecAndReturnCode(argv_str, &error), 0) << error;
+ EXPECT_EQ(ExecAndReturnCode(argv_str, &error), ProfileAssistant::kCompile) << error;
// Verify that we can load the result.
@@ -1404,4 +1404,30 @@ TEST_F(ProfileAssistantTest, BootImageMergeWithAnnotations) {
ASSERT_TRUE(result.Load(reference_profile_fd));
ASSERT_TRUE(info.Equals(result));
}
+
+TEST_F(ProfileAssistantTest, DifferentProfileVersions) {
+ ScratchFile profile1;
+ ScratchFile profile2;
+
+ ProfileCompilationInfo info1(/*for_boot_image*/ false);
+ info1.Save(profile1.GetFd());
+ profile1.GetFile()->ResetOffset();
+
+ ProfileCompilationInfo info2(/*for_boot_image*/ true);
+ info2.Save(profile2.GetFd());
+ profile2.GetFile()->ResetOffset();
+
+ std::vector<int> profile_fds({ GetFd(profile1)});
+ int reference_profile_fd = GetFd(profile2);
+ ASSERT_EQ(ProcessProfiles(profile_fds, reference_profile_fd),
+ ProfileAssistant::kErrorDifferentVersions);
+
+ // Reverse the order of the profiles to verify we get the same behaviour.
+ profile_fds[0] = GetFd(profile2);
+ reference_profile_fd = GetFd(profile1);
+ profile1.GetFile()->ResetOffset();
+ profile2.GetFile()->ResetOffset();
+ ASSERT_EQ(ProcessProfiles(profile_fds, reference_profile_fd),
+ ProfileAssistant::kErrorDifferentVersions);
+}
} // namespace art