Пример #1
0
/**
* Check the status of any pending tests
* 
* @param mixed $state
*/
function CheckBenchmarkStatus($benchmark, &$state)
{
    global $logFile;
    if ($state['running']) {
        $start_time = $state['last_run'];
        if (!is_dir("./results/benchmarks/{$benchmark}/data")) {
            mkdir("./results/benchmarks/{$benchmark}/data", 0777, true);
        }
        $dataFile = "./results/benchmarks/{$benchmark}/data/" . gmdate('Ymd_Hi', $start_time) . '.json';
        logMsg("Data File: {$dataFile}", "./log/{$logFile}", true);
        $updated = 0;
        if (gz_is_file($dataFile)) {
            $data = json_decode(gz_file_get_contents($dataFile), true);
            logMsg("Loaded " . count($data) . " existing records", "./log/{$logFile}", true);
        } else {
            $data = array();
            logMsg("Data file doesn't exist, starting fresh", "./log/{$logFile}", true);
        }
        $done = true;
        $total_tests = count($state['tests']);
        $pending_tests = 0;
        foreach ($state['tests'] as &$test) {
            if (!$test['completed']) {
                $status = GetTestStatus($test['id'], true);
                $now = time();
                if ($status['statusCode'] >= 400) {
                    logMsg("Test {$test['id']} : Failed - {$status['statusText']}", "./log/{$logFile}", true);
                    $test['completed'] = $now;
                } elseif ($status['statusCode'] == 200) {
                    logMsg("Test {$test['id']} : Completed", "./log/{$logFile}", true);
                    if (array_key_exists('completeTime', $status) && $status['completeTime']) {
                        $test['completed'] = $status['completeTime'];
                    } elseif (array_key_exists('startTime', $status) && $status['startTime']) {
                        $test['completed'] = $status['startTime'];
                    } else {
                        $test['completed'] = $now;
                    }
                } else {
                    $pending_tests++;
                    $done = false;
                    logMsg("Test {$test['id']} : {$status['statusText']}", "./log/{$logFile}", true);
                }
                // collect the test data and archive the test as we get each result
                if ($test['completed']) {
                    $updated++;
                    CollectResults($test, $data);
                    if (ArchiveTest($test['id'])) {
                        logMsg("Test {$test['id']} : Archived", "./log/{$logFile}", true);
                        $path = GetTestPath($test['id']);
                        if (strlen($path)) {
                            delTree($path);
                        }
                    }
                }
            }
        }
        if ($updated) {
            logMsg("Data updated for for {$updated} tests, total data rows: " . count($data), "./log/{$logFile}", true);
            gz_file_put_contents($dataFile, json_encode($data));
        } else {
            logMsg("No test data updated", "./log/{$logFile}", true);
        }
        $now = time();
        $elapsed = $now > $start_time ? $now - $start_time : 0;
        if ($elapsed > 172800) {
            // kill it if it has been running for 2 days
            $done = true;
        }
        if ($done) {
            logMsg("Benchmark '{$benchmark}' is finished after running for {$elapsed} seconds", "./log/{$logFile}", true);
            $state['runs'][] = $start_time;
            $state['running'] = false;
            $state['needs_aggregation'] = true;
            unset($state['tests']);
        } else {
            logMsg("'{$benchmark}' is waiting for {$pending_tests} of {$total_tests} tests after {$elapsed} seconds", "./log/{$logFile}", true);
        }
        logMsg("Done checking status", "./log/{$logFile}", true);
    }
}
Пример #2
0
/**
* Check the given log file for all tests that match
* 
* @param mixed $logFile
* @param mixed $match
*/
function CheckTest($testPath, $id, $elapsedDays)
{
    global $archiveCount;
    global $deleted;
    global $kept;
    global $log;
    global $MIN_DAYS;
    $logLine = "{$id} : ";
    echo "\rArc:{$archiveCount}, Del:{$deleted}, Kept:{$kept}, Checking:" . str_pad($id, 45);
    $delete = false;
    if (!is_file("{$testPath}/testinfo.ini") && !is_file("{$testPath}/testinfo.json.gz") && !is_file("{$testPath}/testinfo.json")) {
        $delete = true;
    } else {
        $elapsed = TestLastAccessed($id);
        if (isset($elapsed)) {
            if ($elapsed >= $MIN_DAYS) {
                if (ArchiveTest($id)) {
                    $archiveCount++;
                    $logLine .= "Archived";
                    if (VerifyArchive($id) || $elapsed >= 30) {
                        $delete = true;
                    }
                } else {
                    if ($elapsed < 60) {
                        $status = GetTestStatus($id, false);
                        if ($status['statusCode'] >= 400 || $status['statusCode'] == 102 && $status['remote'] && $elapsed > 1) {
                            $delete = true;
                        }
                    } elseif ($elapsedDays > 10) {
                        $logLine .= "Old test, Failed to archive, deleting";
                        $delete = true;
                    } else {
                        $logLine .= "Failed to archive";
                    }
                }
            } else {
                $logLine .= "Last Accessed {$elapsed} days";
            }
        } else {
            $delete = true;
        }
    }
    if ($delete) {
        delTree("{$testPath}/");
        $deleted++;
        $logLine .= " Deleted";
    } else {
        $kept++;
    }
    if ($log) {
        $logLine .= "\n";
        fwrite($log, $logLine);
    }
}
Пример #3
0
             unset($beaconUrl);
         } else {
             $lock = LockTest($id);
             if ($lock) {
                 $testInfo = GetTestInfo($id);
                 if ($testInfo) {
                     $testInfo['showslow'] = 1;
                     SaveTestInfo($id, $testInfo);
                 }
                 UnlockTest($lock);
             }
         }
     }
 }
 // archive the actual test
 ArchiveTest($id, false);
 // post the test to tsview if requested
 $tsviewdb = GetSetting('tsviewdb');
 if (array_key_exists('tsview_id', $testInfo) && strlen($testInfo['tsview_id']) && strlen($tsviewdb) && is_file('./lib/tsview.inc.php')) {
     require_once './lib/tsview.inc.php';
     TSViewPostResult($testInfo, $id, $testPath, $settings['tsviewdb'], $testInfo['tsview_id']);
 }
 // post the test to statsd if requested
 if (GetSetting('statsdHost') && is_file('./lib/statsd.inc.php')) {
     require_once './lib/statsd.inc.php';
     StatsdPostResult($testInfo, $testPath);
 }
 // Send an email notification if necessary
 $notifyFrom = GetSetting('notifyFrom');
 if ($notifyFrom && strlen($notifyFrom) && is_file("{$testPath}/testinfo.ini")) {
     $host = GetSetting('host');
Пример #4
0
<?php

chdir('..');
include 'common.inc';
require_once 'video/avi2frames.inc.php';
require_once 'archive.inc';
set_time_limit(1200);
ignore_user_abort(true);
header("Content-type: text/plain");
if (ValidateTestId($id)) {
    $start = microtime(true);
    RestoreTest($id);
    ReprocessVideo($id);
    // 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);
    }
    $end = microtime(true);
    $elapsed = number_format($end - $start, 3);
    echo "Done - {$elapsed}s";
} else {
    echo "Invalid Test ID";
}
Пример #5
0
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";
}