Loading cmds/installd/dexopt.cpp +40 −18 Original line number Original line Diff line number Diff line Loading @@ -713,6 +713,7 @@ static constexpr int PROFMAN_BIN_RETURN_CODE_SKIP_COMPILATION = 1; static constexpr int PROFMAN_BIN_RETURN_CODE_BAD_PROFILES = 2; 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_IO = 3; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; static constexpr int PROFMAN_BIN_RETURN_CODE_SUCCESS = 5; class RunProfman : public ExecVHelper { class RunProfman : public ExecVHelper { public: public: Loading @@ -720,7 +721,9 @@ class RunProfman : public ExecVHelper { const unique_fd& reference_profile_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>& apk_fds, const std::vector<unique_fd>& apk_fds, const std::vector<std::string>& dex_locations, const std::vector<std::string>& dex_locations, bool copy_and_update) { bool copy_and_update, bool for_snapshot, bool for_boot_image) { // TODO(calin): Assume for now we run in the bg compile job (which is in // TODO(calin): Assume for now we run in the bg compile job (which is in // most of the invocation). With the current data flow, is not very easy or // most of the invocation). With the current data flow, is not very easy or Loading Loading @@ -752,6 +755,14 @@ class RunProfman : public ExecVHelper { AddArg("--copy-and-update-profile-key"); AddArg("--copy-and-update-profile-key"); } } if (for_snapshot) { AddArg("--force-merge"); } if (for_boot_image) { AddArg("--boot-image-merge"); } // Do not add after dex2oat_flags, they should override others for debugging. // Do not add after dex2oat_flags, they should override others for debugging. PrepareArgs(profman_bin); PrepareArgs(profman_bin); } } Loading @@ -759,12 +770,16 @@ class RunProfman : public ExecVHelper { void SetupMerge(const std::vector<unique_fd>& profiles_fd, void SetupMerge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>& apk_fds = std::vector<unique_fd>(), const std::vector<unique_fd>& apk_fds = std::vector<unique_fd>(), const std::vector<std::string>& dex_locations = std::vector<std::string>()) { const std::vector<std::string>& dex_locations = std::vector<std::string>(), bool for_snapshot = false, bool for_boot_image = false) { SetupArgs(profiles_fd, SetupArgs(profiles_fd, reference_profile_fd, reference_profile_fd, apk_fds, apk_fds, dex_locations, dex_locations, /*copy_and_update=*/false); /*copy_and_update=*/ false, for_snapshot, for_boot_image); } } void SetupCopyAndUpdate(unique_fd&& profile_fd, void SetupCopyAndUpdate(unique_fd&& profile_fd, Loading @@ -781,7 +796,9 @@ class RunProfman : public ExecVHelper { reference_profile_fd_, reference_profile_fd_, apk_fds_, apk_fds_, dex_locations, dex_locations, /*copy_and_update=*/true); /*copy_and_update=*/true, /*for_snapshot*/false, /*for_boot_image*/false); } } void SetupDump(const std::vector<unique_fd>& profiles_fd, void SetupDump(const std::vector<unique_fd>& profiles_fd, Loading @@ -795,7 +812,9 @@ class RunProfman : public ExecVHelper { reference_profile_fd, reference_profile_fd, apk_fds, apk_fds, dex_locations, dex_locations, /*copy_and_update=*/false); /*copy_and_update=*/false, /*for_snapshot*/false, /*for_boot_image*/false); } } void Exec() { void Exec() { Loading Loading @@ -872,7 +891,7 @@ static bool analyze_profiles(uid_t uid, const std::string& package_name, break; break; default: default: // Unknown return code or error. Unlink profiles. // Unknown return code or error. Unlink profiles. LOG(WARNING) << "Unknown error code while processing profiles for location " LOG(WARNING) << "Unexpected error code while processing profiles for location " << location << ": " << return_code; << location << ": " << return_code; need_to_compile = false; need_to_compile = false; should_clear_current_profiles = true; should_clear_current_profiles = true; Loading Loading @@ -2741,7 +2760,7 @@ static bool create_app_profile_snapshot(int32_t app_id, } } RunProfman args; RunProfman args; args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations); args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations, /*for_snapshot=*/true); pid_t pid = fork(); pid_t pid = fork(); if (pid == 0) { if (pid == 0) { /* child -- drop privileges before continuing */ /* child -- drop privileges before continuing */ Loading @@ -2756,6 +2775,13 @@ static bool create_app_profile_snapshot(int32_t app_id, return false; return false; } } // Verify that profman finished successfully. int profman_code = WEXITSTATUS(return_code); if (profman_code != PROFMAN_BIN_RETURN_CODE_SUCCESS) { LOG(WARNING) << "profman error for " << package_name << ":" << profile_name << ":" << profman_code; return false; } return true; return true; } } Loading Loading @@ -2838,7 +2864,9 @@ static bool create_boot_image_profile_snapshot(const std::string& package_name, args.SetupMerge(profiles_fd, args.SetupMerge(profiles_fd, snapshot_fd, snapshot_fd, apk_fds, apk_fds, dex_locations); dex_locations, /*for_snapshot=*/true, /*for_boot_image=*/true); pid_t pid = fork(); pid_t pid = fork(); if (pid == 0) { if (pid == 0) { /* child -- drop privileges before continuing */ /* child -- drop privileges before continuing */ Loading @@ -2859,16 +2887,10 @@ static bool create_boot_image_profile_snapshot(const std::string& package_name, // Verify that profman finished successfully. // Verify that profman finished successfully. int profman_code = WEXITSTATUS(return_code); int profman_code = WEXITSTATUS(return_code); switch (profman_code) { if (profman_code != PROFMAN_BIN_RETURN_CODE_SUCCESS) { case PROFMAN_BIN_RETURN_CODE_BAD_PROFILES: // fall through case PROFMAN_BIN_RETURN_CODE_ERROR_IO: // fall through case PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING: LOG(WARNING) << "profman error for " << package_name << ":" << profile_name LOG(WARNING) << "profman error for " << package_name << ":" << profile_name << ":" << profman_code; << ":" << profman_code; return false; return false; default: // Other return codes are ok. continue; } } } } Loading cmds/installd/tests/installd_dexopt_test.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -897,7 +897,9 @@ class ProfileTest : public DexoptTest { std::string expected_profile_content = snap_profile_ + ".expected"; std::string expected_profile_content = snap_profile_ + ".expected"; run_cmd("rm -f " + expected_profile_content); run_cmd("rm -f " + expected_profile_content); run_cmd("touch " + expected_profile_content); run_cmd("touch " + expected_profile_content); run_cmd("profman --profile-file=" + cur_profile_ + // We force merging when creating the expected profile to make sure // that the random profiles do not affect the output. run_cmd("profman --force-merge --profile-file=" + cur_profile_ + " --profile-file=" + ref_profile_ + " --profile-file=" + ref_profile_ + " --reference-profile-file=" + expected_profile_content + " --reference-profile-file=" + expected_profile_content + " --apk=" + apk_path_); " --apk=" + apk_path_); Loading Loading
cmds/installd/dexopt.cpp +40 −18 Original line number Original line Diff line number Diff line Loading @@ -713,6 +713,7 @@ static constexpr int PROFMAN_BIN_RETURN_CODE_SKIP_COMPILATION = 1; static constexpr int PROFMAN_BIN_RETURN_CODE_BAD_PROFILES = 2; 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_IO = 3; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; static constexpr int PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING = 4; static constexpr int PROFMAN_BIN_RETURN_CODE_SUCCESS = 5; class RunProfman : public ExecVHelper { class RunProfman : public ExecVHelper { public: public: Loading @@ -720,7 +721,9 @@ class RunProfman : public ExecVHelper { const unique_fd& reference_profile_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>& apk_fds, const std::vector<unique_fd>& apk_fds, const std::vector<std::string>& dex_locations, const std::vector<std::string>& dex_locations, bool copy_and_update) { bool copy_and_update, bool for_snapshot, bool for_boot_image) { // TODO(calin): Assume for now we run in the bg compile job (which is in // TODO(calin): Assume for now we run in the bg compile job (which is in // most of the invocation). With the current data flow, is not very easy or // most of the invocation). With the current data flow, is not very easy or Loading Loading @@ -752,6 +755,14 @@ class RunProfman : public ExecVHelper { AddArg("--copy-and-update-profile-key"); AddArg("--copy-and-update-profile-key"); } } if (for_snapshot) { AddArg("--force-merge"); } if (for_boot_image) { AddArg("--boot-image-merge"); } // Do not add after dex2oat_flags, they should override others for debugging. // Do not add after dex2oat_flags, they should override others for debugging. PrepareArgs(profman_bin); PrepareArgs(profman_bin); } } Loading @@ -759,12 +770,16 @@ class RunProfman : public ExecVHelper { void SetupMerge(const std::vector<unique_fd>& profiles_fd, void SetupMerge(const std::vector<unique_fd>& profiles_fd, const unique_fd& reference_profile_fd, const unique_fd& reference_profile_fd, const std::vector<unique_fd>& apk_fds = std::vector<unique_fd>(), const std::vector<unique_fd>& apk_fds = std::vector<unique_fd>(), const std::vector<std::string>& dex_locations = std::vector<std::string>()) { const std::vector<std::string>& dex_locations = std::vector<std::string>(), bool for_snapshot = false, bool for_boot_image = false) { SetupArgs(profiles_fd, SetupArgs(profiles_fd, reference_profile_fd, reference_profile_fd, apk_fds, apk_fds, dex_locations, dex_locations, /*copy_and_update=*/false); /*copy_and_update=*/ false, for_snapshot, for_boot_image); } } void SetupCopyAndUpdate(unique_fd&& profile_fd, void SetupCopyAndUpdate(unique_fd&& profile_fd, Loading @@ -781,7 +796,9 @@ class RunProfman : public ExecVHelper { reference_profile_fd_, reference_profile_fd_, apk_fds_, apk_fds_, dex_locations, dex_locations, /*copy_and_update=*/true); /*copy_and_update=*/true, /*for_snapshot*/false, /*for_boot_image*/false); } } void SetupDump(const std::vector<unique_fd>& profiles_fd, void SetupDump(const std::vector<unique_fd>& profiles_fd, Loading @@ -795,7 +812,9 @@ class RunProfman : public ExecVHelper { reference_profile_fd, reference_profile_fd, apk_fds, apk_fds, dex_locations, dex_locations, /*copy_and_update=*/false); /*copy_and_update=*/false, /*for_snapshot*/false, /*for_boot_image*/false); } } void Exec() { void Exec() { Loading Loading @@ -872,7 +891,7 @@ static bool analyze_profiles(uid_t uid, const std::string& package_name, break; break; default: default: // Unknown return code or error. Unlink profiles. // Unknown return code or error. Unlink profiles. LOG(WARNING) << "Unknown error code while processing profiles for location " LOG(WARNING) << "Unexpected error code while processing profiles for location " << location << ": " << return_code; << location << ": " << return_code; need_to_compile = false; need_to_compile = false; should_clear_current_profiles = true; should_clear_current_profiles = true; Loading Loading @@ -2741,7 +2760,7 @@ static bool create_app_profile_snapshot(int32_t app_id, } } RunProfman args; RunProfman args; args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations); args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations, /*for_snapshot=*/true); pid_t pid = fork(); pid_t pid = fork(); if (pid == 0) { if (pid == 0) { /* child -- drop privileges before continuing */ /* child -- drop privileges before continuing */ Loading @@ -2756,6 +2775,13 @@ static bool create_app_profile_snapshot(int32_t app_id, return false; return false; } } // Verify that profman finished successfully. int profman_code = WEXITSTATUS(return_code); if (profman_code != PROFMAN_BIN_RETURN_CODE_SUCCESS) { LOG(WARNING) << "profman error for " << package_name << ":" << profile_name << ":" << profman_code; return false; } return true; return true; } } Loading Loading @@ -2838,7 +2864,9 @@ static bool create_boot_image_profile_snapshot(const std::string& package_name, args.SetupMerge(profiles_fd, args.SetupMerge(profiles_fd, snapshot_fd, snapshot_fd, apk_fds, apk_fds, dex_locations); dex_locations, /*for_snapshot=*/true, /*for_boot_image=*/true); pid_t pid = fork(); pid_t pid = fork(); if (pid == 0) { if (pid == 0) { /* child -- drop privileges before continuing */ /* child -- drop privileges before continuing */ Loading @@ -2859,16 +2887,10 @@ static bool create_boot_image_profile_snapshot(const std::string& package_name, // Verify that profman finished successfully. // Verify that profman finished successfully. int profman_code = WEXITSTATUS(return_code); int profman_code = WEXITSTATUS(return_code); switch (profman_code) { if (profman_code != PROFMAN_BIN_RETURN_CODE_SUCCESS) { case PROFMAN_BIN_RETURN_CODE_BAD_PROFILES: // fall through case PROFMAN_BIN_RETURN_CODE_ERROR_IO: // fall through case PROFMAN_BIN_RETURN_CODE_ERROR_LOCKING: LOG(WARNING) << "profman error for " << package_name << ":" << profile_name LOG(WARNING) << "profman error for " << package_name << ":" << profile_name << ":" << profman_code; << ":" << profman_code; return false; return false; default: // Other return codes are ok. continue; } } } } Loading
cmds/installd/tests/installd_dexopt_test.cpp +3 −1 Original line number Original line Diff line number Diff line Loading @@ -897,7 +897,9 @@ class ProfileTest : public DexoptTest { std::string expected_profile_content = snap_profile_ + ".expected"; std::string expected_profile_content = snap_profile_ + ".expected"; run_cmd("rm -f " + expected_profile_content); run_cmd("rm -f " + expected_profile_content); run_cmd("touch " + expected_profile_content); run_cmd("touch " + expected_profile_content); run_cmd("profman --profile-file=" + cur_profile_ + // We force merging when creating the expected profile to make sure // that the random profiles do not affect the output. run_cmd("profman --force-merge --profile-file=" + cur_profile_ + " --profile-file=" + ref_profile_ + " --profile-file=" + ref_profile_ + " --reference-profile-file=" + expected_profile_content + " --reference-profile-file=" + expected_profile_content + " --apk=" + apk_path_); " --apk=" + apk_path_); Loading