Beispiel #1
0
        $total_subtests++;
        if (!$run_func($test)) {
            $total_tests_failed++;
            $total_subtests_failed++;
        }
    }
}
// cleanup
@unlink("config.conf");
@unlink("error.txt");
$nfile = 1;
while (file_exists("config_{$nfile}.conf")) {
    @unlink("config_{$nfile}.conf");
    $nfile++;
}
$nfile = 1;
while (file_exists("error_{$nfile}.txt")) {
    @unlink("error_{$nfile}.txt");
    $nfile++;
}
// summarize
if ($total_tests_failed) {
    printf("\n%d of %d tests and %d of %d subtests failed, %.2f sec elapsed\nTHERE WERE FAILURES!\n", $total_tests_failed, $total_tests, $total_subtests_failed, $total_subtests, MyMicrotime() - $t);
    exit(1);
} else {
    printf("\n%d tests and %d subtests succesful, %.2f sec elapsed\nALL OK\n", $total_tests, $total_subtests, MyMicrotime() - $t);
    exit(0);
}
//
// $Id: ubertest.php 1624 2008-12-25 13:19:55Z shodan $
//
Beispiel #2
0
function sphBenchmark($name, $locals, $force_reindex)
{
    // load config
    $config = new SphinxConfig($locals);
    if (!($config->Load("bench/{$name}.xml") && CheckConfig($config, $name))) {
        return false;
    }
    global $g_locals;
    $g_locals['rt_mode'] = $config->Requires('force-rt');
    // temporary limitations
    assert($config->SubtestCount() == 1);
    assert($config->IsQueryTest());
    // find unused output prefix
    $i = 0;
    for (; file_exists("bench-results/{$name}.{$i}.bin"); $i++) {
    }
    $output = "bench-results/{$name}.{$i}";
    printf("benchmarking: %s\n", $config->Name());
    // grab index names and paths
    $msg = '';
    if (!$config->IsRt()) {
        // enable only in non rt-mode
        $config->EnableCompat098();
    }
    $config->WriteConfig('config.conf', 'all', $msg);
    $indexes = array();
    $text = file_get_contents('config.conf');
    preg_match_all('/index\\s+(\\S+)\\s+{[^}]+path\\s*=\\s*(.*)[^}]+}/m', $text, $matches);
    for ($i = 0; $i < count($matches[1]); $i++) {
        $indexes[$matches[1][$i]] = $matches[2][$i];
    }
    // checksum/reindex as needed
    $hash = null;
    foreach ($indexes as $indexName => $path) {
        printf("index: %s - ", $indexName);
        if ($config->IsRt() && $force_reindex) {
            EraseRtIndex($locals['data'], $path);
        }
        if (!$config->IsRt() && (!is_readable("{$path}.spa") || !is_readable("{$path}.spi") || $force_reindex)) {
            printf("indexing... ");
            $tm = MyMicrotime();
            $result = RunIndexer($error, $indexName);
            $tm = MyMicrotime() - $tm;
            if ($result == 1) {
                printf("\nerror running the indexer:\n%s\n", $error);
                return false;
            } else {
                if ($result == 2) {
                    printf("done in %s, there were warnings:\n%s\n", sphFormatTime($tm), $error);
                } else {
                    printf("done in %s - ", sphFormatTime($tm));
                }
            }
        }
        if (!$config->IsRt()) {
            $hash = array('spi' => md5_file("{$path}.spi"), 'spa' => md5_file("{$path}.spa"));
            printf("%s\n", $hash['spi']);
        } else {
            $hash = array('xml' => md5_file("bench/{$name}.xml"));
            printf("%s\n", $hash['xml']);
        }
    }
    // start searchd
    if (!$locals['skip-searchd']) {
        $result = StartSearchd('config.conf', "{$output}.searchd.txt", 'searchd.pid', $error);
        if ($result == 1) {
            printf("error starting searchd:\n%s\n", $error);
            return false;
        } else {
            if ($result == 2) {
                printf("searchd warning: %s\n", $error);
            }
        }
    }
    // run the benchmark
    $isOK = false;
    if ($config->IsSphinxqlTest()) {
        $isOK = $config->RunQuerySphinxQL($error, true);
    } else {
        $isOK = $config->RunQuery('*', $error, 'warming-up:') && $config->RunQuery('*', $error, 'profiling:');
    }
    if ($isOK) {
        $report = array('results' => array(), 'time' => time(), 'hash' => $hash, 'version' => GetVersion());
        $i = 0;
        $q = null;
        $last = '';
        foreach ($config->Results() as $result) {
            if ($config->IsSphinxqlTest()) {
                if ($result['sphinxql'] == 'show meta') {
                    $report['results'][] = array('total' => $result['rows'][0]['Value'], 'total_found' => $result['rows'][1]['Value'], 'time' => $result['rows'][2]['Value'], 'query' => $last, 'tag' => $last);
                }
                $last = $result['sphinxql'];
            } else {
                if ($result[0] !== $q) {
                    $i = 0;
                    $q = $result[0];
                }
                $query = $config->GetQuery($q);
                $report['results'][] = array('total' => $result[1], 'total_found' => $result[2], 'time' => $result[3], 'query' => $query['query'][$i++], 'tag' => $query['tag']);
            }
        }
        file_put_contents("{$output}.bin", serialize($report));
        printf("results saved to: {$output}.bin\n");
    } else {
        printf("\nfailed to run queries:\n%s\n", $error);
    }
    // shutdown
    StopSearchd('config.conf', 'searchd.pid');
    // all good
    return $output;
}