profman: Move min new classes and methods limit to argument.
Cherry-pick from 6760f0d7c3d14b5bc54f431b9fdde1d68b4a51ad
This will allow an easy change to these value from framework.
Bug: 172490638
Test: run art_profman_tests
Change-Id: Iab027f7cbf5da0c14b2854900384df93c3a3e2e7
Merged-In: Iab027f7cbf5da0c14b2854900384df93c3a3e2e7
diff --git a/profman/profile_assistant.cc b/profman/profile_assistant.cc
index 1695d8c..ba5be4d 100644
--- a/profman/profile_assistant.cc
+++ b/profman/profile_assistant.cc
@@ -24,9 +24,7 @@
// Minimum number of new methods/classes that profiles
// must contain to enable recompilation.
static constexpr const uint32_t kMinNewMethodsForCompilation = 100;
-static constexpr const uint32_t kMinNewMethodsPercentChangeForCompilation = 2;
static constexpr const uint32_t kMinNewClassesForCompilation = 50;
-static constexpr const uint32_t kMinNewClassesPercentChangeForCompilation = 2;
ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfilesInternal(
@@ -91,10 +89,10 @@
// If we perform a forced merge do not analyze the difference between profiles.
if (!options.IsForceMerge()) {
uint32_t min_change_in_methods_for_compilation = std::max(
- (kMinNewMethodsPercentChangeForCompilation * number_of_methods) / 100,
+ (options.GetMinNewMethodsPercentChangeForCompilation() * number_of_methods) / 100,
kMinNewMethodsForCompilation);
uint32_t min_change_in_classes_for_compilation = std::max(
- (kMinNewClassesPercentChangeForCompilation * number_of_classes) / 100,
+ (options.GetMinNewClassesPercentChangeForCompilation() * number_of_classes) / 100,
kMinNewClassesForCompilation);
// Check if there is enough new information added by the current profiles.
if (((info.GetNumberOfMethods() - number_of_methods) < min_change_in_methods_for_compilation) &&
diff --git a/profman/profile_assistant.h b/profman/profile_assistant.h
index 9aa0768..60641cd 100644
--- a/profman/profile_assistant.h
+++ b/profman/profile_assistant.h
@@ -43,17 +43,35 @@
public:
static constexpr bool kForceMergeDefault = false;
static constexpr bool kBootImageMergeDefault = false;
+ static constexpr uint32_t kMinNewMethodsPercentChangeForCompilation = 2;
+ static constexpr uint32_t kMinNewClassesPercentChangeForCompilation = 2;
Options()
: force_merge_(kForceMergeDefault),
- boot_image_merge_(kBootImageMergeDefault) {
+ boot_image_merge_(kBootImageMergeDefault),
+ min_new_methods_percent_change_for_compilation_(
+ kMinNewMethodsPercentChangeForCompilation),
+ min_new_classes_percent_change_for_compilation_(
+ kMinNewClassesPercentChangeForCompilation) {
}
bool IsForceMerge() const { return force_merge_; }
bool IsBootImageMerge() const { return boot_image_merge_; }
+ uint32_t GetMinNewMethodsPercentChangeForCompilation() const {
+ return min_new_methods_percent_change_for_compilation_;
+ }
+ uint32_t GetMinNewClassesPercentChangeForCompilation() const {
+ return min_new_classes_percent_change_for_compilation_;
+ }
void SetForceMerge(bool value) { force_merge_ = value; }
void SetBootImageMerge(bool value) { boot_image_merge_ = value; }
+ void SetMinNewMethodsPercentChangeForCompilation(uint32_t value) {
+ min_new_methods_percent_change_for_compilation_ = value;
+ }
+ void SetMinNewClassesPercentChangeForCompilation(uint32_t value) {
+ min_new_classes_percent_change_for_compilation_ = value;
+ }
private:
// If true, performs a forced merge, without analyzing if there is a
@@ -63,6 +81,8 @@
// Signals that the merge is for boot image profiles. It will ignore differences
// in profile versions (instead of aborting).
bool boot_image_merge_;
+ uint32_t min_new_methods_percent_change_for_compilation_;
+ uint32_t min_new_classes_percent_change_for_compilation_;
};
// Process the profile information present in the given files. Returns one of
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index c289ae6..39a25e3 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -360,7 +360,9 @@
}
int CheckCompilationMethodPercentChange(uint16_t methods_in_cur_profile,
- uint16_t methods_in_ref_profile) {
+ uint16_t methods_in_ref_profile,
+ const std::vector<const std::string>& extra_args =
+ std::vector<const std::string>()) {
ScratchFile profile;
ScratchFile reference_profile;
std::vector<int> profile_fds({ GetFd(profile)});
@@ -380,11 +382,13 @@
ProfileCompilationInfo info2;
SetupBasicProfile(dex1, hot_methods_ref, empty_vector, empty_vector,
reference_profile, &info2);
- return ProcessProfiles(profile_fds, reference_profile_fd);
+ return ProcessProfiles(profile_fds, reference_profile_fd, extra_args);
}
int CheckCompilationClassPercentChange(uint16_t classes_in_cur_profile,
- uint16_t classes_in_ref_profile) {
+ uint16_t classes_in_ref_profile,
+ const std::vector<const std::string>& extra_args =
+ std::vector<const std::string>()) {
ScratchFile profile;
ScratchFile reference_profile;
@@ -395,7 +399,7 @@
SetupProfile(dex1, dex2, 0, classes_in_cur_profile, profile, &info1);
ProfileCompilationInfo info2;
SetupProfile(dex1, dex2, 0, classes_in_ref_profile, reference_profile, &info2);
- return ProcessProfiles(profile_fds, reference_profile_fd);
+ return ProcessProfiles(profile_fds, reference_profile_fd, extra_args);
}
std::unique_ptr<ArenaAllocator> allocator_;
@@ -572,6 +576,18 @@
kNumberOfMethodsInRefProfile));
}
+TEST_F(ProfileAssistantTest, DoNotAdviseCompilationMethodPercentageWithNewMin) {
+ const uint16_t kNumberOfMethodsInRefProfile = 6000;
+ const uint16_t kNumberOfMethodsInCurProfile = 6200; // Threshold is 20%.
+ std::vector<const std::string> extra_args({"--min-new-methods-percent-change=20"});
+
+ // We should not advise compilation.
+ ASSERT_EQ(ProfileAssistant::kSkipCompilation,
+ CheckCompilationMethodPercentChange(kNumberOfMethodsInCurProfile,
+ kNumberOfMethodsInRefProfile,
+ extra_args));
+}
+
TEST_F(ProfileAssistantTest, DoNotdviseCompilationClassPercentage) {
const uint16_t kNumberOfClassesInRefProfile = 6000;
const uint16_t kNumberOfClassesInCurProfile = 6110; // Threshold is 2%.
@@ -590,6 +606,18 @@
kNumberOfClassesInRefProfile));
}
+TEST_F(ProfileAssistantTest, DoNotAdviseCompilationClassPercentageWithNewMin) {
+ const uint16_t kNumberOfClassesInRefProfile = 6000;
+ const uint16_t kNumberOfClassesInCurProfile = 6200; // Threshold is 20%.
+ std::vector<const std::string> extra_args({"--min-new-classes-percent-change=20"});
+
+ // We should not advise compilation.
+ ASSERT_EQ(ProfileAssistant::kSkipCompilation,
+ CheckCompilationClassPercentChange(kNumberOfClassesInCurProfile,
+ kNumberOfClassesInRefProfile,
+ extra_args));
+}
+
TEST_F(ProfileAssistantTest, FailProcessingBecauseOfProfiles) {
ScratchFile profile1;
ScratchFile profile2;
diff --git a/profman/profman.cc b/profman/profman.cc
index 2adf61f..f8e4184 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -179,6 +179,10 @@
UsageError(" In this case, the reference profile must have a boot profile version.");
UsageError(" --force-merge: performs a forced merge, without analyzing if there is a");
UsageError(" significant difference between the current profile and the reference profile.");
+ UsageError(" --min-new-methods-percent-change=percentage between 0 and 100");
+ UsageError(" the min percent of new methods to trigger a compilation.");
+ UsageError(" --min-new-classes-percent-change=percentage between 0 and 100");
+ UsageError(" the min percent of new classes to trigger a compilation.");
UsageError("");
exit(EXIT_FAILURE);
@@ -406,6 +410,24 @@
&test_profile_class_percentage_);
} else if (StartsWith(option, "--generate-test-profile-seed=")) {
ParseUintOption(raw_option, "--generate-test-profile-seed=", &test_profile_seed_);
+ } else if (StartsWith(option, "--min-new-methods-percent-change=")) {
+ uint32_t min_new_methods_percent_change;
+ ParseUintOption(raw_option,
+ "--min-new-methods-percent-change=",
+ &min_new_methods_percent_change,
+ 0u,
+ 100u);
+ profile_assistant_options_.SetMinNewMethodsPercentChangeForCompilation(
+ min_new_methods_percent_change);
+ } else if (StartsWith(option, "--min-new-classes-percent-change=")) {
+ uint32_t min_new_classes_percent_change;
+ ParseUintOption(raw_option,
+ "--min-new-classes-percent-change=",
+ &min_new_classes_percent_change,
+ 0u,
+ 100u);
+ profile_assistant_options_.SetMinNewClassesPercentChangeForCompilation(
+ min_new_classes_percent_change);
} else if (option == "--copy-and-update-profile-key") {
copy_and_update_profile_key_ = true;
} else if (option == "--boot-image-merge") {