01: package org.apache.lucene.benchmark.byTask.stats;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.lucene.benchmark.byTask.tasks.PerfTask;
24: import org.apache.lucene.benchmark.byTask.utils.Config;
25:
26: /**
27: * Test run data points collected as the test proceeds.
28: */
29: public class Points {
30:
31: private Config config;
32:
33: // stat points ordered by their start time.
34: // for now we collect points as TaskStats objects.
35: // later might optimize to collect only native data.
36: private ArrayList points = new ArrayList();
37:
38: private int nextTaskRunNum = 0;
39:
40: /**
41: * Create a Points statistics object.
42: */
43: public Points(Config config) {
44: this .config = config;
45: }
46:
47: /**
48: * Return the current task stats.
49: * the actual task stats are returned, so caller should not modify this task stats.
50: * @return current {@link TaskStats}.
51: */
52: public List taskStats() {
53: return points;
54: }
55:
56: /**
57: * Mark that a task is starting.
58: * Create a task stats for it and store it as a point.
59: * @param task the starting task.
60: * @return the new task stats created for the starting task.
61: */
62: public synchronized TaskStats markTaskStart(PerfTask task, int round) {
63: TaskStats stats = new TaskStats(task, nextTaskRunNum(), round);
64: points.add(stats);
65: return stats;
66: }
67:
68: // return next task num
69: private synchronized int nextTaskRunNum() {
70: return nextTaskRunNum++;
71: }
72:
73: /**
74: * mark the end of a task
75: */
76: public synchronized void markTaskEnd(TaskStats stats, int count) {
77: int numParallelTasks = nextTaskRunNum - 1
78: - stats.getTaskRunNum();
79: // note: if the stats were cleared, might be that this stats object is
80: // no longer in points, but this is just ok.
81: stats.markEnd(numParallelTasks, count);
82: }
83:
84: /**
85: * Clear all data, prepare for more tests.
86: */
87: public void clearData() {
88: points.clear();
89: }
90:
91: }
|