aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2017-03-27 16:12:26 -0500
committerTianjie Xu2017-03-28 13:28:47 -0500
commit3ee2b9db5a5c9977c6bd726d0e5d12f5ac07d5cf (patch)
tree8fe61071b191a287698efcbfebc51d1496710e4c /install.cpp
parent27c3e47853b27d08fb6b1e250212b785c915c1a6 (diff)
downloadplatform-bootable-recovery-3ee2b9db5a5c9977c6bd726d0e5d12f5ac07d5cf.tar.gz
platform-bootable-recovery-3ee2b9db5a5c9977c6bd726d0e5d12f5ac07d5cf.tar.xz
platform-bootable-recovery-3ee2b9db5a5c9977c6bd726d0e5d12f5ac07d5cf.zip
Log temperature during OTA update
Log the maximum temperature as well as the start/end temperature of an update to last_install. Check the temperature at the end of each block_image_update(verify). To get the maximum temp, we iterate through /sys/class/thermal/thermal_zone*/temp and find the maximum value present. Bug: 32518487 Test: temperature logs in last_install Change-Id: Iaf22a9fbc5b18611bbc5320ffea995417872e514
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp52
1 files changed, 47 insertions, 5 deletions
diff --git a/install.cpp b/install.cpp
index 7cef44a3..0a2fa3ca 100644
--- a/install.cpp
+++ b/install.cpp
@@ -26,11 +26,15 @@
26#include <sys/wait.h> 26#include <sys/wait.h>
27#include <unistd.h> 27#include <unistd.h>
28 28
29#include <algorithm>
29#include <chrono> 30#include <chrono>
31#include <condition_variable>
30#include <functional> 32#include <functional>
31#include <limits> 33#include <limits>
32#include <map> 34#include <map>
35#include <mutex>
33#include <string> 36#include <string>
37#include <thread>
34#include <vector> 38#include <vector>
35 39
36#include <android-base/file.h> 40#include <android-base/file.h>
@@ -46,10 +50,13 @@
46#include "error_code.h" 50#include "error_code.h"
47#include "minui/minui.h" 51#include "minui/minui.h"
48#include "otautil/SysUtil.h" 52#include "otautil/SysUtil.h"
53#include "otautil/ThermalUtil.h"
49#include "roots.h" 54#include "roots.h"
50#include "ui.h" 55#include "ui.h"
51#include "verifier.h" 56#include "verifier.h"
52 57
58using namespace std::chrono_literals;
59
53#define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" 60#define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary"
54static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt"; 61static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt";
55static constexpr const char* AB_OTA_PAYLOAD = "payload.bin"; 62static constexpr const char* AB_OTA_PAYLOAD = "payload.bin";
@@ -63,6 +70,8 @@ static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
63static constexpr float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; 70static constexpr float DEFAULT_FILES_PROGRESS_FRACTION = 0.4;
64static constexpr float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; 71static constexpr float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1;
65 72
73static std::condition_variable finish_log_temperature;
74
66// This function parses and returns the build.version.incremental 75// This function parses and returns the build.version.incremental
67static int parse_build_number(const std::string& str) { 76static int parse_build_number(const std::string& str) {
68 size_t pos = str.find('='); 77 size_t pos = str.find('=');
@@ -299,9 +308,19 @@ update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count,
299} 308}
300#endif // !AB_OTA_UPDATER 309#endif // !AB_OTA_UPDATER
301 310
311static void log_max_temperature(int* max_temperature) {
312 CHECK(max_temperature != nullptr);
313 std::mutex mtx;
314 std::unique_lock<std::mutex> lck(mtx);
315 while (finish_log_temperature.wait_for(lck, 20s) == std::cv_status::timeout) {
316 *max_temperature = std::max(*max_temperature, GetMaxValueFromThermalZone());
317 }
318}
319
302// If the package contains an update binary, extract it and run it. 320// If the package contains an update binary, extract it and run it.
303static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache, 321static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache,
304 std::vector<std::string>& log_buffer, int retry_count) { 322 std::vector<std::string>& log_buffer, int retry_count,
323 int* max_temperature) {
305 read_source_target_build(zip, log_buffer); 324 read_source_target_build(zip, log_buffer);
306 325
307 int pipefd[2]; 326 int pipefd[2];
@@ -392,6 +411,8 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
392 } 411 }
393 close(pipefd[1]); 412 close(pipefd[1]);
394 413
414 std::thread temperature_logger(log_max_temperature, max_temperature);
415
395 *wipe_cache = false; 416 *wipe_cache = false;
396 bool retry_update = false; 417 bool retry_update = false;
397 418
@@ -453,6 +474,10 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
453 474
454 int status; 475 int status;
455 waitpid(pid, &status, 0); 476 waitpid(pid, &status, 0);
477
478 finish_log_temperature.notify_one();
479 temperature_logger.join();
480
456 if (retry_update) { 481 if (retry_update) {
457 return INSTALL_RETRY; 482 return INSTALL_RETRY;
458 } 483 }
@@ -466,7 +491,7 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
466 491
467static int 492static int
468really_install_package(const char *path, bool* wipe_cache, bool needs_mount, 493really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
469 std::vector<std::string>& log_buffer, int retry_count) 494 std::vector<std::string>& log_buffer, int retry_count, int* max_temperature)
470{ 495{
471 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); 496 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
472 ui->Print("Finding update package...\n"); 497 ui->Print("Finding update package...\n");
@@ -517,7 +542,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
517 ui->Print("Retry attempt: %d\n", retry_count); 542 ui->Print("Retry attempt: %d\n", retry_count);
518 } 543 }
519 ui->SetEnableReboot(false); 544 ui->SetEnableReboot(false);
520 int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count); 545 int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature);
521 ui->SetEnableReboot(true); 546 ui->SetEnableReboot(true);
522 ui->Print("\n"); 547 ui->Print("\n");
523 548
@@ -533,13 +558,17 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
533 modified_flash = true; 558 modified_flash = true;
534 auto start = std::chrono::system_clock::now(); 559 auto start = std::chrono::system_clock::now();
535 560
561 int start_temperature = GetMaxValueFromThermalZone();
562 int max_temperature = start_temperature;
563
536 int result; 564 int result;
537 std::vector<std::string> log_buffer; 565 std::vector<std::string> log_buffer;
538 if (setup_install_mounts() != 0) { 566 if (setup_install_mounts() != 0) {
539 LOG(ERROR) << "failed to set up expected mounts for install; aborting"; 567 LOG(ERROR) << "failed to set up expected mounts for install; aborting";
540 result = INSTALL_ERROR; 568 result = INSTALL_ERROR;
541 } else { 569 } else {
542 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); 570 result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count,
571 &max_temperature);
543 } 572 }
544 573
545 // Measure the time spent to apply OTA update in seconds. 574 // Measure the time spent to apply OTA update in seconds.
@@ -570,8 +599,21 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
570 "time_total: " + std::to_string(time_total), 599 "time_total: " + std::to_string(time_total),
571 "retry: " + std::to_string(retry_count), 600 "retry: " + std::to_string(retry_count),
572 }; 601 };
602
603 int end_temperature = GetMaxValueFromThermalZone();
604 max_temperature = std::max(end_temperature, max_temperature);
605 if (start_temperature > 0) {
606 log_buffer.push_back("temperature_start: " + std::to_string(start_temperature));
607 }
608 if (end_temperature > 0) {
609 log_buffer.push_back("temperature_end: " + std::to_string(end_temperature));
610 }
611 if (max_temperature > 0) {
612 log_buffer.push_back("temperature_max: " + std::to_string(max_temperature));
613 }
614
573 std::string log_content = android::base::Join(log_header, "\n") + "\n" + 615 std::string log_content = android::base::Join(log_header, "\n") + "\n" +
574 android::base::Join(log_buffer, "\n"); 616 android::base::Join(log_buffer, "\n") + "\n";
575 if (!android::base::WriteStringToFile(log_content, install_file)) { 617 if (!android::base::WriteStringToFile(log_content, install_file)) {
576 PLOG(ERROR) << "failed to write " << install_file; 618 PLOG(ERROR) << "failed to write " << install_file;
577 } 619 }