DO NOT MERGE Duplicate the last_install content into last_log.

am: a8c0d0b43a

Change-Id: I6ba873dcf7b833daaf6ca74d49a6410be3e4fbcb
This commit is contained in:
Tao Bao
2016-09-27 20:24:22 +00:00
committed by android-build-merger
2 changed files with 40 additions and 38 deletions

View File

@@ -31,7 +31,6 @@
#include <vector> #include <vector>
#include <android-base/file.h> #include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parseint.h> #include <android-base/parseint.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <android-base/strings.h> #include <android-base/strings.h>
@@ -522,13 +521,6 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
modified_flash = true; modified_flash = true;
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
FILE* install_log = fopen_path(install_file, "w");
if (install_log) {
fputs(path, install_log);
fputc('\n', install_log);
} else {
LOGE("failed to open last_install: %s\n", strerror(errno));
}
int result; int result;
std::vector<std::string> log_buffer; std::vector<std::string> log_buffer;
if (setup_install_mounts() != 0) { if (setup_install_mounts() != 0) {
@@ -537,33 +529,40 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
} else { } else {
result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count);
} }
if (install_log != nullptr) {
fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
fputc('\n', install_log);
std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
int count = static_cast<int>(duration.count());
// Report the time spent to apply OTA update in seconds.
fprintf(install_log, "time_total: %d\n", count);
fprintf(install_log, "retry: %d\n", retry_count);
for (const auto& s : log_buffer) { // Measure the time spent to apply OTA update in seconds.
fprintf(install_log, "%s\n", s.c_str()); std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
} int time_total = static_cast<int>(duration.count());
if (ensure_path_mounted(UNCRYPT_STATUS) != 0) { if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS; LOGW("Can't mount %s\n", UNCRYPT_STATUS);
} else {
std::string uncrypt_status;
if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
LOGW("failed to read uncrypt status: %s\n", strerror(errno));
} else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) {
LOGW("corrupted uncrypt_status: %s: %s\n", uncrypt_status.c_str(), strerror(errno));
} else { } else {
std::string uncrypt_status; log_buffer.push_back(android::base::Trim(uncrypt_status));
if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
PLOG(WARNING) << "failed to read uncrypt status";
} else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) {
PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
} else {
fprintf(install_log, "%s\n", android::base::Trim(uncrypt_status).c_str());
}
} }
fclose(install_log);
} }
// The first two lines need to be the package name and install result.
std::vector<std::string> log_header = {
path,
result == INSTALL_SUCCESS ? "1" : "0",
"time_total: " + std::to_string(time_total),
"retry: " + std::to_string(retry_count),
};
std::string log_content = android::base::Join(log_header, "\n") + "\n" +
android::base::Join(log_buffer, "\n");
if (!android::base::WriteStringToFile(log_content, install_file)) {
LOGE("failed to write %s: %s\n", install_file, strerror(errno));
}
// Write a copy into last_log.
LOGI("%s\n", log_content.c_str());
return result; return result;
} }

View File

@@ -1429,15 +1429,18 @@ static bool bootreason_in_blacklist() {
} }
static void log_failure_code(ErrorCode code, const char *update_package) { static void log_failure_code(ErrorCode code, const char *update_package) {
FILE* install_log = fopen_path(TEMPORARY_INSTALL_FILE, "w"); std::vector<std::string> log_buffer = {
if (install_log != nullptr) { update_package,
fprintf(install_log, "%s\n", update_package); "0", // install result
fprintf(install_log, "0\n"); "error: " + std::to_string(code),
fprintf(install_log, "error: %d\n", code); };
fclose(install_log); std::string log_content = android::base::Join(log_buffer, "\n");
} else { if (!android::base::WriteStringToFile(log_content, TEMPORARY_INSTALL_FILE)) {
LOGE("failed to open last_install: %s\n", strerror(errno)); LOGE("failed to write %s: %s\n", TEMPORARY_INSTALL_FILE, strerror(errno));
} }
// Also write the info into last_log.
LOGI("%s\n", log_content.c_str());
} }
static ssize_t logbasename( static ssize_t logbasename(