diff options
author | TeYuan Wang <kamewang@google.com> | 2022-12-01 23:55:00 +0800 |
---|---|---|
committer | TeYuan Wang <kamewang@google.com> | 2022-12-22 09:30:23 +0800 |
commit | dacdb1fb86d7c99abe125184646f04a05b4a7ff4 (patch) | |
tree | c6c25132d84b8257da1820964683a073924ba280 | |
parent | 44729dc510917b1ac1788c4ca0ff1918c6dc60e5 (diff) |
thermal: avoid the duplicate sensor reading log
Bug: 254163925
Test: emul_temp and verify the sensor log
Change-Id: Ia6eb5d153abae5324b8cd2eb3dd1204441e0a073
-rw-r--r-- | thermal/thermal-helper.cpp | 44 | ||||
-rw-r--r-- | thermal/thermal-helper.h | 2 |
2 files changed, 23 insertions, 23 deletions
diff --git a/thermal/thermal-helper.cpp b/thermal/thermal-helper.cpp index c3451f4..8436127 100644 --- a/thermal/thermal-helper.cpp +++ b/thermal/thermal-helper.cpp @@ -334,8 +334,8 @@ bool ThermalHelper::readCoolingDevice(std::string_view cooling_device, bool ThermalHelper::readTemperature(std::string_view sensor_name, Temperature_1_0 *out) { // Return fail if the thermal sensor cannot be read. float temp; - std::string sensor_log; - if (!readThermalSensor(sensor_name, &temp, false, &sensor_log)) { + std::map<std::string, float> sensor_log_map; + if (!readThermalSensor(sensor_name, &temp, false, &sensor_log_map)) { LOG(ERROR) << "readTemperature: failed to read sensor: " << sensor_name; return false; } @@ -355,8 +355,12 @@ bool ThermalHelper::readTemperature(std::string_view sensor_name, Temperature_1_ out->vrThrottlingThreshold = sensor_info.vr_threshold; if (sensor_info.is_watch) { - LOG(INFO) << sensor_name.data() << ":" << out->currentValue << " raw data:[" << sensor_log - << "]"; + std::ostringstream sensor_log; + for (const auto &sensor_log_pair : sensor_log_map) { + sensor_log << sensor_log_pair.first << ":" << sensor_log_pair.second << " "; + } + LOG(INFO) << sensor_name.data() << ":" << out->currentValue + << " raw data: " << sensor_log.str(); } return true; } @@ -367,9 +371,9 @@ bool ThermalHelper::readTemperature( const bool force_no_cache) { // Return fail if the thermal sensor cannot be read. float temp; - std::string sensor_log; + std::map<std::string, float> sensor_log_map; - if (!readThermalSensor(sensor_name, &temp, force_no_cache, &sensor_log)) { + if (!readThermalSensor(sensor_name, &temp, force_no_cache, &sensor_log_map)) { LOG(ERROR) << "readTemperature: failed to read sensor: " << sensor_name; return false; } @@ -402,8 +406,13 @@ bool ThermalHelper::readTemperature( ? status.first : status.second; if (sensor_info.is_watch) { - LOG(INFO) << sensor_name.data() << ":" << out->value << " raw data:[" << sensor_log << "]"; + std::ostringstream sensor_log; + for (const auto &sensor_log_pair : sensor_log_map) { + sensor_log << sensor_log_pair.first << ":" << sensor_log_pair.second << " "; + } + LOG(INFO) << sensor_name.data() << ":" << out->value << " raw data: " << sensor_log.str(); } + return true; } @@ -793,31 +802,25 @@ bool ThermalHelper::fillCpuUsages(hidl_vec<CpuUsage> *cpu_usages) const { } bool ThermalHelper::readThermalSensor(std::string_view sensor_name, float *temp, - const bool force_no_cache, std::string *sensor_log) { + const bool force_no_cache, + std::map<std::string, float> *sensor_log_map) { float temp_val = 0.0; std::string file_reading; - std::string sub_sensor_log; boot_clock::time_point now = boot_clock::now(); ATRACE_NAME(StringPrintf("ThermalHelper::readThermalSensor - %s", sensor_name.data()).c_str()); - if (!(sensor_info_map_.count(sensor_name.data()) && - sensor_status_map_.count(sensor_name.data()))) { - return false; - } const auto &sensor_info = sensor_info_map_.at(sensor_name.data()); auto &sensor_status = sensor_status_map_.at(sensor_name.data()); - // Check if thermal data need to be read from buffer + // Check if thermal data need to be read from cache if (!force_no_cache && (sensor_status.thermal_cached.timestamp != boot_clock::time_point::min()) && (std::chrono::duration_cast<std::chrono::milliseconds>( now - sensor_status.thermal_cached.timestamp) < sensor_info.time_resolution) && !isnan(sensor_status.thermal_cached.temp)) { *temp = sensor_status.thermal_cached.temp; - sensor_log->append(StringPrintf("%s:%0.f ", sensor_name.data(), *temp)); - - LOG(VERBOSE) << "read " << sensor_name.data() << " from buffer, value:" << *temp; + (*sensor_log_map)[sensor_name.data()] = *temp; ATRACE_INT((sensor_name.data() + std::string("-cached")).c_str(), static_cast<int>(*temp)); return true; } @@ -833,12 +836,11 @@ bool ThermalHelper::readThermalSensor(std::string_view sensor_name, float *temp, return false; } *temp = std::stof(::android::base::Trim(file_reading)); - sensor_log->append(StringPrintf("%s:%0.f ", sensor_name.data(), *temp)); } else { for (size_t i = 0; i < sensor_info.virtual_sensor_info->linked_sensors.size(); i++) { float sensor_reading = 0.0; if (!readThermalSensor(sensor_info.virtual_sensor_info->linked_sensors[i], - &sensor_reading, force_no_cache, &sub_sensor_log)) { + &sensor_reading, force_no_cache, sensor_log_map)) { return false; } if (std::isnan(sensor_info.virtual_sensor_info->coefficients[i])) { @@ -872,10 +874,8 @@ bool ThermalHelper::readThermalSensor(std::string_view sensor_name, float *temp, } } *temp = (temp_val + sensor_info.virtual_sensor_info->offset); - sensor_log->append( - StringPrintf("%s:%0.f(%s) ", sensor_name.data(), *temp, sub_sensor_log.data())); } - + (*sensor_log_map)[sensor_name.data()] = *temp; ATRACE_INT(sensor_name.data(), static_cast<int>(*temp)); { diff --git a/thermal/thermal-helper.h b/thermal/thermal-helper.h index eca9805..fe5ebb8 100644 --- a/thermal/thermal-helper.h +++ b/thermal/thermal-helper.h @@ -151,7 +151,7 @@ class ThermalHelper { float value) const; // Read temperature data according to thermal sensor's info bool readThermalSensor(std::string_view sensor_name, float *temp, const bool force_sysfs, - std::string *sensor_log); + std::map<std::string, float> *sensor_log_map); bool connectToPowerHal(); void updateSupportedPowerHints(); void updateCoolingDevices(const std::vector<std::string> &cooling_devices_to_update); |