device_temperature_async now relies on dumpsys thermalservice, temperature output format changed

This commit is contained in:
Alexey Chubar 2024-09-23 17:34:46 +03:00
parent c24039a694
commit dacaefab40
1 changed files with 40 additions and 12 deletions

View File

@ -281,20 +281,48 @@ function device_cputop_async(string $atf_host, string $device) : Amp\Promise
function device_temperature_async(string $atf_host, string $device) : Amp\Promise function device_temperature_async(string $atf_host, string $device) : Amp\Promise
{ {
return Amp\call(function() use($atf_host, $device) { return Amp\call(function() use($atf_host, $device) {
//NOTE: on current devices 16 thermal zone are responsible for GPU temperature probing list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell dumpsys thermalservice", DEPLOY_OPT_ERR_OK, 1);
list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell cat /sys/class/thermal/thermal_zone16/temp", DEPLOY_OPT_ERR_OK, 1);
if($code !== 0) if($code !== 0)
return 0; return array();
foreach($lines as $idx => $line) return device_parse_soc_temps($lines);
{
$line = trim($line);
if(!$line)
continue;
return intval($line);
}
return 0;
}); });
} }
function device_parse_soc_temps($thermal_output_lines)
{
$cpu_temp = null;
$gpu_temp = null;
$hal_section_found = false;
foreach($thermal_output_lines as $line)
{
if(!$hal_section_found)
{
if(strpos($line, 'Current temperatures from HAL:') !== false)
$hal_section_found = true;
continue;
}
if(strpos($line, 'mType=0') !== false) //Type 0 indicates CPI
$cpu_temp = device_parse_thermal_line($line);
if(strpos($line, 'mType=1') !== false) //Type 1 indicates GPU
$gpu_temp = device_parse_thermal_line($line);
if($cpu_temp && $gpu_temp)
break;
}
return [
'cpu_temp' => $cpu_temp,
'gpu_temp' => $gpu_temp
];
}
function device_parse_thermal_line($line)
{
return preg_match('/mValue=([^,]+)/', $line, $matches) ? floatval($matches[1]) : null;
}