added some missed functions

This commit is contained in:
Bimmy 2022-08-18 20:37:36 +03:00
parent 3d6b842d20
commit 69c9892c6d
1 changed files with 71 additions and 16 deletions

View File

@ -64,6 +64,16 @@ class ATFApkInstaller
} }
}); });
} }
function getSize()
{
list($status, $lines) = atf_host_exec("ls -sd -- ./{$this->apk_name}", DEPLOY_OPT_ERR_OK|DEPLOY_OPT_SILENT);
if($status != 0)
return 0;
$items = explode(' ', $lines[0]);
//ls -s returns size in blocks where each block is 512 bytes long
return $items[0]*512;
}
} }
@ -196,6 +206,8 @@ class ATFSession
$install = new ATFApkInstaller($apk_name, $override_conf); $install = new ATFApkInstaller($apk_name, $override_conf);
$this->trySendApkStatsEvent($install->getSize());
foreach($this->plans as $plan) foreach($this->plans as $plan)
$this->_runPlan($install, $plan); $this->_runPlan($install, $plan);
@ -250,28 +262,17 @@ class ATFSession
}); });
} }
function trySendApkStatsEvent() function trySendApkStatsEvent($apk_size)
{ {
try try
{ {
$apk_sizeB = get_apk_size(); $msg = "version $this->version($this->rev_hash) size: $apk_size";
$apk_sizeMb = round($apk_sizeB / 1024 / 1024,4);
$version = taskman_prop('GAME_VERSION');
$rev_hash = taskman_prop('GAME_REVISION_HASH');
$msg = "version $version($rev_hash) size: $apk_sizeMb Mb ($apk_sizeB B)";
atf_slack_post($msg, array('channel' => _atf_slack_chan_qa())); atf_slack_post($msg, array('channel' => _atf_slack_chan_qa()));
$data['guid'] = $this->guid;
$data['time'] = time();
$data['version'] = $version;
$data['revHash'] = $rev_hash;
$data['apk_size'] = $apk_sizeB;
atf_stats_send('apk_size', $data);
$data['guid'] = $this->guid;
$data['time'] = time(); $data['time'] = time();
$data['version'] = $this->version; $data['version'] = $this->version;
$data['revHash'] = $this->rev_hash; $data['revHash'] = $this->rev_hash;
$data['guid'] = $this->guid;
$data['branch'] = $this->branch; $data['branch'] = $this->branch;
$data['event'] = 'apk_size'; $data['event'] = 'apk_size';
$data['value'] = $apk_size; $data['value'] = $apk_size;
@ -1232,6 +1233,23 @@ function atf_device_del_file_async($device, $device_path, $opts = 0)
return atf_host_exec_async("%{adb}% -s $device shell rm -rf $device_path", $opts); return atf_host_exec_async("%{adb}% -s $device shell rm -rf $device_path", $opts);
} }
function atf_device_blink($device, $times = 5)
{
//disable auto brightness
atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness_mode 0");
for($i=0;$i<$times;++$i)
{
atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness 255");
sleep(1);
atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness 5");
}
//enable auto brightness
atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness 100");
atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness_mode 1");
}
function atf_device_pull_file_async($device, $device_path, $timeout = 10, $throw_error_on_timeout = false) function atf_device_pull_file_async($device, $device_path, $timeout = 10, $throw_error_on_timeout = false)
{ {
return Amp\call(function() use($device, $device_path, $throw_error_on_timeout, $timeout) { return Amp\call(function() use($device, $device_path, $throw_error_on_timeout, $timeout) {
@ -1317,6 +1335,43 @@ function atf_stats_send($table, array $data)
$db->insert($table, array(array_values($data)), array_keys($data)); $db->insert($table, array(array_values($data)), array_keys($data));
} }
function atf_device_mem_async($device)
{
return Amp\call(function() use($device) {
list($code, $lines) = yield atf_host_exec_async("%{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'] = 1*$items[1];
else if($items && $items[0] === "TOTAL" && $items[1] === "PSS:")
$res['total'] = 1*$items[2];
else if($items && $items[0] === "Native" && $items[1] === "Heap:")
$res['native'] = 1*$items[2];
else if($items && $items[0] === "Java" && $items[1] === "Heap:")
$res['java'] = 1*$items[2];
else if($items && $items[0] === "System:")
$res['system'] = 1*$items[1];
else if($items && $items[0] === "Graphics:")
$res['graphics'] = 1*$items[1];
}
return $res;
});
}
function atf_log($msg) function atf_log($msg)
{ {
echo date("Y-m-d H:i:s") . " " . $msg . "\n"; echo date("Y-m-d H:i:s") . " " . $msg . "\n";