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"; } } } }
/** * 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); }
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); }
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); } } }
/** * 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; }
<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">
/** * 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); $final_histogram = GetImageHistogram("{$video_directory}/{$last_file}", $options, $histograms); foreach ($frames['frames'] as $time => &$frame) { $histogram = GetImageHistogram("{$video_directory}/{$frame['file']}", $options, $histograms); $frame['progress'] = CalculateFrameProgress($histogram, $start_histogram, $final_histogram, 5); if ($frame['progress'] == 100 && !array_key_exists('complete', $frames)) { $frames['complete'] = $time; } } } } elseif (gz_is_file("{$testPath}/{$run}.{$cached}.histograms.json")) { $raw = json_decode(gz_file_get_contents("{$testPath}/{$run}.{$cached}.histograms.json"), true); $histograms = array(); foreach ($raw as $h) { if (isset($h['time']) && isset($h['histogram'])) { $histograms[$h['time']] = $h['histogram']; } } ksort($histograms, SORT_NUMERIC); $final_histogram = end($histograms); $start_histogram = reset($histograms); foreach ($histograms as $time => $histogram) { $frames['frames'][$time] = array(); $progress = CalculateFrameProgress($histogram, $start_histogram, $final_histogram, 5); $frames['frames'][$time]['progress'] = $progress; if ($progress == 100 && !isset($frames['complete'])) { $frames['complete'] = $time; } } } } if (isset($frames) && !array_key_exists('SpeedIndex', $frames)) { $dirty = true; $frames['SpeedIndex'] = CalculateSpeedIndex($frames); } if (isset($frames)) { $frames['visualComplete'] = 0; foreach ($frames['frames'] as $time => &$frame) { if ($frame['progress'] > 0 && !array_key_exists('startRender', $frames)) { $frames['startRender'] = $time; } if (!$frames['visualComplete'] && $frame['progress'] == 100) { $frames['visualComplete'] = $time; } // fix up the frame paths in case we have a cached version referencing a relay path if (isset($frame['path'])) { $frame['path'] = $base_path . '/' . basename($frame['path']); } } } if ($completed && !isset($end) && !isset($options) && $dirty && isset($frames) && count($frames)) { gz_file_put_contents($cache_file, json_encode($frames)); } return $frames; }
/** * 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; } } } if (count($paintEvents)) { ksort($paintEvents, SORT_NUMERIC); $current = 0.0; $lastTime = 0.0; $lastProgress = 0.0; $progress['SpeedIndex'] = 0.0; $progress['VisuallyComplete'] = 0; $progress['StartRender'] = 0; $progress['VisualProgress'] = array(); foreach ($paintEvents as $time => $increment) { $current += $increment; $currentProgress = floatval(floatval($current) / floatval($total)); $currentProgress = floatval(round($currentProgress * 100) / 100.0); $elapsed = $time - $lastTime; $siIncrement = floatval($elapsed) * (1.0 - $lastProgress); $progress['SpeedIndex'] += $siIncrement; $progress['VisualProgress'][$time] = $currentProgress; $progress['VisuallyComplete'] = $time; if (!$progress['StartRender']) { $progress['StartRender'] = $time; } $lastProgress = $currentProgress; $lastTime = $time; if ($currentProgress >= 1.0) { break; } } } } if ($completed && isset($progress) && is_array($progress)) { SavedCachedDevToolsProgress($testPath, $run, $cached, $progress); } } } return $progress; }
/** * 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) { $ret['average'] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $ret['average'][$label] = $stats[$cached]; } } // standard deviation // check if removing standard deviation $addStandard = 1; if (isset($_GET['standard'])) { if ($_GET['standard'] == 0) { $addStandard = 0; } } // add standard deviation if ($addStandard == 1) { $ret['standardDeviation'] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $ret['standardDeviation'][$label] = array(); foreach ($stats[$cached] as $key => $val) { $ret['standardDeviation'][$label][$key] = PageDataStandardDeviation($pageData, $key, $cached); } } } // median // check if removing median $addMedian = 1; if (isset($_GET['median'])) { if ($_GET['median'] == 0) { $addMedian = 0; } } // add median if ($addMedian == 1) { $ret['median'] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $medianRun = GetMedianRun($pageData, $cached, $median_metric); if (array_key_exists($medianRun, $pageData)) { $ret['median'][$label] = GetSingleRunData($id, $testPath, $medianRun, $cached, $pageData, $testInfo); } } } // runs // check if removing runs $addRuns = 1; if (isset($_GET['runs'])) { if ($_GET['runs'] == 0) { $addRuns = 0; } } // add runs if ($addRuns == 1) { $ret['runs'] = array(); for ($run = 1; $run <= $runs; $run++) { $ret['runs'][$run] = array(); for ($cached = 0; $cached <= $cachedMax; $cached++) { $label = $cacheLabels[$cached]; $ret['runs'][$run][$label] = GetSingleRunData($id, $testPath, $run, $cached, $pageData, $testInfo); } } } ArchiveApi($id); return $ret; }
/** * 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); } if ($delete) { unlink("{$workDir}/{$fileName}"); } else { AddJobFileHead($workDir, $fileName, $priority, true); } if ($is_json) { $testJson = array(); $script = ''; $isScript = false; $lines = explode("\r\n", $testInfo); foreach ($lines as $line) { if (strlen(trim($line))) { if ($isScript) { if (strlen($script)) { $script .= "\r\n"; } $script .= $line; } elseif (!strcasecmp($line, '[Script]')) { $isScript = true; } else { $pos = strpos($line, '='); if ($pos !== false) { $key = trim(substr($line, 0, $pos)); $value = trim(substr($line, $pos + 1)); if (strlen($key) && strlen($value)) { if ($key == 'customMetric') { $pos = strpos($value, ':'); if ($pos !== false) { $metric = trim(substr($value, 0, $pos)); $code = base64_decode(substr($value, $pos + 1)); if ($code !== false && strlen($metric) && strlen($code)) { if (!isset($testJson['customMetrics'])) { $testJson['customMetrics'] = array(); } $testJson['customMetrics'][$metric] = $code; } } } elseif (is_numeric($value)) { $testJson[$key] = (int) $value; } else { $testJson[$key] = $value; } } } } } } if (strlen($script)) { $testJson['script'] = $script; } echo json_encode($testJson); } else { echo $testInfo; } $ok = true; } // zero out the tracked page loads in case some got lost if (!$is_done && is_file("./tmp/{$location}.tests")) { $tests = json_decode(file_get_contents("./tmp/{$location}.tests"), true); if ($tests) { $tests['tests'] = 0; file_put_contents("./tmp/{$location}.tests", json_encode($tests)); } } } UnlockLocation($lock); // keep track of the last time this location reported in $testerInfo = array(); $testerInfo['ip'] = $_SERVER['REMOTE_ADDR']; $testerInfo['pc'] = $pc; $testerInfo['ec2'] = $ec2; $testerInfo['ver'] = array_key_exists('version', $_GET) ? $_GET['version'] : $_GET['ver']; $testerInfo['freedisk'] = @$_GET['freedisk']; $testerInfo['ie'] = @$_GET['ie']; $testerInfo['dns'] = $dnsServers; $testerInfo['video'] = @$_GET['video']; $testerInfo['GPU'] = @$_GET['GPU']; $testerInfo['test'] = ''; if (isset($testId)) { $testerInfo['test'] = $testId; } UpdateTester($location, $tester, $testerInfo); } } return $is_done; }
/** * 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']; } } } }
/** * 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); } if (isset($frames)) { $frames['visualComplete'] = 0; foreach ($frames['frames'] as $time => &$frame) { if ($frame['progress'] > 0 && !array_key_exists('startRender', $frames)) { $frames['startRender'] = $time; } if ($frame['progress'] == 100) { $frames['visualComplete'] = $time; break; } } } $devTools = GetDevToolsProgress($testPath, $run, $cached); if (isset($devTools)) { if (!isset($frames)) { $frames = array(); } $frames['DevTools'] = $devTools; } if ($completed && !isset($end) && !isset($options) && $dirty && isset($frames) && count($frames)) { gz_file_put_contents($cache_file, json_encode($frames)); } return $frames; }
<?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
/** * 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; } }
/** * 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']; } } } }
$test['end'] = (int) ((double) $test['end'] * 1000.0); } } if ($test['end'] == -1) { $test['end'] = 0; } elseif (!$test['end']) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['fullyLoaded']; } $test['videoPath'] = "./{$test['path']}/video_{$test['run']}"; if ($test['cached']) { $test['videoPath'] .= '_cached'; } if ($test['syncStartRender'] || $test['syncDocTime'] || $test['syncFullyLoaded']) { $videoIdExtra .= ".{$test['syncStartRender']}.{$test['syncDocTime']}.{$test['syncFullyLoaded']}"; } $testInfo = GetTestInfo($test['id']); if ($testInfo) { if (!strlen($test['label'])) { $test['label'] = trim($testInfo['label']); } if (array_key_exists('locationText', $testInfo)) { $test['location'] = $testInfo['locationText']; } } if (!strlen($test['label'])) { $test['label'] = trim($test['pageData'][1][0]['URL']); } // See if the label has been edited $new_label = getLabel($test['id'], $user); if (!empty($new_label)) { $labels[] = $new_label;
function CollectTestResult($test, &$data) { global $benchmark; $id = $test['id']; $count = 0; echo "Reprocessing Test {$id}..."; logMsg("Reprocessing Test {$id}", "./log/reprocess-{$benchmark}.log", true); RestoreTest($id); ReprocessVideo($id); $testPath = './' . GetTestPath($id); $page_data = loadAllPageData($testPath); if (count($page_data)) { foreach ($page_data as $run => &$page_run) { foreach ($page_run as $cached => &$test_data) { $data_row = $test_data; unset($data_row['URL']); // figure out the per-type request info (todo: measure how expensive this is and see if we have a better way) $breakdown = getBreakdown($test['id'], $testPath, $run, $cached, $requests); foreach ($breakdown as $mime => &$values) { $data_row["{$mime}_requests"] = $values['requests']; $data_row["{$mime}_bytes"] = $values['bytes']; } // capture the page speed score if ($cached) { $data_row['page_speed'] = GetPageSpeedScore("{$testPath}/{$run}_Cached_pagespeed.txt"); } else { $data_row['page_speed'] = GetPageSpeedScore("{$testPath}/{$run}_pagespeed.txt"); } $data_row['url'] = $test['url']; $data_row['label'] = $test['label']; $data_row['location'] = $test['location']; $data_row['config'] = $test['config']; $data_row['cached'] = $cached; $data_row['run'] = $run; $data_row['id'] = $test['id']; $data[] = $data_row; $count++; } } } else { $data_row = array(); $data_row['url'] = $test['url']; $data_row['label'] = $test['label']; $data_row['location'] = $test['location']; $data_row['config'] = $test['config']; $data_row['id'] = $test['id']; $data[] = $data_row; } // If the test was already archived, re-archive it. $testInfo = GetTestInfo($id); if (array_key_exists('archived', $testInfo) && $testInfo['archived']) { $lock = LockTest($id); if (isset($lock)) { $testInfo = GetTestInfo($id); $testInfo['archived'] = false; SaveTestInfo($id, $testInfo); UnlockTest($lock); } ArchiveTest($id); } echo "{$count} results\n"; }
} } else { $files = glob("{$testPath}/*{$fileType}.*"); if ($files && is_array($files) && count($files)) { $hasCSV = true; } else { $hasCSV = false; } // loop through all of the results files (one per run) - both cached and uncached if ($hasCSV) { echo "{$header},\"Run\",\"Cached\""; if (!$is_requests) { echo ',"Speed Index"'; } echo "\r\n"; $testInfo = GetTestInfo($testPath); for ($i = 1; $i <= $test['test']['runs']; $i++) { $additional = array($i, 0); if (!$is_requests) { $additional[] = SpeedIndex($testPath, $i, 0, $testInfo); } csvFile("{$testPath}/{$i}_{$fileType}", null, $column_count, $additional); $additional = array($i, 1); if (!$is_requests) { $additional[] = SpeedIndex($testPath, $i, 1, $testInfo); } csvFile("{$testPath}/{$i}_Cached_{$fileType}", null, $column_count, $additional); } } else { csvPageData($id, $testPath, $test['test']['runs']); }
/** * 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; global $screenwidth; global $screenheight; global $winver; global $isWinServer; global $isWin64; $workDir = "./work/jobs/{$location}"; $locInfo = GetLocationInfo($location); $locKey = ''; if (isset($locInfo) && is_array($locInfo) && isset($locInfo['key'])) { $locKey = $locInfo['key']; } $incremental = true; if (GetSetting('no_incremental') || isset($locInfo['incremental']) && !$locInfo['incremental']) { $incremental = false; } if (strpos($location, '..') == false && strpos($location, '\\') == false && strpos($location, '/') == false && (!strlen($locKey) || !strcmp($key, $locKey))) { $now = time(); // If it is an EC2 auto-scaling location, make sure the agent isn't marked as offline $offline = false; if (isset($locInfo['ami'])) { $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; 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) { $testInfo = GetTestJob($location, $fileName, $workDir, $priority, $testInfo, $pc, $testerIndex, $testerCount); if (isset($testInfo)) { $original_test_info = $testInfo; $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 $newline = strpos($testInfo, "\n", 2); if ($newline) { $newline++; $after = substr($testInfo, $newline); $testInfo = substr($testInfo, 0, $newline); $software = GetSetting('software'); if ($software) { $testInfo .= "software={$software}\r\n"; } if (GetSetting('enable_agent_processing')) { $testInfo .= "processResults=1\r\n"; } if (!$incremental) { $testInfo .= "incremental=0\r\n"; } $testInfo .= $after; } // 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); } } $dotPos = stripos($testId, "."); $testInfoJson['id'] = $dotPos === false ? $testId : substr($testId, $dotPos + 1); ProcessTestShard($testInfoJson, $testInfo, $delete, $priority); SaveTestInfo($testId, $testInfoJson); } UnlockTest($lock); } } if ($delete) { if (isset($fileName) && is_file("{$workDir}/{$fileName}")) { unlink("{$workDir}/{$fileName}"); } } else { AddTestJobHead($location, $original_test_info, $workDir, $fileName, $priority, true); } if ($is_json) { $testJson = array(); $script = ''; $isScript = false; $lines = explode("\r\n", $testInfo); foreach ($lines as $line) { if (strlen(trim($line))) { if ($isScript) { if (strlen($script)) { $script .= "\r\n"; } $script .= $line; } elseif (!strcasecmp($line, '[Script]')) { $isScript = true; } else { $pos = strpos($line, '='); if ($pos !== false) { $key = trim(substr($line, 0, $pos)); $value = trim(substr($line, $pos + 1)); if (strlen($key) && strlen($value)) { if ($key == 'customMetric') { $pos = strpos($value, ':'); if ($pos !== false) { $metric = trim(substr($value, 0, $pos)); $code = base64_decode(substr($value, $pos + 1)); if ($code !== false && strlen($metric) && strlen($code)) { if (!isset($testJson['customMetrics'])) { $testJson['customMetrics'] = array(); } $testJson['customMetrics'][$metric] = $code; } } } elseif (is_numeric($value)) { $testJson[$key] = (int) $value; } else { $testJson[$key] = $value; } } } } } } if (strlen($script)) { $testJson['script'] = $script; } // See if we need to include apk information if (isset($_REQUEST['apk']) && is_file(__DIR__ . '/update/apk.dat')) { $apk_info = json_decode(file_get_contents(__DIR__ . '/update/apk.dat'), true); if (isset($apk_info) && is_array($apk_info) && isset($apk_info['packages']) && is_array($apk_info['packages'])) { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http'; $update_path = dirname($_SERVER['PHP_SELF']) . '/update/'; $base_uri = "{$protocol}://{$_SERVER['HTTP_HOST']}{$update_path}"; foreach ($apk_info['packages'] as $package => $info) { $apk_info['packages'][$package]['apk_url'] = "{$base_uri}{$apk_info['packages'][$package]['file_name']}?md5={$apk_info['packages'][$package]['md5']}"; } $testJson['apk_info'] = $apk_info; } } echo json_encode($testJson); } else { echo $testInfo; } $ok = true; } // keep track of the last time this location reported in $testerInfo = array(); $testerInfo['ip'] = $_SERVER['REMOTE_ADDR']; $testerInfo['pc'] = $pc; $testerInfo['ec2'] = $ec2; $testerInfo['ver'] = array_key_exists('version', $_GET) ? $_GET['version'] : $_GET['ver']; $testerInfo['freedisk'] = @$_GET['freedisk']; $testerInfo['ie'] = @$_GET['ie']; $testerInfo['dns'] = $dnsServers; $testerInfo['video'] = @$_GET['video']; $testerInfo['GPU'] = @$_GET['GPU']; $testerInfo['screenwidth'] = $screenwidth; $testerInfo['screenheight'] = $screenheight; $testerInfo['winver'] = $winver; $testerInfo['isWinServer'] = $isWinServer; $testerInfo['isWin64'] = $isWin64; $testerInfo['test'] = ''; if (isset($testId)) { $testerInfo['test'] = $testId; } UpdateTester($location, $tester, $testerInfo); } } return $is_done; }
UnlockTest($testLock); } if ($testInfo && array_key_exists('location', $testInfo)) { $location = $testInfo['location']; $locKey = GetLocationKey($location); if (!strlen($locKey) || !strcmp($key, $locKey) || !strcmp($_SERVER['REMOTE_ADDR'], "127.0.0.1")) { $testErrorStr = ''; if (array_key_exists('testerror', $_REQUEST) && strlen($_REQUEST['testerror'])) { $testErrorStr = ', Test Error: "' . $_REQUEST['testerror'] . '"'; } if (array_key_exists('error', $_REQUEST) && strlen($_REQUEST['error'])) { $errorStr = ', Test Run Error: "' . $_REQUEST['error'] . '"'; } logTestMsg($id, "Test Run Complete. Run: {$runNumber}, Cached: {$cacheWarmed}, Done: {$done}, Tester: {$tester}{$testErrorStr}{$errorStr}"); $testLock = LockTest($id); $testInfo = GetTestInfo($id); // update the location time if (strlen($location)) { if (!is_dir('./tmp')) { mkdir('./tmp', 0777, true); } touch("./tmp/{$location}.tm"); } // Figure out the path to the results. $ini = parse_ini_file("{$testPath}/testinfo.ini"); $time = time(); $testInfo['last_updated'] = $time; // Allow for the test agents to indicate that they are including a // trace-based timeline (mostly for the mobile agents that always include it) if (isset($_REQUEST['timeline']) && $_REQUEST['timeline']) { $testInfo['timeline'] = 1;
/** * Parse the list of tests and identify the screen shots to compare * */ function ParseTests() { $tests = array(); global $median_metric; if (isset($_REQUEST['tests'])) { $groups = explode(',', $_REQUEST['tests']); foreach ($groups as $group) { $parts = explode('-', $group); if (count($parts) >= 1 && ValidateTestId($parts[0])) { $test = array(); $test['id'] = $parts[0]; $test['cached'] = 0; for ($i = 1; $i < count($parts); $i++) { $p = explode(':', $parts[$i]); if (count($p) >= 2) { if ($p[0] == 'r') { $test['run'] = (int) $p[1]; } if ($p[0] == 'l') { $test['label'] = $p[1]; } if ($p[0] == 'c') { $test['cached'] = (int) $p[1]; } } } RestoreTest($test['id']); $test['path'] = GetTestPath($test['id']); if (!isset($test['run'])) { $pageData = loadAllPageData($test['path']); $test['run'] = GetMedianRun($pageData, $test['cached'], $median_metric); } if (!isset($test['label'])) { $label = getLabel($test['id'], $user); if (!empty($label)) { $test['label'] = $new_label; } else { $info = GetTestInfo($test['id']); if ($info && isset($info['label']) && strlen($info['label'])) { $test['label'] = trim($info['label']); } } } if (!isset($test['label'])) { $test['label'] = $test['id']; } $cachedText = ''; if ($test['cached']) { $cachedText = '_Cached'; } $fileBase = "{$test['path']}/{$test['run']}{$cachedText}_screen"; if (is_file("{$fileBase}.png")) { $test['image'] = "{$fileBase}.png"; } elseif (is_file("{$fileBase}.jpg")) { $test['image'] = "{$fileBase}.jpg"; } if (isset($test['image'])) { $size = getimagesize($test['image']); if ($size && count($size) >= 2 && $size[0] > 0 && $size[1] > 0) { $test['width'] = $size[0]; $test['height'] = $size[1]; $tests[] = $test; } } } } } if (!count($tests)) { unset($tests); } return $tests; }
unset($locations[$name]); } } } } BuildLocations($locations); // see if we are running a relay test if (@strlen($req_rkey)) { RelayTest(); } else { // see if we're re-running an existing test if (isset($test)) { unset($test); } if (array_key_exists('resubmit', $_POST)) { $test = GetTestInfo(trim($_POST['resubmit'])); if ($test) { unset($test['completed']); unset($test['started']); unset($test['tester']); unset($test['batch']); } else { unset($test); } } // pull in the test parameters if (!isset($test)) { $test = array(); $test['url'] = trim($req_url); $test['domElement'] = trim($req_domelement); $test['login'] = trim($req_login);
/** * Generate a HAR file for the given test * * @param mixed $testPath */ function GenerateHAR($id, $testPath, $options) { global $median_metric; $json = '{}'; if (isset($testPath)) { $pageData = null; if (isset($options["run"]) && $options["run"]) { if (!strcasecmp($options["run"], 'median')) { $raw = loadAllPageData($testPath); $run = GetMedianRun($raw, $options['cached'], $median_metric); unset($raw); } else { $run = intval($options["run"]); } if (!$run) { $run = 1; } $pageData[$run] = array(); $testInfo = GetTestInfo($testPath); if (isset($options['cached'])) { $pageData[$run][$options['cached']] = loadPageRunData($testPath, $run, $options['cached'], null, $testInfo); if (!isset($pageData[$run][$options['cached']])) { unset($pageData); } } else { $pageData[$run][0] = loadPageRunData($testPath, $run, 0, null, $testInfo); if (!isset($pageData[$run][0])) { unset($pageData); } $pageData[$run][1] = loadPageRunData($testPath, $run, 1, null, $testInfo); } } if (!isset($pageData)) { $pageData = loadAllPageData($testPath); } // build up the array $harData = BuildHAR($pageData, $id, $testPath, $options); $json_encode_good = version_compare(phpversion(), '5.4.0') >= 0 ? true : false; $pretty_print = false; if (isset($options['pretty']) && $options['pretty']) { $pretty_print = true; } if (isset($options['php']) && $options['php']) { if ($pretty_print && $json_encode_good) { $json = json_encode($harData, JSON_PRETTY_PRINT); } else { $json = json_encode($harData); } } elseif ($json_encode_good) { if ($pretty_print) { $json = json_encode($harData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); } else { $json = json_encode($harData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } } else { $jsonLib = new Services_JSON(); $json = $jsonLib->encode($harData); } if ($json === false) { $jsonLib = new Services_JSON(); $json = $jsonLib->encode($harData); } } return $json; }