/**
* 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;
}
Exemple #2
0
function RenderVideo(&$tests)
{
    global $width, $height, $maxAspectRatio, $videoExtendTime, $biggestThumbnail, $fps, $labelHeight, $timeHeight, $rowPadding, $speed, $fractionTime;
    // adjust the label sizes if we have a LOT of tests
    $scale = 1;
    $count = count($tests);
    if ($count > 49) {
        $scale = 0;
    } elseif ($count > 36) {
        $scale = 0.5;
    } elseif ($count > 25) {
        $scale = 0.6;
    } elseif ($count > 16) {
        $scale = 0.7;
    } elseif ($count > 9) {
        $scale = 0.8;
    }
    // Figure out the end time of the video and
    // make sure all of the tests are restored.
    $videoEnd = 0;
    $all_http = true;
    foreach ($tests as &$test) {
        if (isset($test['label']) && strlen($test['label']) && substr($test['label'], 0, 7) !== 'http://') {
            $all_http = false;
        }
        if (isset($test['speed']) && $test['speed'] > 0 && $test['speed'] < 10) {
            $speed = $test['speed'];
        }
        if (isset($test['bare']) && $test['bare']) {
            $scale = 0;
        }
        if (isset($test['id'])) {
            RestoreTest($test['id']);
        }
        if (isset($test['end']) && is_numeric($test['end']) && $test['end'] > $videoEnd) {
            $videoEnd = $test['end'];
        }
        if (isset($test['path']) && isset($test['run']) && isset($test['cached'])) {
            $progress = GetVisualProgress("./{$test['path']}", $test['run'], $test['cached']);
            if (isset($progress) && is_array($progress) && isset($progress['frames'])) {
                $test['frames'] = $progress['frames'];
                if (count($test['frames'])) {
                    $frame = current($test['frames']);
                    $dim = getimagesize("./{$frame['path']}");
                    $size = max($dim[0], $dim[1]);
                    if ($size > $biggestThumbnail) {
                        $biggestThumbnail = $size;
                    }
                    $test['aspect'] = $dim[0] / $dim[1];
                    if ($test['aspect'] > $maxAspectRatio) {
                        $maxAspectRatio = $test['aspect'];
                    }
                    if (stripos($frame['file'], 'ms_') !== false) {
                        $fps = 60;
                        //$fractionTime = 100;
                    }
                }
            }
        }
    }
    if ($scale < 1) {
        $labelHeight = ceil($labelHeight * $scale);
        $timeHeight = ceil($timeHeight * $scale);
        $rowPadding = ceil($rowPadding * $scale);
    }
    // no need for 60fps video if we are running in slow motion
    if ($speed < 0.5 && $fps == 60) {
        $fps = 30;
    }
    // Keep the time extension constant
    $videoExtendTime = $videoExtendTime * $speed;
    if ($all_http) {
        foreach ($tests as &$test) {
            if (isset($test['label']) && strlen($test['label']) && substr($test['label'], 0, 7) === 'http://') {
                $test['label'] = substr($test['label'], 7);
            }
        }
    }
    if ($videoEnd > 0) {
        $videoEnd += $videoExtendTime;
        $frameCount = ceil($videoEnd * $fps / 1000 / $speed);
        CalculateVideoDimensions($tests);
        $im = imagecreatetruecolor($width, $height);
        if ($im !== false) {
            RenderFrames($tests, $frameCount, $im);
            imagedestroy($im);
        }
    }
}
Exemple #3
0
function SpeedIndex($testPath, $run, $cached, $testInfo)
{
    $speed_index = '';
    $pageData = loadPageRunData($testPath, $run, $cached, null, $testInfo);
    $startOffset = array_key_exists('testStartOffset', $pageData) ? intval(round($pageData['testStartOffset'])) : 0;
    $progress = GetVisualProgress($testPath, $run, $cached, null, null, $startOffset);
    if (isset($progress) && is_array($progress) && array_key_exists('SpeedIndex', $progress)) {
        $speed_index = $progress['SpeedIndex'];
    }
    return $speed_index;
}
/**
* 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'];
            }
        }
    }
}
 if (gz_is_file("{$testPath}/{$i}_Cached_IEWPG.txt")) {
     echo "<pageData>http://{$host}{$uri}{$path}/{$i}_Cached_IEWPG.txt</pageData>\n";
 }
 if (gz_is_file("{$testPath}/{$i}_Cached_IEWTR.txt")) {
     echo "<requestsData>http://{$host}{$uri}{$path}/{$i}_Cached_IEWTR.txt</requestsData>\n";
 }
 if (gz_is_file("{$testPath}/{$i}_Cached_progress.csv")) {
     echo "<utilization>http://{$host}{$uri}{$path}/{$i}_Cached_progress.csv</utilization>\n";
 }
 if (gz_is_file("{$testPath}/{$i}_Cached_pagespeed.txt")) {
     echo "<PageSpeedData>http://{$host}{$uri}/result/{$id}/{$i}_Cached_pagespeed.txt</PageSpeedData>\n";
 }
 echo "</rawData>\n";
 // video frames
 $startOffset = array_key_exists('testStartOffset', $pageData[$i][1]) ? intval(round($pageData[$i][1]['testStartOffset'])) : 0;
 $progress = GetVisualProgress($testPath, $i, 1, null, null, $startOffset);
 if (array_key_exists('frames', $progress) && is_array($progress['frames']) && count($progress['frames'])) {
     echo "<videoFrames>\n";
     foreach ($progress['frames'] as $ms => $frame) {
         echo "<frame>\n";
         echo "<time>{$ms}</time>\n";
         echo "<image>http://{$host}{$uri}{$path}/video_{$i}_cached/{$frame['file']}</image>\n";
         echo "<VisuallyComplete>{$frame['progress']}</VisuallyComplete>\n";
         echo "</frame>\n";
     }
     echo "</videoFrames>\n";
 }
 if (isset($progress) && is_array($progress) && array_key_exists('DevTools', $progress) && is_array($progress['DevTools']) && array_key_exists('processing', $progress['DevTools'])) {
     echo "<processing>\n";
     foreach ($progress['DevTools']['processing'] as $key => $value) {
         echo "<{$key}>{$value}</{$key}>\n";
$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 {
            break;
        }
    }
    return $progress;
}
?>