/** * Remove all video directories except for the median run * * @param mixed $dir */ function PruneDir($dir) { global $count; global $pruned; $pruned++; echo "\r{$count} ({$pruned}): Pruning {$dir} "; $pageData = loadAllPageData($dir); $fv = GetMedianRun($pageData, 0); if ($fv) { $keep = array(); $keep[0] = "video_{$fv}"; $rv = GetMedianRun($pageData, 1); if ($rv) { $keep[1] = "video_{$rv}_cached"; } else { $keep[1] = ''; } $f = scandir($dir); foreach ($f as $file) { if (!strncmp($file, 'video_', 6) && is_dir("{$dir}/{$file}")) { $del = true; if (!strcmp($file, $keep[0]) || !strcmp($file, $keep[1])) { $del = false; } if ($del) { RemoveDirectory("{$dir}/{$file}"); } } } } unset($pageData); }
function StatsdPostResult(&$test, $testPath) { require_once 'page_data.inc'; $runs = $test['runs']; if (array_key_exists('discard', $test) && $test['discard'] > 0 && $test['discard'] <= $runs) { $runs -= $test['discard']; } if ($runs) { $pageData = loadAllPageData($testPath); $medians = array(GetMedianRun($pageData, 0), GetMedianRun($pageData, 1)); if (isset($pageData) && is_array($pageData)) { foreach ($pageData as $run => &$pageRun) { foreach ($pageRun as $cached => &$testData) { if (GetSetting('statsdPattern') && !preg_match('/' . GetSetting('statsdPattern') . '/', $test['label'])) { continue; } if (GetSetting('statsdMedianOnly') && !($medians[$cached] == $run)) { continue; } $graphData = array(); foreach ($testData as $metric => $value) { if (is_float($value)) { $value = intval($value); } if (is_int($value) && $metric != 'result') { $graphData[$metric] = $value; } } StatsdPost($test['location'], $test['browser'], $test['label'], $cached, $graphData); } } } } }
/** * Generate a HAR file for the given test * * @param mixed $testPath */ function GenerateHAR($id, $testPath, $options) { $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); if (!$run) { $run = 1; } unset($raw); } $pageData[$run] = array(); if (isset($options['cached'])) { $pageData[$run][$options['cached']] = loadPageRunData($testPath, $run, $options['cached']); if (!isset($pageData[$run][$options['cached']])) { unset($pageData); } } else { $pageData[$run][0] = loadPageRunData($testPath, $run, 0); if (!isset($pageData[$run][0])) { unset($pageData); } $pageData[$run][1] = loadPageRunData($testPath, $run, 1); } } 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_PRETTY_PRINT); } else { $json = json_encode($harData, JSON_UNESCAPED_UNICODE); } } else { $jsonLib = new Services_JSON(); $json = $jsonLib->encode($harData); } } return $json; }
/** * Delete all of the video files except for the median run * * @param mixed $id */ function KeepMedianVideo($testPath) { require_once 'page_data.inc'; $pageData = loadAllPageData($testPath); $run = GetMedianRun($pageData, 0); if ($run) { $dir = opendir($testPath); if ($dir) { while ($file = readdir($dir)) { $path = $testPath . "/{$file}/"; if (is_dir($path) && !strncmp($file, 'video_', 6) && $file != "video_{$run}") { delTree("{$path}/"); } } closedir($dir); } } }
echo "<PageSpeedData>http://{$host}{$uri}/result/{$id}/{$fvMedian}_pagespeed.txt</PageSpeedData>\n"; } else { echo "<PageSpeedData>http://{$host}{$uri}//getgzip.php?test={$id}&file={$fvMedian}_pagespeed.txt</PageSpeedData>\n"; } } xmlDomains($id, $testPath, $fvMedian, 0); xmlBreakdown($id, $testPath, $fvMedian, 0); xmlRequests($id, $testPath, $fvMedian, 0); StatusMessages($id, $testPath, $fvMedian, 0); ConsoleLog($id, $testPath, $fvMedian, 0); echo "</firstView>\n"; if (isset($rv)) { if (array_key_exists('rvmedian', $_REQUEST) && $_REQUEST['rvmedian'] == 'fv') { $rvMedian = $fvMedian; } else { $rvMedian = GetMedianRun($pageData, 1, $median_metric); } if ($rvMedian) { echo "<repeatView>\n"; echo "<run>{$rvMedian}</run>\n"; if (array_key_exists('testinfo', $test)) { $tester = null; if (array_key_exists('tester', $test['testinfo'])) { $tester = $test['testinfo']['tester']; } if (array_key_exists('test_runs', $test['testinfo']) && array_key_exists($rvMedian, $test['testinfo']['test_runs']) && array_key_exists('tester', $test['testinfo']['test_runs'][$rvMedian])) { $tester = $test['testinfo']['test_runs'][$rvMedian]['tester'] . '<br>'; } if (isset($tester)) { echo "<tester>" . xml_entities($tester) . "</tester>\n"; }
$info = GetTestInfo($test['id']); if ($info) { if (array_key_exists('discard', $info) && $info['discard'] >= 1 && array_key_exists('priority', $info) && $info['priority'] >= 1) { $defaultInterval = 100; } $test['url'] = $info['url']; } $testInfo = parse_ini_file("./{$test['path']}/testinfo.ini", true); if ($testInfo !== FALSE) { if (array_key_exists('test', $testInfo) && array_key_exists('location', $testInfo['test'])) { $test['location'] = $testInfo['test']['location']; } if (isset($testInfo['test']) && isset($testInfo['test']['completeTime'])) { $test['done'] = true; if (!array_key_exists('run', $test) || !$test['run']) { $test['run'] = GetMedianRun($test['pageData'], $test['cached'], $median_metric); } $test['aft'] = array_key_exists('aft', $test['pageData'][$test['run']][$test['cached']]) ? $test['pageData'][$test['run']][$test['cached']]['aft'] : 0; $loadTime = $test['pageData'][$test['run']][$test['cached']]['fullyLoaded']; if (isset($loadTime) && (!isset($fastest) || $loadTime < $fastest)) { $fastest = $loadTime; } // figure out the real end time (in ms) if (isset($test['end'])) { if (!strcmp($test['end'], 'visual') && array_key_exists('visualComplete', $test['pageData'][$test['run']][$test['cached']])) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['visualComplete']; } elseif (!strcmp($test['end'], 'doc')) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime']; } elseif (!strncasecmp($test['end'], 'doc+', 4)) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime'] + (int) ((double) substr($test['end'], 4) * 1000.0); } elseif (!strcmp($test['end'], 'full')) {
if (isset($_REQUEST['maxReqs']) && strlen($_REQUEST['maxReqs'])) { $maxReqs = $_REQUEST['maxReqs']; } header("Content-disposition: attachment; filename={$id}_headersMatch.csv"); header("Content-type: text/csv"); // list of metrics that will be produced // for each of these, the median, average and std dev. will be calculated echo "\"Test ID\",\"Found\"\r\n"; // and now the actual data foreach ($testIds as &$testId) { $cached = 0; RestoreTest($testId); GetTestStatus($testId); $testPath = './' . GetTestPath($testId); $pageData = loadAllPageData($testPath); $medianRun = GetMedianRun($pageData, $cached); $secured = 0; $haveLocations = 1; $requests = getRequests($testId, $testPath, $medianRun, $cached, $secure, $haveLocations, false, true); // Flag indicating if we matched $matched = array(); $nSearches = count($searches); $nRecords = count($requests); if ($nRecords > $maxReqs && $maxReqs != 0) { $nRecords = $maxReqs; } for ($rec = 0; $rec < $nRecords; $rec++) { $r = $requests[$rec]; if (isset($r['headers']) && isset($r['headers']['response'])) { foreach ($r['headers']['response'] as &$header) { // Loop through the search conditions we received
} } foreach ($tests['variations'] as $variationIndex => &$variation) { $urlVariation = CreateUrlVariation($url, $variation['q']); echo "\"{$urlVariation}\","; $id = $test['v'][$variationIndex]; RestoreTest($id); GetTestStatus($id); $testPath = './' . GetTestPath($id); $pageData = loadAllPageData($testPath); for ($cacheVal = 0; $cacheVal <= $cached; $cacheVal++) { if (count($pageData)) { $count = CountSuccessfulTests($pageData, $cacheVal); echo "\"{$count}\","; if ($use_median_run) { $median_run = GetMedianRun($pageData, $cacheVal, $median_metric); echo "\"{$median_run}\","; } foreach ($metrics as $metric => $metricLabel) { if ($use_median_run) { echo "\"{$pageData[$median_run][$cacheVal][$metric]}\","; } else { CalculateAggregateStats($pageData, $cacheVal, $metric, $median, $avg, $stdDev); echo "\"{$median}\",\"{$avg}\",\"{$stdDev}\","; } } } else { echo '"",'; if ($use_median_run) { echo '"",'; }
if (preg_match('/.*\\.test$/', $file)) { unlink("{$testPath}/{$file}"); } } if (array_key_exists('job_file', $testInfo) && is_file($testInfo['job_file'])) { unlink($testInfo['job_file']); } $perTestTime = 0; $testCount = 0; // do pre-complete post-processing MoveVideoFiles($testPath); WptHookPostProcessResults(__DIR__ . '/../' . $testPath); if (!isset($pageData)) { $pageData = loadAllPageData($testPath); } $medianRun = GetMedianRun($pageData, 0, $medianMetric); $testInfo['medianRun'] = $medianRun; $testInfo_dirty = true; // delete all of the videos except for the median run? if (array_key_exists('median_video', $ini) && $ini['median_video']) { KeepVideoForRun($testPath, $medianRun); } $test = file_get_contents("{$testPath}/testinfo.ini"); $now = gmdate("m/d/y G:i:s", $time); // update the completion time if it isn't already set if (!strpos($test, 'completeTime')) { $complete = "[test]\r\ncompleteTime={$now}"; if ($medianRun) { $complete .= "\r\nmedianRun={$medianRun}"; } $out = str_replace('[test]', $complete, $test);
if ($p[0] == 's') { $test['syncStartRender'] = (int) $p[1]; } if ($p[0] == 'd') { $test['syncDocTime'] = (int) $p[1]; } if ($p[0] == 'f') { $test['syncFullyLoaded'] = (int) $p[1]; } } } RestoreTest($test['id']); $test['path'] = GetTestPath($test['id']); $test['pageData'] = loadAllPageData($test['path']); if (!$test['run']) { $test['run'] = GetMedianRun($test['pageData'], 0, $median_metric); } // figure out the real end time (in ms) if (isset($test['end'])) { if (!strcmp($test['end'], 'visual') && array_key_exists('visualComplete', $test['pageData'][$test['run']][$test['cached']])) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['visualComplete']; } elseif (!strcmp($test['end'], 'doc') || !strcmp($test['end'], 'docvisual')) { if (!strcmp($test['end'], 'docvisual')) { $test['extend'] = true; $videoIdExtra .= 'e'; } $test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime']; } elseif (!strncasecmp($test['end'], 'doc+', 4)) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['docTime'] + (int) ((double) substr($test['end'], 4) * 1000.0); } elseif (!strcmp($test['end'], 'aft')) { $test['end'] = $test['pageData'][$test['run']][$test['cached']]['aft'];
if ($p[0] == 'r') { $test['run'] = (int) $p[1]; } if ($p[0] == 'l') { $test['label'] = urldecode($p[1]); } if ($p[0] == 'c') { $test['cached'] = (int) $p[1]; } } } $test['path'] = GetTestPath($test['id']); $test['pageData'] = loadAllPageData($test['path']); BuildVideoScripts("./{$test['path']}"); if (!$test['run']) { $test['run'] = GetMedianRun($test['pageData']); } $test['videoPath'] = "./{$test['path']}/video_{$test['run']}"; if ($test['cached']) { $test['videoPath'] .= '_cached'; } if (!strlen($test['label'])) { $test['label'] = trim(file_get_contents("./{$test['path']}/label.txt")); } if (!strlen($test['label'])) { $test['label'] = trim(file_get_contents("./{$test['path']}/url.txt")); } $labels[] = $test['label']; if (is_dir($test['videoPath'])) { $tests[] = $test; }
foreach ($pageData as $run => $run_data) { if ($run > $max_runs) { $max_runs = $run; } if (isset($run_data[0]) && isset($run_data[0][$metric])) { $fv[$run] = $run_data[0][$metric]; } if (isset($run_data[1]) && isset($run_data[1][$metric])) { $rv[$run] = $run_data[1][$metric]; } } $fvMedian = GetMedianRun($pageData, 0); if ($fvMedian) { $fvMedianValue = $pageData[$fvMedian][0][$metric]; } $rvMedian = GetMedianRun($pageData, 1); if ($rvMedian) { $rvMedianValue = $pageData[$rvMedian][1][$metric]; } } function labelFormat($aLabel) { return number_format($aLabel); } if (count($fv)) { include "lib/jpgraph/jpgraph.php"; include "lib/jpgraph/jpgraph_scatter.php"; include "lib/jpgraph/jpgraph_line.php"; JpGraphError::SetErrLocale('prod'); $graph = new Graph($width, $height); $graph->SetScale("linlin", 0, 0, 1, $max_runs);
/** * 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; }
foreach ($files as $file) { if (preg_match('/.*\\.test$/', $file)) { unlink("{$testPath}/{$file}"); } } if (array_key_exists('job_file', $testInfo) && is_file($testInfo['job_file'])) { unlink($testInfo['job_file']); } $perTestTime = 0; $testCount = 0; // do pre-complete post-processing MoveVideoFiles($testPath); if (!isset($pageData)) { $pageData = loadAllPageData($testPath); } $medianRun = GetMedianRun($pageData, 0); $testInfo['medianRun'] = $medianRun; $testInfo_dirty = true; // delete all of the videos except for the median run? if (array_key_exists('median_video', $ini) && $ini['median_video']) { KeepVideoForRun($testPath, $medianRun); } $test = file_get_contents("{$testPath}/testinfo.ini"); $now = gmdate("m/d/y G:i:s", $time); // update the completion time if it isn't already set if (!strpos($test, 'completeTime')) { $complete = "[test]\r\ncompleteTime={$now}"; if ($medianRun) { $complete .= "\r\nmedianRun={$medianRun}"; } $out = str_replace('[test]', $complete, $test);
/** * Send a mail notification to the user * * @param mixed $mailto * @param mixed $id * @param mixed $testPath */ function notify($mailto, $from, $id, $testPath, $host) { global $test; // calculate the results require_once 'page_data.inc'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: {$from}\r\n"; $headers .= "Reply-To: {$from}"; $pageData = loadAllPageData($testPath); $url = trim($pageData[1][0]['URL']); $shorturl = substr($url, 0, 40); if (strlen($url) > 40) { $shorturl .= '...'; } $subject = "Test results for {$shorturl}"; $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http'; if (!isset($host)) { $host = $_SERVER['HTTP_HOST']; } $fv = GetMedianRun($pageData, 0); if (isset($fv) && $fv) { $load = number_format($pageData[$fv][0]['loadTime'] / 1000.0, 3); $render = number_format($pageData[$fv][0]['render'] / 1000.0, 3); $numRequests = number_format($pageData[$fv][0]['requests'], 0); $bytes = number_format($pageData[$fv][0]['bytesIn'] / 1024, 0); $result = "{$protocol}://{$host}/result/{$id}"; // capture the optimization report require_once 'optimization.inc'; require_once 'object_detail.inc'; $secure = false; $haveLocations = false; $requests = getRequests($id, $testPath, 1, 0, $secure, $haveLocations, false); ob_start(); dumpOptimizationReport($pageData[$fv][0], $requests, $id, 1, 0, $test); $optimization = ob_get_contents(); ob_end_clean(); // build the message body $body = "<html>\r\n <head>\r\n <title>{$subject}</title>\r\n <style type=\"text/css\">\r\n .indented1 {padding-left: 40pt;}\r\n .indented2 {padding-left: 80pt;}\r\n </style>\r\n </head>\r\n <body>\r\n <p>The full test results for <a href=\"{$url}\">{$url}</a> are now <a href=\"{$result}/\">available</a>.</p>\r\n <p>The page loaded in <b>{$load} seconds</b> with the user first seeing something on the page after <b>{$render} seconds</b>. To download \r\n the page required <b>{$numRequests} requests</b> and <b>{$bytes} KB</b>.</p>\r\n <p>Here is what the page looked like when it loaded (click the image for a larger view):<br><a href=\"{$result}/{$fv}/screen_shot/\"><img src=\"{$result}/{$fv}_screen_thumb.jpg\"></a></p>\r\n <h3>Here are the things on the page that could use improving:</h3>\r\n {$optimization}\r\n </body>\r\n </html>"; // send the actual mail mail($mailto, $subject, $body, $headers); } }
foreach ($parts as $fragment) { $test = array(); $components = explode('-', $fragment); $test['id'] = trim($components[0]); $test['path'] = './' . GetTestPath($test['id']); $test['info'] = json_decode(gz_file_get_contents("{$test['path']}/testinfo.json"), true); $test['page_data'] = loadAllPageData($test['path']); $test['fv_run'] = GetMedianRun($test['page_data'], 0, $median_metric); if ($test['fv_run']) { $test['fv'] = $test['page_data'][$test['fv_run']][0]; $docTime = $test['fv']['docTime'] / 1000; if ($docTime > $fv_max_time) { $fv_max_time = $docTime; } } $test['rv_run'] = GetMedianRun($test['page_data'], 1, $median_metric); if ($test['rv_run']) { $test['rv'] = $test['page_data'][$test['rv_run']][0]; } else { $fvonly = true; } $tests[] = $test; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>WebPagetest Test Comparison</title> <?php $gaTemplate = 'Compare';
<?php include 'common.inc'; require_once 'page_data.inc'; $page_keywords = array('image', 'comparison', 'Webpagetest', 'Website Speed Test'); $page_description = "Visual comparison of multiple website screen shots."; $title = 'Web page screen shot diff'; $gaTemplate = 'Screen Shot Diff'; $refPath = GetTestPath($_REQUEST['ref']); $refData = loadAllPageData($refPath); $cmpPath = GetTestPath($_REQUEST['cmp']); $cmpData = loadAllPageData($cmpPath); $refRun = GetMedianRun($refData, 0, $median_metric); $cmpRun = GetMedianRun($cmpData, 0, $median_metric); if ($refRun && $cmpRun) { $refFile = "{$refPath}/{$refRun}_screen.png"; $cmpFile = "{$cmpPath}/{$cmpRun}_screen.png"; if (is_file($refFile) && is_file($cmpFile)) { $refImg = urlencode("{$_REQUEST['ref']}/{$refRun}_screen.png"); $cmpImg = urlencode("{$_REQUEST['cmp']}/{$cmpRun}_screen.png"); } } ?> <!DOCTYPE html> <html> <head> <title>WebPagetest - Screen Shot diff</title> <?php include 'head.inc'; ?> </head>
<?php chdir('..'); include 'common.inc'; include 'page_data.inc'; include './video/visualProgress.inc.php'; $page_keywords = array('Video', 'comparison', 'Webpagetest', 'Website Speed Test'); $page_description = "Side-by-side video comparison of website performance."; $title = "WebPagetest - Visual Progress"; $run = (int) @$req_run; if (!$run) { $pageData = loadAllPageData($testPath); $run = GetMedianRun($pageData, $cached, $median_metric); } $cachedText = ''; if ($run) { $videoPath = "{$testPath}/video_{$run}"; if ($cached) { $videoPath .= '_cached'; $cachedText = '_cached'; } $frames = GetVisualProgress($testPath, $run, $cached); } function GetSIProgress($time) { global $frames; $progress = 0; foreach ($frames['DevTools']['VisualProgress'] as $progressTime => $prog) { if ($progressTime <= $time) { $progress = intval($prog * 100); } else {
* * Export a result data set in HTTP archive format: * http://groups.google.com/group/firebug-working-group/web/http-tracing---export-format * ******************************************************************************/ include 'common.inc'; require_once 'page_data.inc'; include 'object_detail.inc'; require_once 'lib/json.php'; // see if we are loading a single run or all of them if (isset($testPath)) { $pageData; if (isset($_REQUEST["run"]) && $_REQUEST["run"]) { if (!strcasecmp($_REQUEST["run"], 'median')) { $raw = loadAllPageData($testPath); $run = GetMedianRun($raw, $cached, $median_metric); if (!$run) { $run = 1; } unset($raw); } $pageData[$run] = array(); if (isset($cached)) { $pageData[$run][$cached] = loadPageRunData($testPath, $run, $cached); } else { $pageData[$run][0] = loadPageRunData($testPath, $run, 0); $pageData[$run][1] = loadPageRunData($testPath, $run, 1); } } else { $pageData = loadAllPageData($testPath); }
/** * 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; }
public function testGetMedianRun() { $this->assertEquals(1, GetMedianRun($this->pageData, 0, 'TTFB')); $this->assertEquals(1, GetMedianRun($this->pageData2, 0, 'TTFB')); }