aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2016-09-26 13:39:14 -0500
committerTao Bao2016-09-26 16:46:12 -0500
commitf4885adc189f246ac3c651aa5cb2e74a240f3f1e (patch)
tree3a26ae4f7b0d956c3398aa7fa48fece3ecbf341d /install.cpp
parent3cf815a6a93bd9e27d250d181ef877e5d3a42018 (diff)
downloadplatform-bootable-recovery-f4885adc189f246ac3c651aa5cb2e74a240f3f1e.tar.gz
platform-bootable-recovery-f4885adc189f246ac3c651aa5cb2e74a240f3f1e.tar.xz
platform-bootable-recovery-f4885adc189f246ac3c651aa5cb2e74a240f3f1e.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
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 4c697420..01b839ff 100644
--- a/install.cpp
+++ b/install.cpp
@@ -358,13 +358,6 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
358 modified_flash = true; 358 modified_flash = true;
359 auto start = std::chrono::system_clock::now(); 359 auto start = std::chrono::system_clock::now();
360 360
361 FILE* install_log = fopen_path(install_file, "w");
362 if (install_log) {
363 fputs(path, install_log);
364 fputc('\n', install_log);
365 } else {
366 PLOG(ERROR) << "failed to open last_install";
367 }
368 int result; 361 int result;
369 std::vector<std::string> log_buffer; 362 std::vector<std::string> log_buffer;
370 if (setup_install_mounts() != 0) { 363 if (setup_install_mounts() != 0) {
@@ -373,32 +366,39 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
373 } else { 366 } else {
374 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); 367 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count);
375 } 368 }
376 if (install_log != nullptr) {
377 fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
378 fputc('\n', install_log);
379 std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
380 int count = static_cast<int>(duration.count());
381 // Report the time spent to apply OTA update in seconds.
382 fprintf(install_log, "time_total: %d\n", count);
383 fprintf(install_log, "retry: %d\n", retry_count);
384
385 for (const auto& s : log_buffer) {
386 fprintf(install_log, "%s\n", s.c_str());
387 }
388 369
389 if (ensure_path_mounted(UNCRYPT_STATUS) != 0) { 370 // Measure the time spent to apply OTA update in seconds.
390 LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS; 371 std::chrono::duration<double> duration = std::chrono::system_clock::now() - start;
372 int time_total = static_cast<int>(duration.count());
373
374 if (ensure_path_mounted(UNCRYPT_STATUS) != 0) {
375 LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS;
376 } else {
377 std::string uncrypt_status;
378 if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
379 PLOG(WARNING) << "failed to read uncrypt status";
380 } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) {
381 PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
391 } else { 382 } else {
392 std::string uncrypt_status; 383 log_buffer.push_back(android::base::Trim(uncrypt_status));
393 if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) {
394 PLOG(WARNING) << "failed to read uncrypt status";
395 } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_time:")) {
396 PLOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status;
397 } else {
398 fprintf(install_log, "%s\n", android::base::Trim(uncrypt_status).c_str());
399 }
400 } 384 }
401 fclose(install_log);
402 } 385 }
386
387 // The first two lines need to be the package name and install result.
388 std::vector<std::string> log_header = {
389 path,
390 result == INSTALL_SUCCESS ? "1" : "0",
391 "time_total: " + std::to_string(time_total),
392 "retry: " + std::to_string(retry_count),
393 };
394 std::string log_content = android::base::Join(log_header, "\n") + "\n" +
395 android::base::Join(log_buffer, "\n");
396 if (!android::base::WriteStringToFile(log_content, install_file)) {
397 PLOG(ERROR) << "failed to write " << install_file;
398 }
399
400 // Write a copy into last_log.
401 LOG(INFO) << log_content;
402
403 return result; 403 return result;
404} 404}