1 package org.apache.lucene.benchmark.byTask.tasks;
3 import java.util.LinkedHashMap;
5 import org.apache.lucene.benchmark.byTask.PerfRunData;
6 import org.apache.lucene.benchmark.byTask.stats.Report;
7 import org.apache.lucene.benchmark.byTask.stats.TaskStats;
8 import org.apache.lucene.benchmark.byTask.utils.Format;
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed with
13 * this work for additional information regarding copyright ownership.
14 * The ASF licenses this file to You under the Apache License, Version 2.0
15 * (the "License"); you may not use this file except in compliance with
16 * the License. You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
28 * Report (abstract) task - all report tasks extend this task.
30 public abstract class ReportTask extends PerfTask {
32 public ReportTask(PerfRunData runData) {
37 * @see PerfTask#shouldNeverLogAtStart()
40 protected boolean shouldNeverLogAtStart() {
45 * @see PerfTask#shouldNotRecordStats()
48 protected boolean shouldNotRecordStats() {
53 * From here start the code used to generate the reports.
54 * Subclasses would use this part to generate reports.
57 protected static final String newline = System.getProperty("line.separator");
60 * Get a textual summary of the benchmark results, average from all test runs.
62 protected static final String OP = "Operation ";
63 protected static final String ROUND = " round";
64 protected static final String RUNCNT = " runCnt";
65 protected static final String RECCNT = " recsPerRun";
66 protected static final String RECSEC = " rec/s";
67 protected static final String ELAPSED = " elapsedSec";
68 protected static final String USEDMEM = " avgUsedMem";
69 protected static final String TOTMEM = " avgTotalMem";
70 protected static final String COLS[] = {
80 * Compute a title line for a report table
81 * @param longestOp size of longest op name in the table
82 * @return the table title line.
84 protected String tableTitle (String longestOp) {
85 StringBuilder sb = new StringBuilder();
86 sb.append(Format.format(OP,longestOp));
88 sb.append(getRunData().getConfig().getColsNamesForValsByRound());
89 for (int i = 0; i < COLS.length; i++) {
96 * find the longest op name out of completed tasks.
97 * @param taskStats completed tasks to be considered.
98 * @return the longest op name out of completed tasks.
100 protected String longestOp(Iterable<TaskStats> taskStats) {
102 for (final TaskStats stat : taskStats) {
103 if (stat.getElapsed()>=0) { // consider only tasks that ended
104 String name = stat.getTask().getName();
105 if (name.length() > longest.length()) {
114 * Compute a report line for the given task stat.
115 * @param longestOp size of longest op name in the table.
116 * @param stat task stat to be printed.
117 * @return the report line.
119 protected String taskReportLine(String longestOp, TaskStats stat) {
120 PerfTask task = stat.getTask();
121 StringBuilder sb = new StringBuilder();
122 sb.append(Format.format(task.getName(), longestOp));
123 String round = (stat.getRound()>=0 ? ""+stat.getRound() : "-");
124 sb.append(Format.formatPaddLeft(round, ROUND));
125 sb.append(getRunData().getConfig().getColsValuesForValsByRound(stat.getRound()));
126 sb.append(Format.format(stat.getNumRuns(), RUNCNT));
127 sb.append(Format.format(stat.getCount() / stat.getNumRuns(), RECCNT));
128 long elapsed = (stat.getElapsed()>0 ? stat.getElapsed() : 1); // assume at least 1ms
129 sb.append(Format.format(2, (float) (stat.getCount() * 1000.0 / elapsed), RECSEC));
130 sb.append(Format.format(2, (float) stat.getElapsed() / 1000, ELAPSED));
131 sb.append(Format.format(0, (float) stat.getMaxUsedMem() / stat.getNumRuns(), USEDMEM));
132 sb.append(Format.format(0, (float) stat.getMaxTotMem() / stat.getNumRuns(), TOTMEM));
133 return sb.toString();
136 protected Report genPartialReport(int reported, LinkedHashMap<String,TaskStats> partOfTasks, int totalSize) {
137 String longetOp = longestOp(partOfTasks.values());
138 boolean first = true;
139 StringBuilder sb = new StringBuilder();
140 sb.append(tableTitle(longetOp));
143 for (final TaskStats stat : partOfTasks.values()) {
148 String line = taskReportLine(longetOp,stat);
150 if (partOfTasks.size()>2 && lineNum%2==0) {
151 line = line.replaceAll(" "," - ");
154 int[] byTime = stat.getCountsByTime();
155 if (byTime != null) {
158 for(int i=byTime.length-1;i>=0;i--) {
159 if (byTime[i] != 0) {
165 sb.append(" by time:");
166 for(int i=0;i<end;i++) {
167 sb.append(' ').append(byTime[i]);
173 String reptxt = (reported==0 ? "No Matching Entries Were Found!" : sb.toString());
174 return new Report(reptxt,partOfTasks.size(),reported,totalSize);