Esempio n. 1
1
function main()
{
    $program_start_time = microtime(true);
    $arguments = validate_arguments($_GET, array('platform' => 'int', 'metric' => 'int', 'testGroup' => 'int?', 'startTime' => 'int?', 'endTime' => 'int?'));
    $platform_id = $arguments['platform'];
    $metric_id = $arguments['metric'];
    $start_time = $arguments['startTime'];
    $end_time = $arguments['endTime'];
    if (!!$start_time != !!$end_time) {
        exit_with_error('InvalidTimeRange', array('startTime' => $start_time, 'endTime' => $end_time));
    }
    $db = new Database();
    if (!$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    $fetcher = new MeasurementSetFetcher($db);
    if (!$fetcher->fetch_config_list($platform_id, $metric_id)) {
        exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id));
    }
    $cluster_count = 0;
    while (!$fetcher->at_end()) {
        $content = $fetcher->fetch_next_cluster();
        $cluster_count++;
        if ($fetcher->at_end()) {
            $cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json";
            $content['clusterCount'] = $cluster_count;
            $content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000;
        } else {
            $cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json";
        }
        $json = success_json($content);
        generate_data_file($cache_filename, $json);
    }
    echo $json;
}
Esempio n. 2
0
function main($path)
{
    if (count($path) != 1) {
        exit_with_error('InvalidRequest');
    }
    $parts = explode('-', $path[0]);
    if (count($parts) != 2) {
        exit_with_error('InvalidRequest');
    }
    $db = new Database();
    if (!$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    $platform_id = intval($parts[0]);
    $metric_id = intval($parts[1]);
    $config_rows = $db->query_and_fetch_all('SELECT *
        FROM test_configurations WHERE config_metric = $1 AND config_platform = $2', array($metric_id, $platform_id));
    if (!$config_rows) {
        exit_with_error('ConfigurationNotFound');
    }
    $test_group_id = array_get($_GET, 'testGroup');
    $should_cache = array_get($_GET, 'cache');
    if ($test_group_id) {
        $test_group_id = intval($test_group_id);
    } else {
        if ($should_cache) {
            // Only v1 UI needs caching.
            $maxage = config('jsonCacheMaxAge');
            header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT');
            header("Cache-Control: maxage={$maxage}");
        }
    }
    $generator = new RunsGenerator($config_rows);
    foreach ($config_rows as $config) {
        if ($test_group_id) {
            $raw_runs = fetch_runs_for_config_and_test_group($db, $config, $test_group_id);
        } else {
            $raw_runs = fetch_runs_for_config($db, $config);
        }
        $generator->add_runs($config['config_type'], $raw_runs);
    }
    $content = success_json($generator->results());
    if (!$test_group_id) {
        generate_data_file("{$platform_id}-{$metric_id}.json", $content);
    }
    echo $content;
}
function main()
{
    $program_start_time = microtime(true);
    $arguments = validate_arguments($_GET, array('platform' => 'int?', 'metric' => 'int?', 'analysisTask' => 'int?'));
    $platform_id = $arguments['platform'];
    $metric_id = $arguments['metric'];
    $task_id = $arguments['analysisTask'];
    if (!($platform_id && $metric_id && !$task_id || $task_id && !$platform_id && !$metric_id)) {
        exit_with_error('AmbiguousRequest');
    }
    $db = new Database();
    if (!$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    if ($task_id) {
        $fetcher = new AnalysisResultsFetcher($db, $task_id);
        exit_with_success($fetcher->fetch());
    }
    $fetcher = new MeasurementSetFetcher($db);
    if (!$fetcher->fetch_config_list($platform_id, $metric_id)) {
        exit_with_error('ConfigurationNotFound', array('platform' => $platform_id, 'metric' => $metric_id));
    }
    if ($fetcher->at_end()) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
        exit(404);
    }
    $cluster_count = 0;
    while (!$fetcher->at_end()) {
        $content = $fetcher->fetch_next_cluster();
        $cluster_count++;
        if ($fetcher->at_end()) {
            $cache_filename = "measurement-set-{$platform_id}-{$metric_id}.json";
            $content['clusterCount'] = $cluster_count;
            $content['elapsedTime'] = (microtime(true) - $program_start_time) * 1000;
        } else {
            $cache_filename = "measurement-set-{$platform_id}-{$metric_id}-{$content['endTime']}.json";
        }
        $json = success_json($content);
        generate_data_file($cache_filename, $json);
    }
    echo $json;
}
Esempio n. 4
0
 function store()
 {
     return generate_data_file('manifest.json', json_encode($this->manifest));
 }