add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / benchmark / src / java / org / apache / lucene / benchmark / byTask / tasks / RepSumByPrefTask.java
1 package org.apache.lucene.benchmark.byTask.tasks;
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 org.apache.lucene.benchmark.byTask.PerfRunData;
21 import org.apache.lucene.benchmark.byTask.stats.Report;
22 import org.apache.lucene.benchmark.byTask.stats.TaskStats;
23
24 import java.util.LinkedHashMap;
25 import java.util.List;
26
27 /**
28  * Report by-name-prefix statistics aggregated by name.
29  * <br>Other side effects: None.
30  */
31 public class RepSumByPrefTask extends ReportTask {
32
33   public RepSumByPrefTask(PerfRunData runData) {
34     super(runData);
35   }
36
37   protected String prefix;
38
39   @Override
40   public int doLogic() throws Exception {
41     Report rp = reportSumByPrefix(getRunData().getPoints().taskStats());
42     
43     System.out.println();
44     System.out.println("------------> Report Sum By Prefix ("+prefix+") ("+
45         rp.getSize()+" about "+rp.getReported()+" out of "+rp.getOutOf()+")");
46     System.out.println(rp.getText());
47     System.out.println();
48
49     return 0;
50   }
51
52   protected Report reportSumByPrefix (List<TaskStats> taskStats) {
53     // aggregate by task name
54     int reported = 0;
55     LinkedHashMap<String,TaskStats> p2 = new LinkedHashMap<String,TaskStats>();
56     for (final TaskStats stat1 : taskStats) {
57       if (stat1.getElapsed()>=0 && stat1.getTask().getName().startsWith(prefix)) { // only ended tasks with proper name
58         reported++;
59         String name = stat1.getTask().getName();
60         TaskStats stat2 = p2.get(name);
61         if (stat2 == null) {
62           try {
63             stat2 = (TaskStats) stat1.clone();
64           } catch (CloneNotSupportedException e) {
65             throw new RuntimeException(e);
66           }
67           p2.put(name,stat2);
68         } else {
69           stat2.add(stat1);
70         }
71       }
72     }
73     // now generate report from secondary list p2    
74     return genPartialReport(reported, p2, taskStats.size());
75   }
76   
77
78   public void setPrefix(String prefix) {
79     this.prefix = prefix;
80   }
81
82   /* (non-Javadoc)
83    * @see PerfTask#toString()
84    */
85   @Override
86   public String toString() {
87     return super.toString()+" "+prefix;
88   }
89
90 }