/** * 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; }
/** * Send a mail notification to the user * * @param mixed $mailto * @param mixed $id * @param mixed $testPath */ function notify($mailto, $from, $id, $testPath, $host) { $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}"; $url; if (is_file("{$testPath}/url.txt")) { $url = htmlspecialchars(file_get_contents("{$testPath}/url.txt")); } $shorturl = substr($url, 0, 40); if (strlen($url) > 40) { $shorturl .= '...'; } $subject = "Test results for {$shorturl}"; if (!isset($host)) { $host = $_SERVER['HTTP_HOST']; } // calculate the results require_once '../page_data.inc'; $pageData = loadAllPageData($testPath); $fv = null; $rv = null; $pageStats = calculatePageStats($pageData, $fv, $rv); if (isset($fv)) { $load = number_format($fv['loadTime'] / 1000.0, 3); $render = number_format($fv['render'] / 1000.0, 3); $requests = number_format($fv['requests'], 0); $bytes = number_format($fv['bytesIn'] / 1024, 0); $result = "http://{$host}/result/{$id}"; // capture the optimization report require_once '../optimization.inc'; ob_start(); dumpOptimizationReport($testPath, 1, 0); $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>{$requests} 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}/1/screen_shot/\"><img src=\"{$result}/1_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); } }
function IsTestValid($id) { $valid = false; $testPath = './' . GetTestPath($id); $page_data = loadAllPageData($testPath); if (CountSuccessfulTests($page_data, 0) >= 3) { $valid = true; } return $valid; }
function csvPageData($id, $testPath, $runs) { if ($_GET['requests']) { for ($i = 1; $i <= $runs; $i++) { for ($cached = 0; $cached <= 1; $cached++) { $requests = getRequests($id, $testPath, $i, $cached, $secure, $loc, false); if (isset($requests) && is_array($requests) && count($requests)) { foreach ($requests as &$row) { csvArray($row, $id, $i, $cached); } } } } } else { $pageData = loadAllPageData($testPath); if ($pageData && is_array($pageData) && count($pageData)) { for ($i = 1; $i <= $runs; $i++) { if (array_key_exists($i, $pageData)) { if (array_key_exists(0, $pageData[$i])) { csvArray($pageData[$i][0], $id, $i, 0); } if (array_key_exists(1, $pageData[$i])) { csvArray($pageData[$i][1], $id, $i, 1); } } } } } }
$test['run'] = (int) $p[1]; } if ($p[0] == 'l') { $test['label'] = $p[1]; } if ($p[0] == 'c') { $test['cached'] = (int) $p[1]; } if ($p[0] == 'e') { $test['end'] = trim($p[1]); } } } RestoreTest($test['id']); $test['path'] = GetTestPath($test['id']); $test['pageData'] = loadAllPageData($test['path']); $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']) {
/** * 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); } } }
/** * 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); } }
<?php include 'common.inc'; require_once 'page_data.inc'; if (array_key_exists('f', $_REQUEST) && $_REQUEST['f'] == 'json') { include 'jsonResult.php'; } elseif (array_key_exists('f', $_REQUEST) && $_REQUEST['f'] == 'xml') { include 'xmlResult.php'; } else { $options = null; if (array_key_exists('end', $_REQUEST)) { $options = array('end' => $_REQUEST['end']); } $pageData = loadAllPageData($testPath, $options); // if we don't have an url, try to get it from the page results if (!strlen($url)) { $url = $pageData[1][0]['URL']; } if (array_key_exists('testinfo', $test) && array_key_exists('spam', $test['testinfo']) && $test['testinfo']['spam']) { include 'resultSpam.inc.php'; } else { if (isset($test['test']) && ($test['test']['batch'] || $test['test']['batch_locations']) || !array_key_exists('test', $test) && array_key_exists('testinfo', $test) && $test['testinfo']['batch']) { include 'resultBatch.inc'; } elseif (isset($test['testinfo']['cancelled'])) { include 'testcancelled.inc'; } elseif (isset($test['test']) && isset($test['test']['completeTime']) || count($pageData) > 0) { if (@$test['test']['type'] == 'traceroute') { include 'resultTraceroute.inc'; } else { include 'result.inc'; }
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"; }
<?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>
/** * Upload a test result to a TSView instance */ function TSViewPostResult(&$test, $id, $testPath, $server, $tsview_name) { 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); $metrics = array('availability' => 1); $fv = array('availability' => array()); if (!$test['fvonly']) { $rv = array('availability' => array()); } for ($run = 1; $run <= $runs; $run++) { if (array_key_exists($run, $pageData)) { // collect the first-view data if (array_key_exists(0, $pageData[$run]) && array_key_exists('result', $pageData[$run][0]) && ($pageData[$run][0]['result'] == 0 || $pageData[$run][0]['result'] == 99999)) { $fv['availability'][] = 1; foreach ($pageData[$run][0] as $metric => $value) { if (is_int($value) && $metric != 'result') { if (!array_key_exists($metric, $metrics)) { $metrics[$metric] = 1; } if (!array_key_exists($metric, $fv)) { $fv[$metric] = array(); } $fv[$metric][] = $value; } } } else { $fv['availability'][] = 0; } // collect the repeat view data if (isset($rv)) { if (array_key_exists(1, $pageData[$run]) && array_key_exists('result', $pageData[$run][1]) && ($pageData[$run][1]['result'] == 0 || $pageData[$run][1]['result'] == 99999)) { $rv['availability'][] = 1; foreach ($pageData[$run][1] as $metric => $value) { if (is_int($value) && $metric != 'result') { if (!array_key_exists($metric, $metrics)) { $metrics[$metric] = 1; } if (!array_key_exists($metric, $rv)) { $rv[$metric] = array(); } $rv[$metric][] = $value; } } } else { $rv['availability'][] = 0; } } } else { $fv['availability'][] = 0; if (isset($rv)) { $rv['availability'][] = 0; } } } if (array_key_exists('tsview_configs', $test)) { $configs = explode(",", $test['tsview_configs']); } else { $configs = array(); } $results_host = $test['tsview_results_host']; $spof = ""; if ($test['label'] == 'SPOF') { $spof = "-SPOF"; } $datasource = "{$tsview_name}{$spof}"; TSViewCreate($server, $datasource, $metrics); TSViewPost($id, $server, $datasource, $fv, $results_host); if (isset($rv)) { TSViewCreate($server, "{$datasource}-repeat-view", $metrics); TSViewPost($id, $server, "{$datasource}-repeat-view", $rv, $results_host); } } }
// delete any .test files $files = scandir($testPath); 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}";
/** * 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; }
/** * 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; }
<?php include 'common.inc'; require_once 'page_data.inc'; if (array_key_exists('f', $_REQUEST) && $_REQUEST['f'] == 'json') { include 'jsonResult.php'; } elseif (array_key_exists('f', $_REQUEST) && $_REQUEST['f'] == 'xml') { include 'xmlResult.php'; } else { $options = null; if (array_key_exists('end', $_REQUEST)) { $options = array('end' => $_REQUEST['end']); } $pageData = loadAllPageData($testPath, $unusedrequests, $options); // if we don't have an url, try to get it from the page results if (!strlen($url) && isset($pageData[1][0]['URL'])) { $url = $pageData[1][0]['URL']; } if (array_key_exists('testinfo', $test) && array_key_exists('spam', $test['testinfo']) && $test['testinfo']['spam']) { include 'resultSpam.inc.php'; } else { if (isset($test['test']) && ($test['test']['batch'] || $test['test']['batch_locations']) || !array_key_exists('test', $test) && array_key_exists('testinfo', $test) && $test['testinfo']['batch']) { include 'resultBatch.inc'; } elseif (isset($test['testinfo']['cancelled'])) { include 'testcancelled.inc'; } elseif (isset($test['test']) && isset($test['test']['completeTime']) || count($pageData) > 0) { if (@$test['test']['type'] == 'traceroute') { include 'resultTraceroute.inc'; } else { include 'result.inc'; }