diff --git a/atf.inc.php b/atf.inc.php index 3ac6116..4b5f1b6 100644 --- a/atf.inc.php +++ b/atf.inc.php @@ -1,6 +1,8 @@ runAsync($install, $sleep_time = 4, $hung_threshold = 80, $gone_threshold = 30, $stuck_threshold = 200)); } - // function trySendStatsFromJzonAsync(ATFTask $task, $jzon) - // { - // return Amp\call(function() use($task, $jzon) { + function trySendStatsFromJzonAsync(ATFTask $task, $jzon) + { + return Amp\call(function() use($task, $jzon) { - // try - // { - // $data = jzon_parse(trim(str_replace('\"', '"', $jzon))); - // $table = $data['table']; - // unset($data['table']); + try + { + $data = jzon_parse(trim(str_replace('\"', '"', $jzon))); + $table = $data['table']; + unset($data['table']); - // if(isset($data['deviceMemoryUsage']) && $data['deviceMemoryUsage'] === '') - // { - // $mem = yield atf_device_mem_async($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']; - // } - // } - // $this->trySendStats($task, $table, $data); - // } - // catch(Exception $e) - // { - // echo $e->getMessage() . "\n"; - // } + if(isset($data['deviceMemoryUsage']) && $data['deviceMemoryUsage'] === '') + { + $mem = yield atf_device_mem_async($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']; + } + } + $this->trySendStats($task, $table, $data); + } + catch(Exception $e) + { + echo $e->getMessage() . "\n"; + } - // }); - // } + }); + } -// function trySendApkStatsEvent() -// { -// try -// { -// $apk_sizeB = get_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())); - -// $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); + function trySendApkStatsEvent() + { + try + { + $apk_sizeB = get_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())); + + $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['version'] = $this->version; -// $data['revHash'] = $this->rev_hash; -// $data['branch'] = $this->branch; -// $data['event'] = 'apk_size'; -// $data['value'] = $apk_size; -// atf_stats_send('event_value', $data); -// } -// catch(Exception $e) -// { -// echo $e->getMessage() . "\n"; -// } -// } + $data['guid'] = $this->guid; + $data['time'] = time(); + $data['version'] = $this->version; + $data['revHash'] = $this->rev_hash; + $data['branch'] = $this->branch; + $data['event'] = 'apk_size'; + $data['value'] = $apk_size; + atf_stats_send('event_value', $data); + } + catch(Exception $e) + { + echo $e->getMessage() . "\n"; + } + } -// function trySendStats(ATFTask $task, $table, array $data) -// { -// try -// { -// $data['guid'] = $this->guid; -// $data['time'] = time(); -// $data['deviceId'] = $task->device; -// atf_stats_send($table, $data); -// } -// catch(Exception $e) -// { -// echo $e->getMessage() . "\n"; -// } -// } + function trySendStats(ATFTask $task, $table, array $data) + { + try + { + $data['guid'] = $this->guid; + $data['time'] = time(); + $data['deviceId'] = $task->device; + atf_stats_send($table, $data); + } + catch(Exception $e) + { + echo $e->getMessage() . "\n"; + } + } -// function trySendStatsEvent(ATFTask $task, $event, $value = 1) -// { -// $this->trySendStats( -// $task, -// 'event_value', -// array( -// 'event' => $event, -// 'value' => $value, -// 'branch' => $this->branch, -// 'version' => $this->version, -// 'revHash' => $this->rev_hash -// ) -// ); -// } + function trySendStatsEvent(ATFTask $task, $event, $value = 1) + { + $this->trySendStats( + $task, + 'event_value', + array( + 'event' => $event, + 'value' => $value, + 'branch' => $this->branch, + 'version' => $this->version, + 'revHash' => $this->rev_hash + ) + ); + } // function tryShareToQAChannel($msg_slack_id, $error) // { @@ -749,7 +751,7 @@ class ATFPlan if($not_alive_time > $hung_threshold) { $task->addStatusCode(ATFTask::CODE_HUNG); - // $this->session->trySendStatsEvent($task, 'hung'); + $this->session->trySendStatsEvent($task, 'hung'); atf_log("[HNG] No activity for $hung_threshold seconds *{$task->device}*"); $device_is_bogus = true; } @@ -761,13 +763,13 @@ class ATFPlan if($task->last_alive_check_time === $task->reset_time) { $task->addStatusCode(ATFTask::CODE_NSTART); - // $this->session->trySendStatsEvent($task, 'nstart'); + $this->session->trySendStatsEvent($task, 'nstart'); atf_log("[NFD] No app started after $hung_threshold seconds *{$task->device}*"); } else { $task->addStatusCode(ATFTask::CODE_GONE); - // $this->session->trySendStatsEvent($task, 'gone'); + $this->session->trySendStatsEvent($task, 'gone'); atf_log("[GNE] App is gone after $hung_threshold seconds *{$task->device}*"); } $device_is_bogus = true; @@ -779,7 +781,7 @@ class ATFPlan else if($stuck_time > $stuck_threshold) { $task->addStatusCode(ATFTask::CODE_STUCK); - // $this->session->trySendStatsEvent($task, 'stuck'); + $this->session->trySendStatsEvent($task, 'stuck'); atf_log("[STK] Stuck for $stuck_threshold seconds *{$task->device}*"); } @@ -849,8 +851,8 @@ class ATFPlan $task->addStatusCode($item['error'], $item['message']); - // if($item['error'] == ATFTask::CODE_EXCEPTION) - // $this->session->trySendStatsEvent($task, 'exception'); + if($item['error'] == ATFTask::CODE_EXCEPTION) + $this->session->trySendStatsEvent($task, 'exception'); list($msg_type, $msg_text) = self::_parseExtMessage($item['message']); @@ -883,8 +885,8 @@ class ATFPlan $this->session->resetBogusDeviceCount($task->device); $task->onProgress($msg_text); } - // else if($msg_type === '[STAT]') - // yield $this->session->trySendStatsFromJzonAsync($task, $msg_text); + else if($msg_type === '[STAT]') + yield $this->session->trySendStatsFromJzonAsync($task, $msg_text); else if($msg_type === '[WRN]') { $task->addStatusCode(ATFTask::CODE_WARN); @@ -1292,6 +1294,27 @@ function _atf_trim_start($txt, $max_len) return strlen($txt) > $max_len ? "..." . substr($txt, strlen($txt) - $max_len) : $txt; } +function _atf_db() +{ + $config = array( + 'host' => '172.19.179.148', + 'port' => '8123', + 'username' => get('ATF_CLICKHOUSE_USERNAME'), + 'password' => get('ATF_CLICKHOUSE_PASSWORD') + ); + $db = new ClickHouseDB\Client($config); + $db->database(get('ATF_CLICKHOUSE_DB')); + $db->setTimeout(10); + $db->setConnectTimeOut(5); + return $db; +} + +function atf_stats_send($table, array $data) +{ + $db = _atf_db(); + return; + $db->insert($table, array(array_values($data)), array_keys($data)); +} function atf_log($msg) { @@ -1459,7 +1482,6 @@ function atf_host() return $node_name; } - function _atf_opt(array &$args, $opt, $default, $conv_fn = null) { foreach($args as $idx => $arg)