From b67512ba68715903eab62ea0951640a62ee88ef3 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Fri, 30 Mar 2018 10:53:12 -0700 Subject: [PATCH] ThermalHAL: add dump into bugreport lshal-debug/android.hardware.thermal@1.1::IThermal_default.txt: getTemperatures: Name: usb_port_temp Type: UNKNOWN CurrentValue: 30.7 ThrottlingThreshold: nan ShutdownThreshold: nan VrThrottlingThreshold: nan Name: back_therm Type: SKIN CurrentValue: 30 ThrottlingThreshold: 40 ShutdownThreshold: 56 VrThrottlingThreshold: 52 Name: tsens_tz_sensor4 Type: CPU CurrentValue: 42.7 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: tsens_tz_sensor2 Type: CPU CurrentValue: 43 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: battery Type: BATTERY CurrentValue: 28 ThrottlingThreshold: nan ShutdownThreshold: 60 VrThrottlingThreshold: nan Name: tsens_tz_sensor13 Type: GPU CurrentValue: 40.8 ThrottlingThreshold: nan ShutdownThreshold: nan VrThrottlingThreshold: nan Name: tsens_tz_sensor10 Type: CPU CurrentValue: 42.1 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: tsens_tz_sensor9 Type: CPU CurrentValue: 42.4 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: tsens_tz_sensor3 Type: CPU CurrentValue: 42.4 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: tsens_tz_sensor8 Type: CPU CurrentValue: 41.7 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: tsens_tz_sensor7 Type: CPU CurrentValue: 42.1 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 Name: tsens_tz_sensor1 Type: CPU CurrentValue: 43.3 ThrottlingThreshold: 95 ShutdownThreshold: 115 VrThrottlingThreshold: 95 getCpuUsages: Name: CPU0 Active: 3144 Total: 6725 IsOnline: 1 Name: CPU1 Active: 3128 Total: 6943 IsOnline: 1 Name: CPU2 Active: 2128 Total: 6692 IsOnline: 1 Name: CPU3 Active: 1936 Total: 6893 IsOnline: 1 Name: CPU4 Active: 2165 Total: 7027 IsOnline: 1 Name: CPU5 Active: 2356 Total: 7046 IsOnline: 1 Name: CPU6 Active: 3757 Total: 7022 IsOnline: 1 Name: CPU7 Active: 3748 Total: 7049 IsOnline: 1 Test: take BR Bug: 77301612 Bug: 72071908 Change-Id: Ib10ab86731df4cee3c7523c54c5dce51f2038156 --- thermal/Thermal.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++-- thermal/Thermal.h | 2 ++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/thermal/Thermal.cpp b/thermal/Thermal.cpp index 7b29b29de..b47a54d82 100644 --- a/thermal/Thermal.cpp +++ b/thermal/Thermal.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "Thermal.h" @@ -55,12 +56,11 @@ Return Thermal::getTemperatures(getTemperatures_cb _hidl_cb) { hidl_vec temperatures; temperatures.resize(kTemperatureNum); - LOG(INFO) << "ThermalHAL enabled: " << enabled; - if (!enabled) { status.code = ThermalStatusCode::FAILURE; status.debugMessage = "Unsupported hardware"; _hidl_cb(status, temperatures); + LOG(ERROR) << "ThermalHAL not initialized properly."; return Void(); } @@ -93,6 +93,7 @@ Return Thermal::getCpuUsages(getCpuUsages_cb _hidl_cb) { status.code = ThermalStatusCode::FAILURE; status.debugMessage = "Unsupported hardware"; _hidl_cb(status, cpuUsages); + LOG(ERROR) << "ThermalHAL not initialized properly."; return Void(); } @@ -123,6 +124,7 @@ Return Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) { status.code = ThermalStatusCode::FAILURE; status.debugMessage = "Unsupported hardware"; _hidl_cb(status, coolingDevices); + LOG(ERROR) << "ThermalHAL not initialized properly."; return Void(); } @@ -177,6 +179,58 @@ void Thermal::notifyThrottling( } } +Return Thermal::debug(const hidl_handle& handle, const hidl_vec&) { + if (handle != nullptr && handle->numFds >= 1) { + int fd = handle->data[0]; + std::ostringstream dump_buf; + + if (!enabled) { + dump_buf << "ThermalHAL not initialized properly." << std::endl; + } else { + hidl_vec temperatures; + hidl_vec cpu_usages; + cpu_usages.resize(kCpuNum); + temperatures.resize(kTemperatureNum); + + dump_buf << "getTemperatures:" << std::endl; + if (fillTemperatures(&temperatures) != kTemperatureNum) { + dump_buf << "Failed to read thermal sensors." << std::endl; + } else { + for (const auto& t : temperatures) { + dump_buf << "Name: " << t.name + << " Type: " << android::hardware::thermal::V1_0::toString(t.type) + << " CurrentValue: " << t.currentValue + << " ThrottlingThreshold: " << t.throttlingThreshold + << " ShutdownThreshold: " << t.shutdownThreshold + << " VrThrottlingThreshold: " << t.vrThrottlingThreshold + << std::endl; + } + } + + dump_buf << "getCpuUsages:" << std::endl; + ssize_t ret = fillCpuUsages(&cpu_usages); + if (ret < 0) { + dump_buf << "Failed to get CPU usages." << std::endl; + } else { + for (const auto& usage : cpu_usages) { + dump_buf << "Name: " << usage.name + << " Active: " << usage.active + << " Total: " << usage.total + << " IsOnline: " << usage.isOnline + << std::endl; + } + } + + } + std::string buf = dump_buf.str(); + if (!android::base::WriteStringToFd(buf, fd)) { + PLOG(ERROR) << "Failed to dump state to fd"; + } + fsync(fd); + } + return Void(); +} + } // namespace implementation } // namespace V1_1 } // namespace thermal diff --git a/thermal/Thermal.h b/thermal/Thermal.h index d3ac2f9a3..270f06630 100644 --- a/thermal/Thermal.h +++ b/thermal/Thermal.h @@ -54,6 +54,8 @@ struct Thermal : public IThermal { // Methods from ::android::hardware::thermal::V1_1::IThermal follow. Return registerThermalCallback( const sp& callback) override; + // Methods from ::android::hidl::base::V1_0::IBase follow. + Return debug(const hidl_handle& fd, const hidl_vec& args) override; private: bool enabled; };