<?php chdir('..'); include 'common.inc'; require_once './benchmarks/data.inc.php'; $page_keywords = array('Benchmarks', 'Webpagetest', 'Website Speed Test', 'Page Speed'); $page_description = "WebPagetest benchmark details"; $aggregate = 'median'; if (array_key_exists('aggregate', $_REQUEST)) { $aggregate = $_REQUEST['aggregate']; } $benchmark = ''; if (array_key_exists('benchmark', $_REQUEST)) { $benchmark = $_REQUEST['benchmark']; $info = GetBenchmarkInfo($benchmark); if (array_key_exists('options', $info) && array_key_exists('median_run', $info['options'])) { $median_metric = $info['options']['median_run']; } } $url = ''; if (array_key_exists('url', $_REQUEST)) { $url = $_REQUEST['url']; } if (array_key_exists('f', $_REQUEST)) { $out_data = array(); } else { ?> <!DOCTYPE html> <html> <head> <title>WebPagetest - Benchmark trended URL</title>
/** * Generate aggregate metrics for the given test * * @param mixed $benchmark * @param mixed $state */ function AggregateResults($benchmark, &$state, $options) { global $logFile; if (!is_dir("./results/benchmarks/{$benchmark}/aggregate")) { mkdir("./results/benchmarks/{$benchmark}/aggregate", 0777, true); } if (is_file("./results/benchmarks/{$benchmark}/aggregate/info.json")) { $info = json_decode(file_get_contents("./results/benchmarks/{$benchmark}/aggregate/info.json"), true); } else { $info = array('runs' => array()); } if (!array_key_exists('runs', $info)) { $info['runs'] = array(); } // store a list of metrics that we aggregate in the info block $info['metrics'] = array('TTFB', 'basePageSSLTime', 'bytesOut', 'bytesOutDoc', 'bytesIn', 'bytesInDoc', 'connections', 'requests', 'requestsDoc', 'render', 'fullyLoaded', 'docTime', 'domTime', 'score_cache', 'score_cdn', 'score_gzip', 'score_keep-alive', 'score_compress', 'gzip_total', 'gzip_savings', 'image_total', 'image_savings', 'domElements', 'titleTime', 'loadEvent-Time', 'domContentLoadedEventStart', 'domContentLoadedEvent-Time', 'visualComplete', 'lastVisualChange', 'js_bytes', 'js_requests', 'css_bytes', 'css_requests', 'image_bytes', 'image_requests', 'flash_bytes', 'flash_requests', 'html_bytes', 'html_requests', 'text_bytes', 'text_requests', 'other_bytes', 'other_requests', 'SpeedIndex', 'responses_404', 'responses_other', 'browser_version', 'server_rtt', 'docCPUms'); require_once 'benchmarks/data.inc.php'; $bmSettings = GetBenchmarkInfo($benchmark); if (isset($bmSettings) && is_array($bmSettings) && array_key_exists('metrics', $bmSettings) && is_array($bmSettings['metrics'])) { foreach ($bmSettings['metrics'] as $metric => $label) { $info['metrics'][] = $metric; } } // loop through all of the runs and see which ones we don't have aggregates for $runs = array_reverse($state['runs']); foreach ($runs as $run_time) { if (!array_key_exists($run_time, $info['runs'])) { $file_name = "./results/benchmarks/{$benchmark}/data/" . gmdate('Ymd_Hi', $run_time) . '.json'; logMsg("Aggregating Results for {$file_name}", "./log/{$logFile}", true); if (gz_is_file($file_name)) { $data = json_decode(gz_file_get_contents($file_name), true); FilterRawData($data, $options); CreateAggregates($info, $data, $benchmark, $run_time, $options); unset($data); $info['runs'][$run_time] = 1; } else { logMsg("Missing data file - {$file_name}", "./log/{$logFile}", true); } } } file_put_contents("./results/benchmarks/{$benchmark}/aggregate/info.json", json_encode($info)); $state['needs_aggregation'] = false; logMsg("Agregation complete", "./log/{$logFile}", true); }
/** * Load the test data and keep just the median run for each config */ function LoadMedianData($benchmark, $test_time) { global $median_data; global $raw_data; if (!isset($median_data)) { // see if we have a custom metric to use to calculate the median for the given benchmark $info = GetBenchmarkInfo($benchmark); $median_metric = 'docTime'; if (isset($info) && is_array($info) && array_key_exists('options', $info) && array_key_exists('median_run', $info['options'])) { $median_metric = $info['options']['median_run']; } $date = gmdate('Ymd_Hi', $test_time); $data_file = "./results/benchmarks/{$benchmark}/data/{$date}.json"; $key = "{$benchmark}-{$date}"; if (gz_is_file($data_file)) { if (!array_key_exists($key, $raw_data)) { $raw_data[$key] = json_decode(gz_file_get_contents($data_file), true); usort($raw_data[$key], 'RawDataCompare'); } if (count($raw_data[$key])) { $tests = array(); // group the results by test ID foreach ($raw_data[$key] as &$row) { if (array_key_exists($median_metric, $row) && ($row['result'] == 0 || $row['result'] == 99999)) { $id = $row['id']; $cached = $row['cached']; $key = "{$id}-{$cached}"; if (!array_key_exists($key, $tests)) { $tests[$key] = array(); } $tests[$key][] = $row; } } // extract just the median runs $median_data = array(); foreach ($tests as &$test) { $times = array(); foreach ($test as $row) { $times[] = $row[$median_metric]; } $median_run_index = 0; $count = count($times); if ($count > 1) { asort($times); $medianIndex = (int) floor(((double) $count + 1.0) / 2.0); $current = 0; foreach ($times as $index => $time) { $current++; if ($current == $medianIndex) { $median_run_index = $index; break; } } } $row = $test[$median_run_index]; if (array_key_exists('cached', $row) && array_key_exists('url', $row) && array_key_exists('config', $row) && array_key_exists('location', $row)) { $url = $row['url']; if (array_key_exists('label', $row) && strlen($row['label'])) { $url = $row['label']; } $config = $row['config']; $location = $row['location']; $cached = $row['cached']; if (isset($loc_aliases) && count($loc_aliases)) { foreach ($loc_aliases as $loc_name => &$aliases) { foreach ($aliases as $alias) { if ($location == $alias) { $location = $loc_name; break 2; } } } } if (!array_key_exists($config, $median_data)) { $median_data[$config] = array(); } if (!array_key_exists($location, $median_data[$config])) { $median_data[$config][$location] = array(); } if (!array_key_exists($cached, $median_data[$config][$location])) { $median_data[$config][$location][$cached] = array(); } $median_data[$config][$location][$cached][$url] = $row; } } } } } }