本文整理汇总了PHP中GetTestInfo函数的典型用法代码示例。如果您正苦于以下问题:PHP GetTestInfo函数的具体用法?PHP GetTestInfo怎么用?PHP GetTestInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetTestInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CheckTest
function CheckTest($dir)
{
global $count;
echo "\r{$count}: Checking {$dir} ";
$testinfo = GetTestInfo($dir);
if ($testinfo) {
if ($testinfo['started'] && $testinfo['completed']) {
$elapsed = ($testinfo['completed'] - $testinfo['started']) / 60;
if ($elapsed > 25) {
$count++;
echo "\rLong test detected: {$testinfo['id']} ({$elapsed} minutes) \n";
echo "Url: {$testinfo['url']}\n";
echo "ID: {$testinfo['id']}\n";
echo "Key: {$testinfo['key']}\n";
echo "Location: {$testinfo['location']}\n";
echo "Runs: {$testinfo['runs']}\n";
if (strlen($testinfo['key'])) {
echo "API Key: {$testinfo['key']}\n";
}
if (strlen($testinfo['script'])) {
echo "Script:\n{$testinfo['script']}\n";
}
echo "\n";
}
}
}
}
示例2: GetVisualProgress
/**
* Calculate the progress for all of the images in a given directory
*/
function GetVisualProgress($testPath, $run, $cached, $options = null, $end = null, $startOffset = null)
{
// TODO: in the long run this function might get redundant as the version below is more flexible
$frames = null;
$testPath = $testPath[0] == '.' || $testPath[0] == "/" ? $testPath : "./{$testPath}";
$localPaths = new TestPaths($testPath, $run, $cached);
$testInfo = GetTestInfo($testPath);
$completed = IsTestRunComplete($run, $testInfo);
return GetVisualProgressForStep($localPaths, $completed, $options, $end, $startOffset);
}
示例3: fromFiles
public static function fromFiles($rootDirectory, $touchFile = true)
{
$test = array();
$iniPath = $rootDirectory . "/testinfo.ini";
if (is_file($iniPath)) {
$test = parse_ini_file($iniPath, true);
if (!$touchFile) {
touch($iniPath);
}
}
$test["testinfo"] = GetTestInfo($rootDirectory);
return new self($test['testinfo']["id"], $rootDirectory, $test);
}
示例4: CronProcess
function CronProcess($path, $maxAllowedAge)
{
$file = $path . 'testinfo.ini';
if (is_file($file)) {
$testInfo = GetTestInfo($path);
if ($testInfo) {
if (array_key_exists('archived', $testInfo) && $testInfo['archived']) {
$currentTime = time();
$timestamp = filemtime($file);
if ($maxAllowedAge < $currentTime - $timestamp) {
// Remove the expired test results from the
echo "{$path}: expired and deleted.\r\n";
delTree($path);
}
} else {
$info = parse_ini_file($file, true);
if (isset($info['test']['completeTime'])) {
// Deal with the pre-existing test results. Upload them into
// remote storage.
require_once 'storage/storage.inc';
$id = $info['test']['id'];
StoreResults($id);
// StoreResults always generates zipped testinfo.json. We
// delete the unzipped version if there is here.
if (is_file($path . 'testinfo.json')) {
unlink($path . 'testinfo.json');
}
echo "test {$id} is uploaded.\r\n";
}
}
}
} else {
$paths = glob($path . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
foreach ($paths as $path) {
CronProcess($path, $maxAllowedAge);
}
}
}
示例5: CancelTest
/**
* Cancel and individual test
*
* @param mixed $id
*/
function CancelTest($id)
{
$lock = LockTest($id);
if ($lock) {
$cancelled = false;
$testInfo = GetTestInfo($id);
if ($testInfo && !array_key_exists('started', $testInfo)) {
$testInfo['cancelled'] = time();
SaveTestInfo($id, $testInfo);
// delete the actual test file.
if (array_key_exists('workdir', $testInfo)) {
$ext = 'url';
if ($testInfo['priority']) {
$ext = "p{$testInfo['priority']}";
}
$queued_job_file = $testInfo['workdir'] . "/{$id}.{$ext}";
$cancelled = unlink($queued_job_file);
}
}
UnlockTest($lock);
}
return $cancelled;
}
示例6: GetTestPath
<ul class="ui-tabs-nav">
<li class="analytical_review"><a href="/">Analytical Review</a></li>
<li class="visual_comparison ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#">Visual Comparison</a></li>
<li class="traceroute"><a href="/traceroute">Traceroute</a></li>
</ul>
<div id="visual_comparison" class="test_box">
<p>Enter multiple urls to compare them against each other visually.</p>
<input type="hidden" id="nextid" value="2">
<div id="urls">
<?php
if ($tid) {
$testPath = './' . GetTestPath($tid);
$pageData = loadAllPageData($testPath);
$url = trim($pageData[1][0]['URL']);
$testInfo = GetTestInfo($tid);
$label = trim($testInfo['label']);
if (strlen($url)) {
echo '<div id="urldiv0" class="urldiv">';
echo "<input type=\"hidden\" id=\"tid\" name=\"tid\" value=\"{$tid}\">";
echo "<input type=\"hidden\" id=\"run\" name=\"run\" value=\"{$run}\">";
echo "Label: <input id=\"tidlabel\" type=\"text\" name=\"tidlabel\" value=\"{$label}\" style=\"width:10em\"> ";
echo "URL: <input id=\"tidurl\" type=\"text\" style=\"width:30em\" value=\"{$url}\" disabled=\"disabled\"> ";
echo "<a href='#' onClick='return RemoveUrl(\"#urldiv0\");'>Remove</a>";
echo "</div>\n";
}
}
?>
<div id="urldiv1" class="urldiv">
Label: <input id="label1" type="text" name="label[1]" style="width:10em">
URL: <input id="url1" type="text" name="url[1]" style="width:30em">
示例7: GetVisualProgress
/**
* Calculate the progress for all of the images in a given directory
*/
function GetVisualProgress($testPath, $run, $cached, $options = null, $end = null, $startOffset = null)
{
$frames = null;
if (substr($testPath, 0, 1) !== '.') {
$testPath = './' . $testPath;
}
$testInfo = GetTestInfo($testPath);
$completed = IsTestRunComplete($run, $testInfo);
$video_directory = "{$testPath}/video_{$run}";
if ($cached) {
$video_directory .= '_cached';
}
$cache_file = "{$testPath}/{$run}.{$cached}.visual.dat";
if (!isset($startOffset)) {
$startOffset = 0;
}
$visual_data_file = "{$testPath}/llab_{$run}.{$cached}.visual.dat";
if (gz_is_file($visual_data_file)) {
$visual_data = json_decode(gz_file_get_contents($visual_data_file), true);
// see if we are processing an externally-uploaded visual data file
if (isset($visual_data['timespans']['page_load']['startOffset'])) {
$startOffset += $visual_data['timespans']['page_load']['startOffset'];
}
}
$dirty = false;
$current_version = VIDEO_CODE_VERSION;
if (isset($end)) {
if (is_numeric($end)) {
$end = (int) ($end * 1000);
} else {
unset($end);
}
}
if (!isset($end) && !isset($options) && gz_is_file($cache_file)) {
$frames = json_decode(gz_file_get_contents($cache_file), true);
if (!array_key_exists('frames', $frames) || !array_key_exists('version', $frames)) {
unset($frames);
} elseif (array_key_exists('version', $frames) && $frames['version'] !== $current_version) {
unset($frames);
}
}
$base_path = substr($video_directory, 1);
if ((!isset($frames) || !count($frames)) && (is_dir($video_directory) || gz_is_file("{$testPath}/{$run}.{$cached}.histograms.json"))) {
$frames = array('version' => $current_version);
$frames['frames'] = array();
$dirty = true;
if (is_dir($video_directory)) {
$files = scandir($video_directory);
$last_file = null;
$first_file = null;
$previous_file = null;
foreach ($files as $file) {
if (strpos($file, 'frame_') !== false && strpos($file, '.hist') === false) {
$parts = explode('_', $file);
if (count($parts) >= 2) {
$time = (int) $parts[1] * 100 - $startOffset;
if ($time >= 0 && (!isset($end) || $time <= $end)) {
if (isset($previous_file) && !array_key_exists(0, $frames['frames']) && $time > 0) {
$frames['frames'][0] = array('path' => "{$base_path}/{$previous_file}", 'file' => $previous_file);
$first_file = $previous_file;
} elseif (!isset($first_file)) {
$first_file = $file;
}
$last_file = $file;
$frames['frames'][$time] = array('path' => "{$base_path}/{$file}", 'file' => $file);
}
$previous_file = $file;
}
} elseif (strpos($file, 'ms_') !== false && strpos($file, '.hist') === false) {
$parts = explode('_', $file);
if (count($parts) >= 2) {
$time = intval($parts[1]) - $startOffset;
if ($time >= 0 && (!isset($end) || $time <= $end)) {
if (isset($previous_file) && !array_key_exists(0, $frames['frames']) && $time > 0) {
$frames['frames'][0] = array('path' => "{$base_path}/{$previous_file}", 'file' => $previous_file);
$first_file = $previous_file;
} elseif (!isset($first_file)) {
$first_file = $file;
}
$last_file = $file;
$frames['frames'][$time] = array('path' => "{$base_path}/{$file}", 'file' => $file);
}
$previous_file = $file;
}
}
}
if (count($frames['frames']) == 1) {
foreach ($frames['frames'] as $time => &$frame) {
$frame['progress'] = 100;
$frames['complete'] = $time;
}
} elseif (isset($first_file) && strlen($first_file) && isset($last_file) && strlen($last_file) && count($frames['frames'])) {
$histograms = null;
if (gz_is_file("{$testPath}/{$run}.{$cached}.histograms.json")) {
$histograms = json_decode(gz_file_get_contents("{$testPath}/{$run}.{$cached}.histograms.json"), true);
}
$start_histogram = GetImageHistogram("{$video_directory}/{$first_file}", $options, $histograms);
//.........这里部分代码省略.........
示例8: GetDevToolsProgress
/**
* Calculate the visual progress and speed index from the dev tools timeline trace
*
* @param mixed $testPath
* @param mixed $run
* @param mixed $cached
*/
function GetDevToolsProgress($testPath, $run, $cached)
{
$progress = GetCachedDevToolsProgress($testPath, $run, $cached);
if (!isset($progress) || !is_array($progress)) {
$testInfo = GetTestInfo($testPath);
$completed = IsTestRunComplete($run, $testInfo);
$startOffset = null;
if (GetTimeline($testPath, $run, $cached, $timeline, $startOffset)) {
$cachedText = '';
if ($cached) {
$cachedText = '_Cached';
}
$console_log_file = "{$testPath}/{$run}{$cachedText}_console_log.json";
$console_log = array();
$progress = array();
$startTime = 0;
$fullScreen = 0;
$regions = array();
$viewport = null;
if (DevToolsHasLayout($timeline, $viewport)) {
$didLayout = false;
$didReceiveResponse = false;
} else {
$didLayout = true;
$didReceiveResponse = true;
}
$startTimes = array();
$progress['processing'] = array();
foreach ($timeline as &$entry) {
if (array_key_exists('method', $entry)) {
if (array_key_exists('params', $entry) && !array_key_exists($entry['method'], $startTimes)) {
if (array_key_exists('timestamp', $entry['params'])) {
$startTimes[$entry['method']] = $entry['params']['timestamp'];
} elseif (array_key_exists('record', $entry['params']) && array_key_exists('startTime', $entry['params']['record'])) {
$startTimes[$entry['method']] = $entry['params']['record']['startTime'];
}
}
} elseif (array_key_exists('timestamp', $entry) && !array_key_exists('timestamp', $startTimes)) {
$startTimes['timestamp'] = $entry['timestamp'];
}
$frame = '0';
ProcessPaintEntry($entry, $fullScreen, $regions, $frame, $didLayout, $didReceiveResponse, $viewport);
if (!isset($entry['params']['record']['thread']) || $entry['params']['record']['thread'] == 0) {
GetTimelineProcessingTimes($entry, $progress['processing'], $processing_start, $processing_end);
}
if (DevToolsMatchEvent('Console.messageAdded', $entry) && array_key_exists('message', $entry['params']) && is_array($entry['params']['message'])) {
$console_log[] = $entry['params']['message'];
}
}
if (!gz_is_file($console_log_file)) {
gz_file_put_contents($console_log_file, json_encode($console_log));
}
if (count($progress['processing'])) {
$proc_total = 0.0;
foreach ($progress['processing'] as $type => &$procTime) {
$proc_total += $procTime;
$procTime = intval(round($procTime));
}
$progress['processing']['Idle'] = 0;
if (isset($processing_start) && isset($processing_end) && $processing_end > $processing_start) {
$proc_elapsed = $processing_end - $processing_start;
if ($proc_elapsed > $proc_total) {
$progress['processing']['Idle'] = intval(round($proc_elapsed - $proc_total));
}
}
} else {
unset($progress['processing']);
}
foreach ($startTimes as $time) {
if (!$startTime || $time < $startTime) {
$startTime = $time;
}
}
$regionCount = count($regions);
if ($regionCount) {
$paintEvents = array();
$total = 0.0;
foreach ($regions as $name => &$region) {
$area = $region['width'] * $region['height'];
$updateCount = floatval(count($region['times']));
$incrementalImpact = floatval($area) / $updateCount;
// only count full screen paints for half their value
if ($area == $fullScreen) {
$incrementalImpact /= 2;
}
foreach ($region['times'] as $time) {
$total += $incrementalImpact;
$elapsed = (int) ($time - $startTime);
if (!array_key_exists($elapsed, $paintEvents)) {
$paintEvents[$elapsed] = $incrementalImpact;
} else {
$paintEvents[$elapsed] += $incrementalImpact;
}
//.........这里部分代码省略.........
示例9: GetTestResult
/**
* Gather all of the data for a given test and return it as an array
*
* @param mixed $id
*/
function GetTestResult($id)
{
global $url;
global $median_metric;
$testPath = './' . GetTestPath($id);
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$path = substr($testPath, 1);
$pageData = loadAllPageData($testPath);
$stats = array(0 => array(), 1 => array());
$pageStats = calculatePageStats($pageData, $stats[0], $stats[1]);
if (!strlen($url)) {
$url = $pageData[1][0]['URL'];
}
$testInfo = GetTestInfo($id);
if (is_file("{$testPath}/testinfo.ini")) {
$test = parse_ini_file("{$testPath}/testinfo.ini", true);
}
$fvOnly = false;
if (!count($stats[1])) {
$fvOnly = true;
}
$cacheLabels = array('firstView', 'repeatView');
// summary information
$ret = array('id' => $id, 'url' => $url, 'summary' => "{$protocol}://{$host}{$uri}/results.php?test={$id}");
$runs = max(array_keys($pageData));
if (isset($testInfo)) {
if (array_key_exists('url', $testInfo) && strlen($testInfo['url'])) {
$ret['testUrl'] = $testInfo['url'];
}
if (array_key_exists('location', $testInfo) && strlen($testInfo['location'])) {
$locstring = $testInfo['location'];
if (array_key_exists('browser', $testInfo) && strlen($testInfo['browser'])) {
$locstring .= ':' . $testInfo['browser'];
}
$ret['location'] = $locstring;
}
if (isset($test) && array_key_exists('test', $test) && is_array($test['test']) && array_key_exists('location', $test['test']) && strlen($test['test']['location'])) {
$ret['from'] = $test['test']['location'];
}
if (array_key_exists('connectivity', $testInfo) && strlen($testInfo['connectivity'])) {
$ret['connectivity'] = $testInfo['connectivity'];
}
if (array_key_exists('bwIn', $testInfo)) {
$ret['bwDown'] = $testInfo['bwIn'];
}
if (array_key_exists('bwOut', $testInfo)) {
$ret['bwUp'] = $testInfo['bwOut'];
}
if (array_key_exists('latency', $testInfo)) {
$ret['latency'] = $testInfo['latency'];
}
if (array_key_exists('plr', $testInfo)) {
$ret['plr'] = $testInfo['plr'];
}
if (array_key_exists('label', $testInfo) && strlen($testInfo['label'])) {
$ret['label'] = $testInfo['label'];
}
if (array_key_exists('completed', $testInfo)) {
$ret['completed'] = $testInfo['completed'];
}
if (array_key_exists('tester', $testInfo) && strlen($testInfo['tester'])) {
$ret['tester'] = $testInfo['tester'];
}
if (array_key_exists('testerDNS', $testInfo) && strlen($testInfo['testerDNS'])) {
$ret['testerDNS'] = $testInfo['testerDNS'];
}
if (array_key_exists('runs', $testInfo) && $testInfo['runs']) {
$runs = $testInfo['runs'];
}
if (array_key_exists('fvonly', $testInfo)) {
$fvOnly = $testInfo['fvonly'] ? true : false;
}
}
$cachedMax = 0;
if (!$fvOnly) {
$cachedMax = 1;
}
$ret['runs'] = $runs;
$ret['fvonly'] = $fvOnly;
$ret['successfulFVRuns'] = CountSuccessfulTests($pageData, 0);
if (!$fvOnly) {
$ret['successfulRVRuns'] = CountSuccessfulTests($pageData, 1);
}
// average
// check if removing average
$addAverage = 1;
if (isset($_GET['average'])) {
if ($_GET['average'] == 0) {
$addAverage = 0;
}
}
// add average
if ($addAverage == 1) {
//.........这里部分代码省略.........
示例10: GetJob
/**
* Get an actual task to complete
*
*/
function GetJob()
{
$is_done = false;
global $location;
global $key;
global $pc;
global $ec2;
global $tester;
global $recover;
global $is_json;
global $dnsServers;
$workDir = "./work/jobs/{$location}";
$locKey = GetLocationKey($location);
if (strpos($location, '..') == false && strpos($location, '\\') == false && strpos($location, '/') == false && (!strlen($locKey) || !strcmp($key, $locKey))) {
if ($lock = LockLocation($location)) {
$now = time();
$testers = GetTesters($location, true);
// make sure the tester isn't marked as offline (usually when shutting down EC2 instances)
$testerCount = isset($testers['testers']) ? count($testers['testers']) : 0;
$testerIndex = null;
$offline = false;
if ($testerCount) {
if (strlen($ec2)) {
foreach ($testers['testers'] as $index => $testerInfo) {
if (isset($testerInfo['ec2']) && $testerInfo['ec2'] == $ec2 && isset($testerInfo['offline']) && $testerInfo['offline']) {
$offline = true;
}
break;
}
}
foreach ($testers['testers'] as $index => $testerInfo) {
if ($testerInfo['id'] == $tester) {
$testerIndex = $index;
break;
}
}
}
if (!$offline) {
$fileName = GetJobFile($workDir, $priority, $pc, $testerIndex, $testerCount);
if (isset($fileName) && strlen($fileName)) {
$is_done = true;
$delete = true;
if ($is_json) {
header("Content-type: application/json");
} else {
header('Content-type: text/plain');
}
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// send the test info to the test agent
$testInfo = file_get_contents("{$workDir}/{$fileName}");
// extract the test ID from the job file
if (preg_match('/Test ID=([^\\r\\n]+)\\r/i', $testInfo, $matches)) {
$testId = trim($matches[1]);
}
if (isset($testId)) {
// figure out the path to the results
$testPath = './' . GetTestPath($testId);
// flag the test with the start time
$ini = file_get_contents("{$testPath}/testinfo.ini");
if (stripos($ini, 'startTime=') === false) {
$time = time();
$start = "[test]\r\nstartTime=" . gmdate("m/d/y G:i:s", $time);
$out = str_replace('[test]', $start, $ini);
file_put_contents("{$testPath}/testinfo.ini", $out);
}
$lock = LockTest($testId);
if ($lock) {
$testInfoJson = GetTestInfo($testId);
if ($testInfoJson) {
if (!array_key_exists('tester', $testInfoJson) || !strlen($testInfoJson['tester'])) {
$testInfoJson['tester'] = $tester;
}
if (isset($dnsServers) && strlen($dnsServers)) {
$testInfoJson['testerDNS'] = $dnsServers;
}
if (!array_key_exists('started', $testInfoJson) || !$testInfoJson['started']) {
$testInfoJson['started'] = $time;
logTestMsg($testId, "Starting test (initiated by tester {$tester})");
}
if (!array_key_exists('test_runs', $testInfoJson)) {
$testInfoJson['test_runs'] = array();
}
for ($run = 1; $run <= $testInfoJson['runs']; $run++) {
if (!array_key_exists($run, $testInfoJson['test_runs'])) {
$testInfoJson['test_runs'][$run] = array('done' => false);
}
}
$testInfoJson['id'] = $testId;
ProcessTestShard($testInfoJson, $testInfo, $delete);
SaveTestInfo($testId, $testInfoJson);
}
UnlockTest($lock);
}
file_put_contents("./tmp/last-test-{$location}-{$tester}.test", $testId);
}
//.........这里部分代码省略.........
示例11: LoadTestData
/**
* Load information about each of the tests (particularly about the video frames)
*
*/
function LoadTestData()
{
global $tests;
global $admin;
global $supportsAuth;
global $user;
global $supports60fps;
$count = 0;
foreach ($tests as &$test) {
$count++;
$testInfo = null;
$testPath =& $test['path'];
$pageData =& $test['pageData'];
$url = trim($pageData[1][0]['URL']);
if (strlen($url)) {
$test['url'] = $url;
}
if (array_key_exists('label', $test) && strlen($test['label'])) {
$test['name'] = $test['label'];
} else {
$testInfo = GetTestInfo($test['id']);
if ($testInfo && array_key_exists('label', $testInfo)) {
$test['name'] = trim($testInfo['label']);
}
}
// See if we have an overridden test label in the sqlite DB
$new_label = getLabel($test['id'], $user);
if (!empty($new_label)) {
$test['name'] = $new_label;
}
if (!strlen($test['name'])) {
$test['name'] = $test['url'];
$test['name'] = str_replace('http://', '', $test['name']);
$test['name'] = str_replace('https://', '', $test['name']);
}
$test['index'] = $count;
$videoPath = "./{$testPath}/video_{$test['run']}";
if ($test['cached']) {
$videoPath .= '_cached';
}
$test['video'] = array();
if (is_dir($videoPath)) {
$test['video']['start'] = 20000;
$test['video']['end'] = 0;
$test['video']['frames'] = array();
$test['video']['frame_progress'] = array();
$end = null;
if (is_numeric($test['end']) && $test['end'] > 0) {
$end = $test['end'] / 1000.0;
}
$startOffset = array_key_exists('testStartOffset', $pageData[$test['run']][$test['cached']]) ? intval(round($pageData[$test['run']][$test['cached']]['testStartOffset'])) : 0;
if (isset($testInfo) && is_array($testInfo) && array_key_exists('appurify_tests', $testInfo)) {
$startOffset = 0;
}
$test['video']['progress'] = GetVisualProgress("./{$testPath}", $test['run'], $test['cached'], null, $end, $startOffset);
if (array_key_exists('frames', $test['video']['progress'])) {
foreach ($test['video']['progress']['frames'] as $ms => $frame) {
if (!$supports60fps && is_array($frame) && array_key_exists('file', $frame) && substr($frame['file'], 0, 3) == 'ms_') {
$supports60fps = true;
}
if (!$test['end'] || $test['end'] == -1 || $ms <= $test['end']) {
$path = "{$videoPath}/{$frame['file']}";
if ($ms < $test['video']['start']) {
$test['video']['start'] = $ms;
}
if ($ms > $test['video']['end']) {
$test['video']['end'] = $ms;
}
// figure out the dimensions of the source image
if (!array_key_exists('width', $test['video']) || !$test['video']['width'] || !array_key_exists('height', $test['video']) || !$test['video']['height']) {
$size = getimagesize($path);
$test['video']['width'] = $size[0];
$test['video']['height'] = $size[1];
}
$test['video']['frames'][$ms] = $frame['file'];
$test['video']['frame_progress'][$ms] = $frame['progress'];
}
}
if ($test['end'] == -1) {
$test['end'] = $test['video']['end'];
} elseif ($test['end']) {
$test['video']['end'] = $test['end'];
}
}
if (!isset($test['video']['frames'][0])) {
$test['video']['frames'][0] = $test['video']['frames'][$test['video']['start']]['file'];
$test['video']['frame_progress'][0] = $test['video']['frames'][$test['video']['start']]['progress'];
}
}
}
}
示例12: GetVisualProgress
/**
* Calculate the progress for all of the images in a given directory
*/
function GetVisualProgress($testPath, $run, $cached, $options = null, $end = null, $startOffset = null)
{
$frames = null;
if (substr($testPath, 0, 1) !== '.') {
$testPath = './' . $testPath;
}
$testInfo = GetTestInfo($testPath);
$completed = IsTestRunComplete($run, $testInfo);
$video_directory = "{$testPath}/video_{$run}";
if ($cached) {
$video_directory .= '_cached';
}
$cache_file = "{$testPath}/{$run}.{$cached}.visual.dat";
if (!isset($startOffset)) {
$startOffset = 0;
}
$dirty = false;
$current_version = VIDEO_CODE_VERSION;
if (isset($end)) {
if (is_numeric($end)) {
$end = (int) ($end * 1000);
} else {
unset($end);
}
}
if (!isset($end) && !isset($options) && gz_is_file($cache_file)) {
$frames = json_decode(gz_file_get_contents($cache_file), true);
if (!array_key_exists('frames', $frames) || !array_key_exists('version', $frames)) {
unset($frames);
} elseif (array_key_exists('version', $frames) && $frames['version'] !== $current_version) {
unset($frames);
}
}
if ((!isset($frames) || !count($frames)) && is_dir($video_directory)) {
$frames = array('version' => $current_version);
$frames['frames'] = array();
$dirty = true;
$base_path = substr($video_directory, 1);
$files = scandir($video_directory);
$last_file = null;
$first_file = null;
$previous_file = null;
foreach ($files as $file) {
if (strpos($file, 'frame_') !== false && strpos($file, '.hist') === false) {
$parts = explode('_', $file);
if (count($parts) >= 2) {
$time = (int) $parts[1] * 100 - $startOffset;
if ($time >= 0 && (!isset($end) || $time <= $end)) {
if (isset($previous_file) && !array_key_exists(0, $frames['frames']) && $time > 0) {
$frames['frames'][0] = array('path' => "{$base_path}/{$previous_file}", 'file' => $previous_file);
$first_file = $previous_file;
} elseif (!isset($first_file)) {
$first_file = $file;
}
$last_file = $file;
$frames['frames'][$time] = array('path' => "{$base_path}/{$file}", 'file' => $file);
}
$previous_file = $file;
}
} elseif (strpos($file, 'ms_') !== false && strpos($file, '.hist') === false) {
$parts = explode('_', $file);
if (count($parts) >= 2) {
$time = intval($parts[1]) - $startOffset;
if ($time >= 0 && (!isset($end) || $time <= $end)) {
if (isset($previous_file) && !array_key_exists(0, $frames['frames']) && $time > 0) {
$frames['frames'][0] = array('path' => "{$base_path}/{$previous_file}", 'file' => $previous_file);
$first_file = $previous_file;
} elseif (!isset($first_file)) {
$first_file = $file;
}
$last_file = $file;
$frames['frames'][$time] = array('path' => "{$base_path}/{$file}", 'file' => $file);
}
$previous_file = $file;
}
}
}
if (count($frames['frames']) == 1) {
foreach ($frames['frames'] as $time => &$frame) {
$frame['progress'] = 100;
$frames['complete'] = $time;
}
} elseif (isset($first_file) && strlen($first_file) && isset($last_file) && strlen($last_file) && count($frames['frames'])) {
$start_histogram = GetImageHistogram("{$video_directory}/{$first_file}", $options);
$final_histogram = GetImageHistogram("{$video_directory}/{$last_file}", $options);
foreach ($frames['frames'] as $time => &$frame) {
$histogram = GetImageHistogram("{$video_directory}/{$frame['file']}", $options);
$frame['progress'] = CalculateFrameProgress($histogram, $start_histogram, $final_histogram, 5);
if ($frame['progress'] == 100 && !array_key_exists('complete', $frames)) {
$frames['complete'] = $time;
}
}
}
}
if (isset($frames) && !array_key_exists('SpeedIndex', $frames)) {
$dirty = true;
$frames['SpeedIndex'] = CalculateSpeedIndex($frames);
//.........这里部分代码省略.........
示例13: DateTime
<?php
require_once './common.inc';
if (array_key_exists('original', $_REQUEST) && array_key_exists('optimized', $_REQUEST)) {
$original = $_REQUEST['original'];
$optimized = $_REQUEST['optimized'];
if (ValidateTestId($original) && ValidateTestId($optimized)) {
// Write out the fake testinfo (use the original test as a template)
$today = new DateTime("now", new DateTimeZone('UTC'));
$test = GetTestInfo($original);
if (isset($test) && is_array($test) && count($test)) {
$test['id'] = $today->format('ymd') . '_PSS_' . md5(uniqid(rand(), true));
$test['path'] = './' . GetTestPath($test['id']);
$test['batch'] = 1;
$test['label'] = 'PageSpeed Service Comparison';
if (array_key_exists('url', $test) && strlen($test['url'])) {
$test['label'] .= ' for ' . $test['url'];
}
$test['view'] = 'pss';
if (!is_dir($test['path'])) {
mkdir($test['path'], 0777, true);
}
SaveTestInfo($test['id'], $test);
// write out the bulk test data
$tests = array();
$tests['variations'] = array();
$tests['urls'] = array();
$tests['urls'][] = array('u' => $test['url'], 'l' => 'Original', 'id' => $original);
$tests['urls'][] = array('u' => $test['url'], 'l' => 'Optimized', 'id' => $optimized);
gz_file_put_contents("./{$test['path']}/bulk.json", json_encode($tests));
// redirect
示例14: tbnDrawChecklist
/**
* Draw the checklist image
*
* @param resource $img
*/
function tbnDrawChecklist(&$img)
{
global $id;
global $testPath;
global $run;
global $cached;
global $url;
require_once 'optimizationChecklist.inc';
$is_secure = false;
$has_locations = false;
$testInfo = GetTestInfo($testPath);
$requests = getRequests($id, $testPath, $run, $cached, $is_secure, $has_locations, false);
$page_data = loadPageRunData($testPath, $run, $cached, null, $testInfo);
$img = drawChecklist($url, $requests, $page_data);
if (!$requests || !$page_data) {
$failed = true;
}
}
示例15: LoadTestData
/**
* Load information about each of the tests (particularly about the video frames)
*
*/
function LoadTestData()
{
global $tests;
global $admin;
global $supportsAuth;
global $user;
global $supports60fps;
$count = 0;
foreach ($tests as &$test) {
$count++;
$testInfo = null;
$testPath =& $test['path'];
if (!empty($test['stepResult'])) {
$url = trim($test['stepResult']->getUrl());
if (strlen($url)) {
$test['url'] = $url;
}
}
if (array_key_exists('label', $test) && strlen($test['label'])) {
$test['name'] = $test['label'];
} else {
$testInfo = GetTestInfo($test['id']);
if ($testInfo && array_key_exists('label', $testInfo)) {
$test['name'] = trim($testInfo['label']);
}
}
// See if we have an overridden test label in the sqlite DB
$new_label = getLabel($test['id'], $user);
if (!empty($new_label)) {
$test['name'] = $new_label;
}
if (!strlen($test['name'])) {
$test['name'] = $test['url'];
$test['name'] = str_replace('http://', '', $test['name']);
$test['name'] = str_replace('https://', '', $test['name']);
}
$test['index'] = $count;
$localPaths = new TestPaths("./{$testPath}", $test["run"], $test["cached"], $test["step"]);
$videoPath = $localPaths->videoDir();
$test['video'] = array();
if (is_dir($videoPath)) {
$test['video']['start'] = 20000;
$test['video']['end'] = 0;
$test['video']['frames'] = array();
$test['video']['frame_progress'] = array();
$end = null;
if (is_numeric($test['end']) && $test['end'] > 0) {
$end = $test['end'] / 1000.0;
}
if (!empty($test["stepResult"])) {
$test['video']['progress'] = $test["stepResult"]->getVisualProgress($end);
}
if (!empty($test['video']['progress']['frames'])) {
foreach ($test['video']['progress']['frames'] as $ms => $frame) {
if (!$supports60fps && is_array($frame) && array_key_exists('file', $frame) && substr($frame['file'], 0, 3) == 'ms_') {
$supports60fps = true;
}
if ((!$test['end'] || $test['end'] == -1 || $ms <= $test['end']) && (!isset($test['initial']) || !count($test['video']['frames']) || $ms >= $test['initial'])) {
$path = "{$videoPath}/{$frame['file']}";
if ($ms < $test['video']['start']) {
$test['video']['start'] = $ms;
}
if ($ms > $test['video']['end']) {
$test['video']['end'] = $ms;
}
// figure out the dimensions of the source image
if (!array_key_exists('width', $test['video']) || !$test['video']['width'] || !array_key_exists('height', $test['video']) || !$test['video']['height']) {
$size = getimagesize($path);
$test['video']['width'] = $size[0];
$test['video']['height'] = $size[1];
}
$test['video']['frames'][$ms] = $frame['file'];
$test['video']['frame_progress'][$ms] = $frame['progress'];
}
}
if ($test['end'] == -1) {
$test['end'] = $test['video']['end'];
} elseif ($test['end']) {
$test['video']['end'] = $test['end'];
}
}
if (!isset($test['video']['frames'][0])) {
$test['video']['frames'][0] = $test['video']['frames'][$test['video']['start']]['file'];
$test['video']['frame_progress'][0] = $test['video']['frames'][$test['video']['start']]['progress'];
}
}
}
}