summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libprofile/profile/profile_compilation_info.cc6
-rw-r--r--libprofile/profile/profile_compilation_info.h4
-rw-r--r--libprofile/profile/profile_compilation_info_test.cc52
-rw-r--r--profman/include/profman/profman_result.h2
-rw-r--r--profman/profile_assistant_test.cc4
-rw-r--r--profman/profman.cc6
6 files changed, 50 insertions, 24 deletions
diff --git a/libprofile/profile/profile_compilation_info.cc b/libprofile/profile/profile_compilation_info.cc
index af007d1962..d3bf475d0d 100644
--- a/libprofile/profile/profile_compilation_info.cc
+++ b/libprofile/profile/profile_compilation_info.cc
@@ -2477,8 +2477,8 @@ bool ProfileCompilationInfo::IsProfileFile(int fd) {
}
bool ProfileCompilationInfo::UpdateProfileKeys(
- const std::vector<std::unique_ptr<const DexFile>>& dex_files, /*out*/ bool* updated) {
- *updated = false;
+ const std::vector<std::unique_ptr<const DexFile>>& dex_files, /*out*/ bool* matched) {
+ *matched = false;
for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
for (const std::unique_ptr<DexFileData>& dex_data : info_) {
if (dex_data->checksum == dex_file->GetLocationChecksum() &&
@@ -2498,8 +2498,8 @@ bool ProfileCompilationInfo::UpdateProfileKeys(
// form the old key.
dex_data->profile_key = MigrateAnnotationInfo(new_profile_key, dex_data->profile_key);
profile_key_map_.Put(dex_data->profile_key, dex_data->profile_index);
- *updated = true;
}
+ *matched = true;
}
}
}
diff --git a/libprofile/profile/profile_compilation_info.h b/libprofile/profile/profile_compilation_info.h
index 57e80a5fbd..68177629b0 100644
--- a/libprofile/profile/profile_compilation_info.h
+++ b/libprofile/profile/profile_compilation_info.h
@@ -655,9 +655,9 @@ class ProfileCompilationInfo {
// If the new profile key would collide with an existing key (for a different dex)
// the method returns false. Otherwise it returns true.
//
- // `updated` is set to true if any profile key has been updated by this method.
+ // `matched` is set to true if any profile has matched any input dex file.
bool UpdateProfileKeys(const std::vector<std::unique_ptr<const DexFile>>& dex_files,
- /*out*/ bool* updated);
+ /*out*/ bool* matched);
// Checks if the profile is empty.
bool IsEmpty() const;
diff --git a/libprofile/profile/profile_compilation_info_test.cc b/libprofile/profile/profile_compilation_info_test.cc
index dc784189f9..81680041b5 100644
--- a/libprofile/profile/profile_compilation_info_test.cc
+++ b/libprofile/profile/profile_compilation_info_test.cc
@@ -956,9 +956,9 @@ TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOk) {
AddMethod(&info, dex2, /*method_idx=*/ 0);
// Update the profile keys based on the original dex files
- bool updated = false;
- ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &updated));
- ASSERT_TRUE(updated);
+ bool matched = false;
+ ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &matched));
+ ASSERT_TRUE(matched);
// Verify that we find the methods when searched with the original dex files.
for (const std::unique_ptr<const DexFile>& dex : dex_files) {
@@ -984,9 +984,9 @@ TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOkWithAnnotation) {
AddMethod(&info, dex2, /*method_idx=*/ 0, Hotness::kFlagHot, annotation);
// Update the profile keys based on the original dex files
- bool updated = false;
- ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &updated));
- ASSERT_TRUE(updated);
+ bool matched = false;
+ ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &matched));
+ ASSERT_TRUE(matched);
// Verify that we find the methods when searched with the original dex files.
for (const std::unique_ptr<const DexFile>& dex : dex_files) {
@@ -1001,7 +1001,33 @@ TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOkWithAnnotation) {
}
}
-TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOkButNoUpdate) {
+TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOkMatchedButNoUpdate) {
+ std::vector<std::unique_ptr<const DexFile>> dex_files;
+ dex_files.push_back(std::unique_ptr<const DexFile>(dex1));
+
+ // Both the checksum and the location match the original dex file.
+ ProfileCompilationInfo info;
+ AddMethod(&info, dex1, /*method_idx=*/0);
+
+ // No update should happen, but this should be considered as a happy case.
+ bool matched = false;
+ ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &matched));
+ ASSERT_TRUE(matched);
+
+ // Verify that we find the methods when searched with the original dex files.
+ for (const std::unique_ptr<const DexFile>& dex : dex_files) {
+ ProfileCompilationInfo::MethodHotness loaded_hotness =
+ GetMethod(info, dex.get(), /*method_idx=*/ 0);
+ ASSERT_TRUE(loaded_hotness.IsHot());
+ }
+
+ // Release the ownership as this is held by the test class;
+ for (std::unique_ptr<const DexFile>& dex : dex_files) {
+ UNUSED(dex.release());
+ }
+}
+
+TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOkButNoMatch) {
std::vector<std::unique_ptr<const DexFile>> dex_files;
dex_files.push_back(std::unique_ptr<const DexFile>(dex1));
@@ -1009,9 +1035,9 @@ TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyOkButNoUpdate) {
AddMethod(&info, dex2, /*method_idx=*/ 0);
// Update the profile keys based on the original dex files.
- bool updated = false;
- ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &updated));
- ASSERT_FALSE(updated);
+ bool matched = false;
+ ASSERT_TRUE(info.UpdateProfileKeys(dex_files, &matched));
+ ASSERT_FALSE(matched);
// Verify that we did not perform any update and that we cannot find anything with the new
// location.
@@ -1043,9 +1069,9 @@ TEST_F(ProfileCompilationInfoTest, UpdateProfileKeyFail) {
// This will cause the rename to fail because an existing entry would already have that name.
AddMethod(&info, dex1_renamed, /*method_idx=*/ 0);
- bool updated = false;
- ASSERT_FALSE(info.UpdateProfileKeys(dex_files, &updated));
- ASSERT_FALSE(updated);
+ bool matched = false;
+ ASSERT_FALSE(info.UpdateProfileKeys(dex_files, &matched));
+ ASSERT_FALSE(matched);
// Release the ownership as this is held by the test class;
for (std::unique_ptr<const DexFile>& dex : dex_files) {
diff --git a/profman/include/profman/profman_result.h b/profman/include/profman/profman_result.h
index 4d2b7336bb..9c9aca9e05 100644
--- a/profman/include/profman/profman_result.h
+++ b/profman/include/profman/profman_result.h
@@ -57,7 +57,7 @@ class ProfmanResult {
// The return codes of running profman with `--copy-and-update-profile-key`.
enum CopyAndUpdateResult {
kCopyAndUpdateSuccess = 0,
- kCopyAndUpdateNoUpdate = 21,
+ kCopyAndUpdateNoMatch = 21,
kCopyAndUpdateErrorFailedToUpdateProfile = 22,
kCopyAndUpdateErrorFailedToSaveProfile = 23,
kCopyAndUpdateErrorFailedToLoadProfile = 24,
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index 07f9ad9f26..d28ec6513d 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -2065,8 +2065,8 @@ TEST_F(ProfileAssistantTest, CopyAndUpdateProfileKeyNoUpdate) {
argv_str.push_back("--copy-and-update-profile-key");
std::string error;
- // Must return kCopyAndUpdateNoUpdate.
- ASSERT_EQ(ExecAndReturnCode(argv_str, &error), ProfmanResult::kCopyAndUpdateNoUpdate) << error;
+ // Must return kCopyAndUpdateNoMatch.
+ ASSERT_EQ(ExecAndReturnCode(argv_str, &error), ProfmanResult::kCopyAndUpdateNoMatch) << error;
// Verify that the content is the same.
ProfileCompilationInfo result;
diff --git a/profman/profman.cc b/profman/profman.cc
index 0259222119..a359d615ab 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -1909,8 +1909,8 @@ class ProfMan final {
// Open the dex files to look up classes and methods.
std::vector<std::unique_ptr<const DexFile>> dex_files;
OpenApkFilesFromLocations(&dex_files);
- bool updated = false;
- if (!profile.UpdateProfileKeys(dex_files, &updated)) {
+ bool matched = false;
+ if (!profile.UpdateProfileKeys(dex_files, &matched)) {
return ProfmanResult::kCopyAndUpdateErrorFailedToUpdateProfile;
}
bool result = use_fds
@@ -1919,7 +1919,7 @@ class ProfMan final {
if (!result) {
return ProfmanResult::kCopyAndUpdateErrorFailedToSaveProfile;
}
- return updated ? ProfmanResult::kCopyAndUpdateSuccess : ProfmanResult::kCopyAndUpdateNoUpdate;
+ return matched ? ProfmanResult::kCopyAndUpdateSuccess : ProfmanResult::kCopyAndUpdateNoMatch;
} else {
return ProfmanResult::kCopyAndUpdateErrorFailedToLoadProfile;
}