Search in sources :

Example 1 with TaskStats

use of org.apache.lucene.benchmark.byTask.stats.TaskStats in project lucene-solr by apache.

the class TestPerfTasksLogic method testReadTokens.

/**
   * Test ReadTokensTask
   */
public void testReadTokens() throws Exception {
    // We will call ReadTokens on this many docs
    final int NUM_DOCS = 20;
    // Read tokens from first NUM_DOCS docs from Reuters and
    // then build index from the same docs
    String[] algLines1 = { "# ----- properties ", "analyzer=org.apache.lucene.analysis.core.WhitespaceAnalyzer", "content.source=org.apache.lucene.benchmark.byTask.feeds.LineDocSource", "docs.file=" + getReuters20LinesFile(), "# ----- alg ", "{ReadTokens}: " + NUM_DOCS, "ResetSystemErase", "CreateIndex", "{AddDoc}: " + NUM_DOCS, "CloseIndex" };
    // Run algo
    Benchmark benchmark = execBenchmark(algLines1);
    List<TaskStats> stats = benchmark.getRunData().getPoints().taskStats();
    // Count how many tokens all ReadTokens saw
    int totalTokenCount1 = 0;
    for (final TaskStats stat : stats) {
        if (stat.getTask().getName().equals("ReadTokens")) {
            totalTokenCount1 += stat.getCount();
        }
    }
    // Separately count how many tokens are actually in the index:
    IndexReader reader = DirectoryReader.open(benchmark.getRunData().getDirectory());
    assertEquals(NUM_DOCS, reader.numDocs());
    int totalTokenCount2 = 0;
    Fields fields = MultiFields.getFields(reader);
    for (String fieldName : fields) {
        if (fieldName.equals(DocMaker.ID_FIELD) || fieldName.equals(DocMaker.DATE_MSEC_FIELD) || fieldName.equals(DocMaker.TIME_SEC_FIELD)) {
            continue;
        }
        Terms terms = fields.terms(fieldName);
        if (terms == null) {
            continue;
        }
        TermsEnum termsEnum = terms.iterator();
        PostingsEnum docs = null;
        while (termsEnum.next() != null) {
            docs = TestUtil.docs(random(), termsEnum, docs, PostingsEnum.FREQS);
            while (docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
                totalTokenCount2 += docs.freq();
            }
        }
    }
    reader.close();
    // Make sure they are the same
    assertEquals(totalTokenCount1, totalTokenCount2);
}
Also used : Fields(org.apache.lucene.index.Fields) MultiFields(org.apache.lucene.index.MultiFields) IndexReader(org.apache.lucene.index.IndexReader) Terms(org.apache.lucene.index.Terms) TaskStats(org.apache.lucene.benchmark.byTask.stats.TaskStats) PostingsEnum(org.apache.lucene.index.PostingsEnum) TermsEnum(org.apache.lucene.index.TermsEnum)

Example 2 with TaskStats

use of org.apache.lucene.benchmark.byTask.stats.TaskStats in project lucene-solr by apache.

the class TestPerfTasksLogic method doTestDisableCounting.

private void doTestDisableCounting(boolean disable) throws Exception {
    // 1. alg definition (required in every "logic" test)
    String[] algLines = disableCountingLines(disable);
    // 2. execute the algorithm  (required in every "logic" test)
    Benchmark benchmark = execBenchmark(algLines);
    // 3. test counters
    int n = disable ? 0 : 1;
    int nChecked = 0;
    for (final TaskStats stats : benchmark.getRunData().getPoints().taskStats()) {
        String taskName = stats.getTask().getName();
        if (taskName.equals("Rounds")) {
            assertEquals("Wrong total count!", 20 + 2 * n, stats.getCount());
            nChecked++;
        } else if (taskName.equals("CreateIndex")) {
            assertEquals("Wrong count for CreateIndex!", n, stats.getCount());
            nChecked++;
        } else if (taskName.equals("CloseIndex")) {
            assertEquals("Wrong count for CloseIndex!", n, stats.getCount());
            nChecked++;
        }
    }
    assertEquals("Missing some tasks to check!", 3, nChecked);
}
Also used : TaskStats(org.apache.lucene.benchmark.byTask.stats.TaskStats)

Example 3 with TaskStats

use of org.apache.lucene.benchmark.byTask.stats.TaskStats in project lucene-solr by apache.

the class PerfTask method runAndMaybeStats.

/**
   * Run the task, record statistics.
   * @return number of work items done by this task.
   */
public final int runAndMaybeStats(boolean reportStats) throws Exception {
    if (!reportStats || shouldNotRecordStats()) {
        setup();
        int count = doLogic();
        count = disableCounting ? 0 : count;
        tearDown();
        return count;
    }
    if (reportStats && depth <= maxDepthLogStart && !shouldNeverLogAtStart()) {
        System.out.println("------------> starting task: " + getName());
    }
    setup();
    Points pnts = runData.getPoints();
    TaskStats ts = pnts.markTaskStart(this, runData.getConfig().getRoundNumber());
    int count = doLogic();
    count = disableCounting ? 0 : count;
    pnts.markTaskEnd(ts, count);
    tearDown();
    return count;
}
Also used : Points(org.apache.lucene.benchmark.byTask.stats.Points) TaskStats(org.apache.lucene.benchmark.byTask.stats.TaskStats)

Example 4 with TaskStats

use of org.apache.lucene.benchmark.byTask.stats.TaskStats in project lucene-solr by apache.

the class RepSelectByPrefTask method reportSelectByPrefix.

protected Report reportSelectByPrefix(List<TaskStats> taskStats) {
    String longestOp = longestOp(taskStats);
    boolean first = true;
    StringBuilder sb = new StringBuilder();
    sb.append(tableTitle(longestOp));
    sb.append(newline);
    int reported = 0;
    for (final TaskStats stat : taskStats) {
        if (stat.getElapsed() >= 0 && stat.getTask().getName().startsWith(prefix)) {
            // only ended tasks with proper name
            reported++;
            if (!first) {
                sb.append(newline);
            }
            first = false;
            String line = taskReportLine(longestOp, stat);
            if (taskStats.size() > 2 && reported % 2 == 0) {
                line = line.replaceAll("   ", " - ");
            }
            sb.append(line);
        }
    }
    String reptxt = (reported == 0 ? "No Matching Entries Were Found!" : sb.toString());
    return new Report(reptxt, reported, reported, taskStats.size());
}
Also used : Report(org.apache.lucene.benchmark.byTask.stats.Report) TaskStats(org.apache.lucene.benchmark.byTask.stats.TaskStats)

Example 5 with TaskStats

use of org.apache.lucene.benchmark.byTask.stats.TaskStats in project lucene-solr by apache.

the class RepSumByNameRoundTask method reportSumByNameRound.

/**
   * Report statistics as a string, aggregate for tasks named the same, and from the same round.
   * @return the report
   */
protected Report reportSumByNameRound(List<TaskStats> taskStats) {
    // aggregate by task name and round
    LinkedHashMap<String, TaskStats> p2 = new LinkedHashMap<>();
    int reported = 0;
    for (final TaskStats stat1 : taskStats) {
        if (stat1.getElapsed() >= 0) {
            // consider only tasks that ended
            reported++;
            String name = stat1.getTask().getName();
            // group by round
            String rname = stat1.getRound() + "." + name;
            TaskStats stat2 = p2.get(rname);
            if (stat2 == null) {
                try {
                    stat2 = stat1.clone();
                } catch (CloneNotSupportedException e) {
                    throw new RuntimeException(e);
                }
                p2.put(rname, stat2);
            } else {
                stat2.add(stat1);
            }
        }
    }
    // now generate report from secondary list p2    
    return genPartialReport(reported, p2, taskStats.size());
}
Also used : TaskStats(org.apache.lucene.benchmark.byTask.stats.TaskStats) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TaskStats (org.apache.lucene.benchmark.byTask.stats.TaskStats)11 LinkedHashMap (java.util.LinkedHashMap)4 Report (org.apache.lucene.benchmark.byTask.stats.Report)3 Points (org.apache.lucene.benchmark.byTask.stats.Points)1 Fields (org.apache.lucene.index.Fields)1 IndexReader (org.apache.lucene.index.IndexReader)1 MultiFields (org.apache.lucene.index.MultiFields)1 PostingsEnum (org.apache.lucene.index.PostingsEnum)1 Terms (org.apache.lucene.index.Terms)1 TermsEnum (org.apache.lucene.index.TermsEnum)1