add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / java / org / apache / lucene / benchmark / byTask / stats / Points.java
1 package org.apache.lucene.benchmark.byTask.stats;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * 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 /**
28  * Test run data points collected as the test proceeds.
29  */
30 public class Points {
31
32   // stat points ordered by their start time. 
33   // for now we collect points as TaskStats objects.
34   // later might optimize to collect only native data.
35   private ArrayList<TaskStats> points = new ArrayList<TaskStats>();
36
37   private int nextTaskRunNum = 0;
38
39   private TaskStats currentStats;
40
41   /**
42    * Create a Points statistics object. 
43    */
44   public Points (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> 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     this.currentStats = stats;
65     points.add(stats);
66     return stats;
67   }
68
69   public TaskStats getCurrentStats() {
70     return currentStats;
71   }
72   
73   // return next task num
74   private synchronized int nextTaskRunNum() {
75     return nextTaskRunNum++;
76   }
77   
78   /**
79    * mark the end of a task
80    */
81   public synchronized void markTaskEnd (TaskStats stats, int count) {
82     int numParallelTasks = nextTaskRunNum - 1 - stats.getTaskRunNum();
83     // note: if the stats were cleared, might be that this stats object is 
84     // no longer in points, but this is just ok.
85     stats.markEnd(numParallelTasks, count);
86   }
87
88   /**
89    * Clear all data, prepare for more tests.
90    */
91   public void clearData() {
92     points.clear();
93   }
94
95 }