Loading cmds/installd/dexopt.cpp +45 −13 Original line number Diff line number Diff line Loading @@ -715,13 +715,20 @@ static constexpr int PROFMAN_BIN_RETURN_CODE_BAD_PROFILES = 2; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_IO = 3; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>* apk_fds = nullptr) { static void run_profman(const std::vector<unique_fd>& profile_fds, const unique_fd& reference_profile_fd, const std::vector<unique_fd>* apk_fds, bool copy_and_update) { const char* profman_bin = is_debug_runtime() ? "/system/bin/profmand" : "/system/bin/profman"; std::vector<std::string> profile_args(profiles_fd.size()); for (size_t k = 0; k < profiles_fd.size(); k++) { profile_args[k] = "--profile-file-fd=" + std::to_string(profiles_fd[k].get()); if (copy_and_update) { CHECK_EQ(1u, profile_fds.size()); CHECK(apk_fds != nullptr); CHECK_EQ(1u, apk_fds->size()); } std::vector<std::string> profile_args(profile_fds.size()); for (size_t k = 0; k < profile_fds.size(); k++) { profile_args[k] = "--profile-file-fd=" + std::to_string(profile_fds[k].get()); } std::string reference_profile_arg = "--reference-profile-file-fd=" + std::to_string(reference_profile_fd.get()); Loading @@ -734,7 +741,7 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, } // program name, reference profile fd, the final NULL and the profile fds const char* argv[3 + profile_args.size() + apk_args.size()]; const char* argv[3 + profile_args.size() + apk_args.size() + (copy_and_update ? 1 : 0)]; int i = 0; argv[i++] = profman_bin; argv[i++] = reference_profile_arg.c_str(); Loading @@ -744,6 +751,9 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, for (size_t k = 0; k < apk_args.size(); k++) { argv[i++] = apk_args[k].c_str(); } if (copy_and_update) { argv[i++] = "--copy-and-update-profile-key"; } // Do not add after dex2oat_flags, they should override others for debugging. argv[i] = NULL; Loading @@ -752,6 +762,25 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, exit(68); /* only get here on exec failure */ } static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>* apk_fds = nullptr) { run_profman(profiles_fd, reference_profile_fd, apk_fds, /*copy_and_update*/false); } static void run_profman_copy_and_update(unique_fd&& profile_fd, unique_fd&& reference_profile_fd, unique_fd&& apk_fd) { std::vector<unique_fd> profiles_fd; profiles_fd.push_back(std::move(profile_fd)); std::vector<unique_fd> apk_fds; apk_fds.push_back(std::move(apk_fd)); run_profman(profiles_fd, reference_profile_fd, &apk_fds, /*copy_and_update*/true); } // Decides if profile guided compilation is needed or not based on existing profiles. // The location is the package name for primary apks or the dex path for secondary dex files. // Returns true if there is enough information in the current profiles that makes it Loading Loading @@ -2610,7 +2639,7 @@ bool prepare_app_profile(const std::string& package_name, userid_t user_id, appid_t app_id, const std::string& profile_name, const std::string& code_path ATTRIBUTE_UNUSED, const std::string& code_path, const std::unique_ptr<std::string>& dex_metadata) { // Prepare the current profile. std::string cur_profile = create_current_profile_path(user_id, package_name, profile_name, Loading @@ -2631,8 +2660,11 @@ bool prepare_app_profile(const std::string& package_name, /*read_write*/ true, /*is_secondary_dex*/ false); unique_fd dex_metadata_fd(TEMP_FAILURE_RETRY( open(dex_metadata->c_str(), O_RDONLY | O_NOFOLLOW))); std::vector<unique_fd> profiles_fd; profiles_fd.push_back(std::move(dex_metadata_fd)); unique_fd apk_fd(TEMP_FAILURE_RETRY(open(code_path.c_str(), O_RDONLY | O_NOFOLLOW))); if (apk_fd < 0) { PLOG(ERROR) << "Could not open code path " << code_path; return false; } pid_t pid = fork(); if (pid == 0) { Loading @@ -2640,10 +2672,10 @@ bool prepare_app_profile(const std::string& package_name, gid_t app_shared_gid = multiuser_get_shared_gid(user_id, app_id); drop_capabilities(app_shared_gid); // TODO(calin): the dex metadata profile might embed different names for the // same code path (e.g. YouTube.apk or base.apk, depending on how the initial // profile was captured). We should pass the code path to adjust the names in the profile. run_profman_merge(profiles_fd, ref_profile_fd); // The copy and update takes ownership over the fds. run_profman_copy_and_update(std::move(dex_metadata_fd), std::move(ref_profile_fd), std::move(apk_fd)); exit(42); /* only get here on exec failure */ } Loading Loading
cmds/installd/dexopt.cpp +45 −13 Original line number Diff line number Diff line Loading @@ -715,13 +715,20 @@ static constexpr int PROFMAN_BIN_RETURN_CODE_BAD_PROFILES = 2; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_IO = 3; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>* apk_fds = nullptr) { static void run_profman(const std::vector<unique_fd>& profile_fds, const unique_fd& reference_profile_fd, const std::vector<unique_fd>* apk_fds, bool copy_and_update) { const char* profman_bin = is_debug_runtime() ? "/system/bin/profmand" : "/system/bin/profman"; std::vector<std::string> profile_args(profiles_fd.size()); for (size_t k = 0; k < profiles_fd.size(); k++) { profile_args[k] = "--profile-file-fd=" + std::to_string(profiles_fd[k].get()); if (copy_and_update) { CHECK_EQ(1u, profile_fds.size()); CHECK(apk_fds != nullptr); CHECK_EQ(1u, apk_fds->size()); } std::vector<std::string> profile_args(profile_fds.size()); for (size_t k = 0; k < profile_fds.size(); k++) { profile_args[k] = "--profile-file-fd=" + std::to_string(profile_fds[k].get()); } std::string reference_profile_arg = "--reference-profile-file-fd=" + std::to_string(reference_profile_fd.get()); Loading @@ -734,7 +741,7 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, } // program name, reference profile fd, the final NULL and the profile fds const char* argv[3 + profile_args.size() + apk_args.size()]; const char* argv[3 + profile_args.size() + apk_args.size() + (copy_and_update ? 1 : 0)]; int i = 0; argv[i++] = profman_bin; argv[i++] = reference_profile_arg.c_str(); Loading @@ -744,6 +751,9 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, for (size_t k = 0; k < apk_args.size(); k++) { argv[i++] = apk_args[k].c_str(); } if (copy_and_update) { argv[i++] = "--copy-and-update-profile-key"; } // Do not add after dex2oat_flags, they should override others for debugging. argv[i] = NULL; Loading @@ -752,6 +762,25 @@ static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, exit(68); /* only get here on exec failure */ } static void run_profman_merge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>* apk_fds = nullptr) { run_profman(profiles_fd, reference_profile_fd, apk_fds, /*copy_and_update*/false); } static void run_profman_copy_and_update(unique_fd&& profile_fd, unique_fd&& reference_profile_fd, unique_fd&& apk_fd) { std::vector<unique_fd> profiles_fd; profiles_fd.push_back(std::move(profile_fd)); std::vector<unique_fd> apk_fds; apk_fds.push_back(std::move(apk_fd)); run_profman(profiles_fd, reference_profile_fd, &apk_fds, /*copy_and_update*/true); } // Decides if profile guided compilation is needed or not based on existing profiles. // The location is the package name for primary apks or the dex path for secondary dex files. // Returns true if there is enough information in the current profiles that makes it Loading Loading @@ -2610,7 +2639,7 @@ bool prepare_app_profile(const std::string& package_name, userid_t user_id, appid_t app_id, const std::string& profile_name, const std::string& code_path ATTRIBUTE_UNUSED, const std::string& code_path, const std::unique_ptr<std::string>& dex_metadata) { // Prepare the current profile. std::string cur_profile = create_current_profile_path(user_id, package_name, profile_name, Loading @@ -2631,8 +2660,11 @@ bool prepare_app_profile(const std::string& package_name, /*read_write*/ true, /*is_secondary_dex*/ false); unique_fd dex_metadata_fd(TEMP_FAILURE_RETRY( open(dex_metadata->c_str(), O_RDONLY | O_NOFOLLOW))); std::vector<unique_fd> profiles_fd; profiles_fd.push_back(std::move(dex_metadata_fd)); unique_fd apk_fd(TEMP_FAILURE_RETRY(open(code_path.c_str(), O_RDONLY | O_NOFOLLOW))); if (apk_fd < 0) { PLOG(ERROR) << "Could not open code path " << code_path; return false; } pid_t pid = fork(); if (pid == 0) { Loading @@ -2640,10 +2672,10 @@ bool prepare_app_profile(const std::string& package_name, gid_t app_shared_gid = multiuser_get_shared_gid(user_id, app_id); drop_capabilities(app_shared_gid); // TODO(calin): the dex metadata profile might embed different names for the // same code path (e.g. YouTube.apk or base.apk, depending on how the initial // profile was captured). We should pass the code path to adjust the names in the profile. run_profman_merge(profiles_fd, ref_profile_fd); // The copy and update takes ownership over the fds. run_profman_copy_and_update(std::move(dex_metadata_fd), std::move(ref_profile_fd), std::move(apk_fd)); exit(42); /* only get here on exec failure */ } Loading