/** * Gather all of the data that we collect for a single run * * @param mixed $id * @param mixed $testPath * @param mixed $run * @param mixed $cached */ function GetSingleRunData($id, $testPath, $run, $cached, &$pageData, $testInfo) { $ret = null; if (array_key_exists($run, $pageData) && is_array($pageData[$run]) && array_key_exists($cached, $pageData[$run]) && is_array($pageData[$run][$cached])) { $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); $ret = $pageData[$run][$cached]; $ret['run'] = $run; $cachedText = ''; if ($cached) { $cachedText = '_Cached'; } if (isset($testInfo)) { if (array_key_exists('tester', $testInfo)) { $ret['tester'] = $testInfo['tester']; } if (array_key_exists('test_runs', $testInfo) && array_key_exists($run, $testInfo['test_runs']) && array_key_exists('tester', $testInfo['test_runs'][$run])) { $ret['tester'] = $testInfo['test_runs'][$run]['tester']; } } $basic_results = false; if (array_key_exists('basic', $_REQUEST) && $_REQUEST['basic']) { $basic_results = true; } if (!$basic_results && gz_is_file("{$testPath}/{$run}{$cachedText}_pagespeed.txt")) { $ret['PageSpeedScore'] = GetPageSpeedScore("{$testPath}/{$run}{$cachedText}_pagespeed.txt"); $ret['PageSpeedData'] = "{$protocol}://{$host}{$uri}//getgzip.php?test={$id}&file={$run}{$cachedText}_pagespeed.txt"; } $ret['pages'] = array(); $ret['pages']['details'] = "{$protocol}://{$host}{$uri}/details.php?test={$id}&run={$run}&cached={$cached}"; $ret['pages']['checklist'] = "{$protocol}://{$host}{$uri}/performance_optimization.php?test={$id}&run={$run}&cached={$cached}"; $ret['pages']['breakdown'] = "{$protocol}://{$host}{$uri}/breakdown.php?test={$id}&run={$run}&cached={$cached}"; $ret['pages']['domains'] = "{$protocol}://{$host}{$uri}/domains.php?test={$id}&run={$run}&cached={$cached}"; $ret['pages']['screenShot'] = "{$protocol}://{$host}{$uri}/screen_shot.php?test={$id}&run={$run}&cached={$cached}"; $ret['thumbnails'] = array(); $ret['thumbnails']['waterfall'] = "{$protocol}://{$host}{$uri}/result/{$id}/{$run}{$cachedText}_waterfall_thumb.png"; $ret['thumbnails']['checklist'] = "{$protocol}://{$host}{$uri}/result/{$id}/{$run}{$cachedText}_optimization_thumb.png"; $ret['thumbnails']['screenShot'] = "{$protocol}://{$host}{$uri}/result/{$id}/{$run}{$cachedText}_screen_thumb.png"; $ret['images'] = array(); $ret['images']['waterfall'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_waterfall.png"; $ret['images']['connectionView'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_connection.png"; $ret['images']['checklist'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_optimization.png"; $ret['images']['screenShot'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_screen.jpg"; if (is_file("{$testPath}/{$run}{$cachedText}_screen.png")) { $ret['images']['screenShotPng'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_screen.png"; } $ret['rawData'] = array(); $ret['rawData']['headers'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_report.txt"; $ret['rawData']['pageData'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_IEWPG.txt"; $ret['rawData']['requestsData'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_IEWTR.txt"; $ret['rawData']['utilization'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_progress.csv"; if (is_file("{$testPath}/{$run}{$cachedText}_bodies.zip")) { $ret['rawData']['bodies'] = "{$protocol}://{$host}{$uri}{$path}/{$run}{$cachedText}_bodies.zip"; } if (!$basic_results) { $startOffset = array_key_exists('testStartOffset', $ret) ? intval(round($ret['testStartOffset'])) : 0; $progress = GetVisualProgress($testPath, $run, $cached, null, null, $startOffset); if (array_key_exists('frames', $progress) && is_array($progress['frames']) && count($progress['frames'])) { $cachedTextLower = strtolower($cachedText); $ret['videoFrames'] = array(); foreach ($progress['frames'] as $ms => $frame) { $videoFrame = array('time' => $ms); $videoFrame['image'] = "http://{$host}{$uri}{$path}/video_{$run}{$cachedTextLower}/{$frame['file']}"; $videoFrame['VisuallyComplete'] = $frame['progress']; $ret['videoFrames'][] = $videoFrame; } } $requests = getRequests($id, $testPath, $run, $cached, $secure, $haveLocations, false, true); $ret['domains'] = getDomainBreakdown($id, $testPath, $run, $cached, $requests); $ret['breakdown'] = getBreakdown($id, $testPath, $run, $cached, $requests); // check if removing requests $addRequests = 1; if (isset($_GET['requests'])) { if ($_GET['requests'] == 0) { $addRequests = 0; } } // add requests if ($addRequests == 1) { $ret['requests'] = $requests; } $console_log = DevToolsGetConsoleLog($testPath, $run, $cached); if (isset($console_log)) { $ret['consoleLog'] = $console_log; } if (gz_is_file("{$testPath}/{$run}{$cachedText}_status.txt")) { $ret['status'] = array(); $lines = gz_file("{$testPath}/{$run}{$cachedText}_status.txt"); foreach ($lines as $line) { $line = trim($line); if (strlen($line)) { list($time, $message) = explode("\t", $line); if (strlen($time) && strlen($message)) { $ret['status'][] = array('time' => $time, 'message' => $message); } } } } } } return $ret; }
/** * Take a tab-separated file, convert it to csv and spit it out * * @param mixed $fileName * @param mixed $includeHeader */ function csvFile($fileName, $label, $column_count, &$additional_columns) { $lines = gz_file($fileName); if ($lines) { // loop through each line in the file foreach ($lines as $linenum => $line) { if ($linenum > 0 || strncasecmp($line, 'Date', 4)) { $line = trim($line, "\r\n"); if (strlen($line)) { $parseLine = str_replace("\t", "\t ", $line); $fields = explode("\t", $parseLine); if (count($fields)) { if (isset($label)) { $label = str_replace('"', '', $label); echo "\"{$label}\","; } for ($i = 0; $i < $column_count; $i++) { $value = ''; if (array_key_exists($i, $fields)) { $value = str_replace('"', '""', trim($fields[$i])); } echo "\"{$value}\","; } if (isset($additional_columns) && count($additional_columns)) { foreach ($additional_columns as $value) { $value = str_replace('"', '""', trim($value)); echo "\"{$value}\","; } } echo "\r\n"; } } } } } }
/** * Load the status messages into an array * * @param mixed $path */ function LoadStatusMessages($path) { $messages = array(); if (is_file($path)) { $lines = gz_file($path); if (isset($lines) && is_array($lines)) { foreach ($lines as $line) { $line = trim($line); if (strlen($line)) { $parts = explode("\t", $line); $time = (double) $parts[0] / 1000.0; $message = trim($parts[1]); if ($time >= 0.0) { $msg = array('time' => $time, 'message' => $message); $messages[] = $msg; } } } } } return $messages; }
/** * Dump any logged browser status messages * * @param mixed $id * @param mixed $testPath * @param mixed $run * @param mixed $cached */ function StatusMessages($id, $testPath, $run, $cached) { $cachedText = ''; if ($cached) { $cachedText = '_Cached'; } $statusFile = "{$testPath}/{$run}{$cachedText}_status.txt"; if (gz_is_file($statusFile)) { echo "<status>\n"; $messages = array(); $lines = gz_file($statusFile); foreach ($lines as $line) { $line = trim($line); if (strlen($line)) { $parts = explode("\t", $line); $time = xml_entities(trim($parts[0])); $message = xml_entities(trim($parts[1])); echo "<entry>\n"; echo "<time>{$time}</time>\n"; echo "<message>{$message}</message>\n"; echo "</entry>\n"; } } echo "</status>\n"; } }
/** * @param TestStepResult $stepResult * @return string Markup with links */ private function _getTimelineLinks($stepResult) { if (!$this->testInfo->hasTimeline()) { return ""; } $localPaths = $stepResult->createTestPaths(); if (!gz_is_file($localPaths->devtoolsTraceFile()) && !gz_is_file($localPaths->devtoolsTimelineFile()) && !gz_file($localPaths->devtoolsFile())) { return ""; } $urlGenerator = $stepResult->createUrlGenerator("", FRIENDLY_URLS); $downloadUrl = $urlGenerator->stepDetailPage("getTimeline"); $viewUrl = $urlGenerator->stepDetailPage("chrome/timeline"); $breakdownUrl = $urlGenerator->stepDetailPage("breakdownTimeline"); $out = "<br><br>\n"; $out .= "<a href=\"{$downloadUrl}\" title=\"Download Chrome Dev Tools Timeline\">Timeline</a>\n"; $out .= " (<a href=\"{$viewUrl}\" title=\"View Chrome Dev Tools Timeline\">view</a>)\n"; $out .= "<br>\n"; $out .= "<a href=\"{$breakdownUrl}\" title=\"View browser main thread activity by event type\">Processing Breakdown</a>"; return $out; }