aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2016-09-26 13:39:14 -0500
committerTao Bao2016-09-26 16:56:25 -0500
commitbadaac45fee6e39dd74001ea3b2aa954afb37999 (patch)
tree610e17fb688dae99e70f71389b1ae2cffa58e81d /install.cpp
parentc8db4817809e163d887f7955a03ad0f97159f12b (diff)
downloadplatform-bootable-recovery-badaac45fee6e39dd74001ea3b2aa954afb37999.tar.gz
platform-bootable-recovery-badaac45fee6e39dd74001ea3b2aa954afb37999.tar.xz
platform-bootable-recovery-badaac45fee6e39dd74001ea3b2aa954afb37999.zip
Duplicate the last_install content into last_log.
Currently we save the OTA metrics in last_install, which keeps the data for the _last_ install only. This CL logs the same content into last_log so that we keep the metrics for every install. Bug: 31607469 Test: Apply an update (via OTA and sideload) and check last_log and last_install. Change-Id: Id8f174d79534fddc9f06d72a4e69b2b1d8ab186c (cherry picked from commit f4885adc189f246ac3c651aa5cb2e74a240f3f1e)
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/install.cpp b/install.cpp
index d600ea33..9a83c488 100644
--- a/install.cpp
+++ b/install.cpp
@@ -517,13 +517,6 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
517 modified_flash = true; 517 modified_flash = true;
518 auto start = std::chrono::system_clock::now(); 518 auto start = std::chrono::system_clock::now();
519 519
520 FILE* install_log = fopen_path(install_file, "w");
521 if (install_log) {
522 fputs(path, install_log);
523 fputc('\n', install_log);
524 } else {
525 PLOG(ERROR) << "failed to open last_install";
526 }
527 int result; 520 int result;
528 std::vector<std::string> log_buffer; 521 std::vector<std::string> log_buffer;
529 if (setup_install_mounts() != 0) { 522 if (setup_install_mounts() != 0) {
@@ -532,33 +525,40 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
532 } else { 525 } else {
533 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); 526 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count);
534 } 527 }
535 if (install_log != nullptr) {
536 fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
537 fputc('\n', install_log);
538 std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
539 int count = static_cast<int>(duration.count());
540 // Report the time spent to apply OTA update in seconds.
541 fprintf(install_log, "time_total: %d\n", count);
542 fprintf(install_log, "retry: %d\n", retry_count);
543
544 for (const auto& s : log_buffer) {
545 fprintf(install_log, "%s\n", s.c_str());
546 }
547 528
548 if (ensure_path_mounted(UNCRYPT_STATUS) != 0) { 529 // Measure the time spent to apply OTA update in seconds.
549 LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS; 530 std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
531 int time_total = static_cast<int>(duration.count());
532
533 if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
534 LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS;
535 } else {
536 std::string uncrypt_status;
537 if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
538 PLOG(WARNING) << "failed to read uncrypt status";
539 } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) {
540 PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
550 } else { 541 } else {
551 std::string uncrypt_status; 542 log_buffer.push_back(android::base::Trim(uncrypt_status));
552 if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
553 PLOG(WARNING) << "failed to read uncrypt status";
554 } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) {
555 PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
556 } else {
557 fprintf(install_log, "%s\n", android::base::Trim(uncrypt_status).c_str());
558 }
559 } 543 }
560 fclose(install_log);
561 } 544 }
545
546 // The first two lines need to be the package name and install result.
547 std::vector<std::string> log_header = {
548 path,
549 result == INSTALL_SUCCESS ? "1" : "0",
550 "time_total: " + std::to_string(time_total),
551 "retry: " + std::to_string(retry_count),
552 };
553 std::string log_content = android::base::Join(log_header, "\n") + "\n" +
554 android::base::Join(log_buffer, "\n");
555 if (!android::base::WriteStringToFile(log_content, install_file)) {
556 PLOG(ERROR) << "failed to write " << install_file;
557 }
558
559 // Write a copy into last_log.
560 LOG(INFO) << log_content;
561
562 return result; 562 return result;
563} 563}
564 564