Making it possible to register custom stats event hooks; Adding device CPU top and LA probing routines
Publish PHP Package / docker (push) Successful in 7s
Details
Publish PHP Package / docker (push) Successful in 7s
Details
This commit is contained in:
parent
721894b4a4
commit
c24039a694
81
atf.inc.php
81
atf.inc.php
|
@ -396,22 +396,6 @@ function _multi_curl_async($ch, $get_content) : Amp\Promise
|
|||
});
|
||||
}
|
||||
|
||||
function device_screen(string $atf_host, string $device)
|
||||
{
|
||||
$screen_file_name = '%{dir}%/'.uniqid("screen_").'.png';
|
||||
try
|
||||
{
|
||||
host_exec($atf_host, "%{adb}% -s $device exec-out screencap -p > $screen_file_name");
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$data = host_get_file($atf_host, $screen_file_name);
|
||||
host_exec($atf_host, "rm -rf $screen_file_name");
|
||||
return $data;
|
||||
}
|
||||
|
||||
function del_external_files_async(string $atf_host, string $device, array $external_files) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device, $external_files) {
|
||||
|
@ -483,68 +467,3 @@ function _filter_error_logs(array &$lines)
|
|||
$lines = $filtered;
|
||||
}
|
||||
|
||||
function device_pss_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
$res = yield device_mem_async($atf_host, $device);
|
||||
return $res['total'];
|
||||
});
|
||||
}
|
||||
|
||||
function device_mem_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell dumpsys meminfo -s %{package_id}%", DEPLOY_OPT_ERR_OK, 20);
|
||||
|
||||
$res = array(
|
||||
'total' => 0,
|
||||
'native' => 0,
|
||||
'java' => 0,
|
||||
'system' => 0,
|
||||
'graphics' => 0,
|
||||
);
|
||||
|
||||
if($code !== 0)
|
||||
return $res;
|
||||
|
||||
foreach($lines as $idx => $line)
|
||||
{
|
||||
$items = preg_split('/\s+/', trim($line));
|
||||
if($items && $items[0] === "TOTAL:")
|
||||
$res['total'] = intval($items[1]);
|
||||
else if($items && $items[0] === "TOTAL" && $items[1] === "PSS:")
|
||||
$res['total'] = intval($items[2]);
|
||||
else if($items && $items[0] === "Native" && $items[1] === "Heap:")
|
||||
$res['native'] = intval($items[2]);
|
||||
else if($items && $items[0] === "Java" && $items[1] === "Heap:")
|
||||
$res['java'] = intval($items[2]);
|
||||
else if($items && $items[0] === "System:")
|
||||
$res['system'] = intval($items[1]);
|
||||
else if($items && $items[0] === "Graphics:")
|
||||
$res['graphics'] = intval($items[1]);
|
||||
}
|
||||
|
||||
return $res;
|
||||
});
|
||||
}
|
||||
|
||||
function device_temperature_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
//NOTE: on current devices 16 thermal zone is responsible for GPU temperature probing
|
||||
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)
|
||||
return 0;
|
||||
|
||||
foreach($lines as $idx => $line)
|
||||
{
|
||||
$line = trim($line);
|
||||
if(!$line)
|
||||
continue;
|
||||
return intval($line);
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
138
device.inc.php
138
device.inc.php
|
@ -160,3 +160,141 @@ class CachedDevices implements IDevicePool
|
|||
}
|
||||
}
|
||||
|
||||
function device_screen(string $atf_host, string $device)
|
||||
{
|
||||
$screen_file_name = '%{dir}%/'.uniqid("screen_").'.png';
|
||||
try
|
||||
{
|
||||
host_exec($atf_host, "%{adb}% -s $device exec-out screencap -p > $screen_file_name");
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$data = host_get_file($atf_host, $screen_file_name);
|
||||
host_exec($atf_host, "rm -rf $screen_file_name");
|
||||
return $data;
|
||||
}
|
||||
|
||||
function device_pss_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
$res = yield device_mem_async($atf_host, $device);
|
||||
return $res['total'];
|
||||
});
|
||||
}
|
||||
|
||||
function device_mem_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell dumpsys meminfo -s %{package_id}%", DEPLOY_OPT_ERR_OK, 20);
|
||||
|
||||
$res = array(
|
||||
'total' => 0,
|
||||
'native' => 0,
|
||||
'java' => 0,
|
||||
'system' => 0,
|
||||
'graphics' => 0,
|
||||
);
|
||||
|
||||
if($code !== 0)
|
||||
return $res;
|
||||
|
||||
foreach($lines as $idx => $line)
|
||||
{
|
||||
$items = preg_split('/\s+/', trim($line));
|
||||
if($items && $items[0] === "TOTAL:")
|
||||
$res['total'] = intval($items[1]);
|
||||
else if($items && $items[0] === "TOTAL" && $items[1] === "PSS:")
|
||||
$res['total'] = intval($items[2]);
|
||||
else if($items && $items[0] === "Native" && $items[1] === "Heap:")
|
||||
$res['native'] = intval($items[2]);
|
||||
else if($items && $items[0] === "Java" && $items[1] === "Heap:")
|
||||
$res['java'] = intval($items[2]);
|
||||
else if($items && $items[0] === "System:")
|
||||
$res['system'] = intval($items[1]);
|
||||
else if($items && $items[0] === "Graphics:")
|
||||
$res['graphics'] = intval($items[1]);
|
||||
}
|
||||
|
||||
return $res;
|
||||
});
|
||||
}
|
||||
|
||||
function device_cpuinfo_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell dumpsys cpuinfo -s %{package_id}%", DEPLOY_OPT_ERR_OK, 20);
|
||||
|
||||
$res = array(
|
||||
'la1' => 0,
|
||||
'la5' => 0,
|
||||
'la15' => 0
|
||||
);
|
||||
|
||||
if($code !== 0 || count($lines) == 0)
|
||||
return $res;
|
||||
|
||||
foreach($lines as $idx => $line)
|
||||
{
|
||||
if(strpos($line, 'Load:') !== false)
|
||||
{
|
||||
$items = explode(':', $line);
|
||||
$sub_items = explode('/', $items[1]);
|
||||
|
||||
$res['la1'] = floatval(trim($sub_items[0]));
|
||||
$res['la5'] = floatval(trim($sub_items[1]));
|
||||
$res['la15'] = floatval(trim($sub_items[2]));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
});
|
||||
}
|
||||
|
||||
function device_cputop_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($atf_host, $device) {
|
||||
list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell top -q -o'%CPU,PID,CMDLINE' -n1 -s1 | grep -w %{package_id}%", DEPLOY_OPT_ERR_OK, 20);
|
||||
|
||||
$cpu = 0;
|
||||
|
||||
if($code !== 0 || count($lines) == 0)
|
||||
return $cpu;
|
||||
|
||||
foreach($lines as $idx => $line)
|
||||
{
|
||||
$items = preg_split('/\s+/', trim($line));
|
||||
if(count($items) > 0)
|
||||
{
|
||||
$cpu = intval($items[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $cpu;
|
||||
});
|
||||
}
|
||||
|
||||
function device_temperature_async(string $atf_host, string $device) : Amp\Promise
|
||||
{
|
||||
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 cat /sys/class/thermal/thermal_zone16/temp", DEPLOY_OPT_ERR_OK, 1);
|
||||
|
||||
if($code !== 0)
|
||||
return 0;
|
||||
|
||||
foreach($lines as $idx => $line)
|
||||
{
|
||||
$line = trim($line);
|
||||
if(!$line)
|
||||
continue;
|
||||
return intval($line);
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class SessionConfig
|
|||
public IMChan $im_qa;
|
||||
public IStatsSender $stats;
|
||||
public string $device_replay_path = 'replay.txt';
|
||||
public array $stats_event_listeners = array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
@ -40,6 +41,11 @@ class SessionConfig
|
|||
$this->atf_host = 'atf';
|
||||
taskman\deploy_declare_node($this->atf_host, $settings);
|
||||
}
|
||||
|
||||
function registerStatsEventListener(callable $hook)
|
||||
{
|
||||
$this->stats_event_listeners[] = $hook;
|
||||
}
|
||||
}
|
||||
|
||||
class Session
|
||||
|
@ -174,6 +180,7 @@ class Session
|
|||
if($this->conf->adb_reboot)
|
||||
adb_reboot($this->conf->atf_host);
|
||||
|
||||
//TODO: should not be here
|
||||
$this->trySendApkStatsEvent($this->apk_installer->getSize());
|
||||
|
||||
$all_tasks = $this->_getAllTasks();
|
||||
|
@ -387,8 +394,9 @@ class Session
|
|||
$table = $data['table'];
|
||||
unset($data['table']);
|
||||
|
||||
$data = yield $this->inflateMissingStats($task, $table, $data);
|
||||
$data = yield $this->applyStatsEventsListeners($task, $table, $data);
|
||||
|
||||
if($data !== null)
|
||||
$this->trySendStats($task, $table, $data);
|
||||
}
|
||||
catch(Exception $e)
|
||||
|
@ -399,27 +407,12 @@ class Session
|
|||
});
|
||||
}
|
||||
|
||||
//TODO: make it more flexible via plugin alike system?
|
||||
function inflateMissingStats(Task $task, string $table, array $data) : Amp\Promise
|
||||
function applyStatsEventsListeners(Task $task, string $table, array $data) : Amp\Promise
|
||||
{
|
||||
return Amp\call(function() use($task, $table, $data) {
|
||||
//NOTE: filling memory usage if it's not set
|
||||
if(isset($data['deviceMemoryUsage']) && $data['deviceMemoryUsage'] === '')
|
||||
{
|
||||
$mem = yield device_mem_async($this->conf->atf_host, $task->device);
|
||||
$data['deviceMemoryUsage'] = $mem['total'];
|
||||
if($table === 'device_memory')
|
||||
{
|
||||
$data['deviceMemoryUsageNative'] = $mem['native'];
|
||||
$data['deviceMemoryUsageSystem'] = $mem['system'];
|
||||
$data['deviceMemoryUsageJava'] = $mem['java'];
|
||||
$data['deviceMemoryUsageGraphics'] = $mem['graphics'];
|
||||
}
|
||||
}
|
||||
|
||||
//NOTE: filling CPU temperature
|
||||
if(isset($data['event']) && $data['event'] == 'cpuTemp')
|
||||
$data['value'] = yield device_temperature_async($this->conf->atf_host, $task->device);
|
||||
foreach($this->conf->stats_event_listeners as $hook)
|
||||
$data = yield $hook($this, $task, $table, $data);
|
||||
|
||||
return $data;
|
||||
});
|
||||
|
@ -429,6 +422,7 @@ class Session
|
|||
{
|
||||
try
|
||||
{
|
||||
$data = array();
|
||||
$data['guid'] = $this->guid;
|
||||
$data['time'] = time();
|
||||
$data['version'] = $this->conf->proj_version;
|
||||
|
|
Loading…
Reference in New Issue