001: package org.apache.lucene.benchmark.byTask.stats;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
021:
022: /**
023: * Statistics for a task run.
024: * <br>The same task can run more than once, but, if that task records statistics,
025: * each run would create its own TaskStats.
026: */
027: public class TaskStats implements Cloneable {
028:
029: /** task for which data was collected */
030: private PerfTask task;
031:
032: /** round in which task run started */
033: private int round;
034:
035: /** task start time */
036: private long start;
037:
038: /** task elapsed time. elapsed >= 0 indicates run completion! */
039: private long elapsed = -1;
040:
041: /** max tot mem during task */
042: private long maxTotMem;
043:
044: /** max used mem during task */
045: private long maxUsedMem;
046:
047: /** serial run number of this task run in the perf run */
048: private int taskRunNum;
049:
050: /** number of other tasks that started to run while this task was still running */
051: private int numParallelTasks;
052:
053: /** number of work items done by this task.
054: * For indexing that can be number of docs added.
055: * For warming that can be number of scanned items, etc.
056: * For repeating tasks, this is a sum over repetitions.
057: */
058: private int count;
059:
060: /** Number of similar tasks aggregated into this record.
061: * Used when summing up on few runs/instances of similar tasks.
062: */
063: private int numRuns = 1;
064:
065: /**
066: * Create a run data for a task that is starting now.
067: * To be called from Points.
068: */
069: TaskStats(PerfTask task, int taskRunNum, int round) {
070: this .task = task;
071: this .taskRunNum = taskRunNum;
072: this .round = round;
073: maxTotMem = Runtime.getRuntime().totalMemory();
074: maxUsedMem = maxTotMem - Runtime.getRuntime().freeMemory();
075: start = System.currentTimeMillis();
076: }
077:
078: /**
079: * mark the end of a task
080: */
081: void markEnd(int numParallelTasks, int count) {
082: elapsed = System.currentTimeMillis() - start;
083: long totMem = Runtime.getRuntime().totalMemory();
084: if (totMem > maxTotMem) {
085: maxTotMem = totMem;
086: }
087: long usedMem = totMem - Runtime.getRuntime().freeMemory();
088: if (usedMem > maxUsedMem) {
089: maxUsedMem = usedMem;
090: }
091: this .numParallelTasks = numParallelTasks;
092: this .count = count;
093: }
094:
095: /**
096: * @return the taskRunNum.
097: */
098: public int getTaskRunNum() {
099: return taskRunNum;
100: }
101:
102: /* (non-Javadoc)
103: * @see java.lang.Object#toString()
104: */
105: public String toString() {
106: StringBuffer res = new StringBuffer(task.getName());
107: res.append(" ");
108: res.append(count);
109: res.append(" ");
110: res.append(elapsed);
111: return res.toString();
112: }
113:
114: /**
115: * @return Returns the count.
116: */
117: public int getCount() {
118: return count;
119: }
120:
121: /**
122: * @return elapsed time.
123: */
124: public long getElapsed() {
125: return elapsed;
126: }
127:
128: /**
129: * @return Returns the maxTotMem.
130: */
131: public long getMaxTotMem() {
132: return maxTotMem;
133: }
134:
135: /**
136: * @return Returns the maxUsedMem.
137: */
138: public long getMaxUsedMem() {
139: return maxUsedMem;
140: }
141:
142: /**
143: * @return Returns the numParallelTasks.
144: */
145: public int getNumParallelTasks() {
146: return numParallelTasks;
147: }
148:
149: /**
150: * @return Returns the task.
151: */
152: public PerfTask getTask() {
153: return task;
154: }
155:
156: /**
157: * @return Returns the numRuns.
158: */
159: public int getNumRuns() {
160: return numRuns;
161: }
162:
163: /**
164: * Add data from another stat, for aggregation
165: * @param stat2 the added stat data.
166: */
167: public void add(TaskStats stat2) {
168: numRuns += stat2.getNumRuns();
169: elapsed += stat2.getElapsed();
170: maxTotMem += stat2.getMaxTotMem();
171: maxUsedMem += stat2.getMaxUsedMem();
172: count += stat2.getCount();
173: if (round != stat2.round) {
174: round = -1; // no meaning if agregating tasks of different ruond.
175: }
176: }
177:
178: /* (non-Javadoc)
179: * @see java.lang.Object#clone()
180: */
181: public Object clone() throws CloneNotSupportedException {
182: return super .clone();
183: }
184:
185: /**
186: * @return the round number.
187: */
188: public int getRound() {
189: return round;
190: }
191:
192: }
|