start of new file
[IRC.git] / Robust / src / Benchmarks / Prefetch / LUFact / java / JGFInstrumentor.java
1 /**************************************************************************
2  *                                                                         *
3  *         Java Grande Forum Benchmark Suite - Thread Version 1.0          *
4  *                                                                         *
5  *                            produced by                                  *
6  *                                                                         *
7  *                  Java Grande Benchmarking Project                       *
8  *                                                                         *
9  *                                at                                       *
10  *                                                                         *
11  *                Edinburgh Parallel Computing Centre                      *
12  *                                                                         * 
13  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
14  *                                                                         *
15  *                                                                         *
16  *      This version copyright (c) The University of Edinburgh, 1999.      *
17  *                         All rights reserved.                            *
18  *                                                                         *
19  **************************************************************************/
20 import java.util.*;
21 public class JGFInstrumentor{
22
23   protected HashMap timers;
24   protected HashMap data; 
25
26   public JGFInstrumentor() {
27     timers = new HashMap();
28     data = new HashMap(); 
29   }
30
31   public static void addTimer (String name, HashMap timers){
32
33     if (timers.containsKey(name)) {
34       System.out.println("JGFInstrumentor.addTimer: warning -  timer " + name + 
35           " already exists");
36     }
37     else {
38       timers.put(name, new JGFTimer(name));
39     }
40   }
41
42   public static void addTimer (String name, String opname, HashMap timers){
43
44     if (timers.containsKey(name)) {
45       System.out.println("JGFInstrumentor.addTimer: warning -  timer " + name + 
46           " already exists");
47     }
48     else {
49       timers.put(name, new JGFTimer(name,opname));
50     }
51
52   }
53
54   public static void addTimer (String name, String opname, int size, HashMap timers){
55
56     if (timers.containsKey(name)) {
57       System.out.println("JGFInstrumentor.addTimer: warning -  timer " + name +
58           " already exists");
59     }
60     else {
61       timers.put(name, new JGFTimer(name,opname,size));
62     }
63
64   }
65
66   public static void startTimer(String name, HashMap timers){
67     if (timers.containsKey(name)) {
68       ((JGFTimer) timers.get(name)).start();
69     }
70     else {
71       System.out.println("JGFInstrumentor.startTimer: failed -  timer " + name + 
72           " does not exist");
73     }
74
75   }
76
77   public static void stopTimer(String name, HashMap timers){
78     if (timers.containsKey(name)) {
79       ((JGFTimer) timers.get(name)).stop();
80     }
81     else {
82       System.out.println("JGFInstrumentor.stopTimer: failed -  timer " + name + 
83           " does not exist");
84     }
85   }
86
87   public static void addOpsToTimer(String name, double count, HashMap timers){
88     if (timers.containsKey(name)) {
89       ((JGFTimer) timers.get(name)).addops(count);
90     }
91     else {
92       System.out.println("JGFInstrumentor.addOpsToTimer: failed -  timer " + name + 
93           " does not exist");
94     }
95   }  
96
97   public static void addTimeToTimer(String name, double added_time, HashMap timers){
98     if (timers.containsKey(name)) {
99       ((JGFTimer) timers.get(name)).addtime(added_time);
100     }
101     else {
102       System.out.println("JGFInstrumentor.addTimeToTimer: failed -  timer " + name +
103           " does not exist");
104     }
105
106
107
108   }
109
110   public static double readTimer(String name, HashMap timers){
111     double time; 
112     if (timers.containsKey(name)) {
113       time = ((JGFTimer) timers.get(name)).time;
114     }
115     else {
116       System.out.println("JGFInstrumentor.readTimer: failed -  timer " + name + 
117           " does not exist");
118       time = 0.0; 
119     }
120     return time; 
121   }  
122
123   public static void resetTimer(String name, HashMap timers){
124     if (timers.containsKey(name)) {
125       ((JGFTimer) timers.get(name)).reset();
126     }
127     else {
128       System.out.println("JGFInstrumentor.resetTimer: failed -  timer " + name +
129           " does not exist");
130     }
131   }
132
133   public static void printTimer(String name, HashMap timers){
134     if (timers.containsKey(name)) {
135       ((JGFTimer) timers.get(name)).print();
136     }
137     else {
138       System.out.println("JGFInstrumentor.printTimer: failed -  timer " + name +
139           " does not exist");
140     }
141   }
142
143   public static void printperfTimer(String name, HashMap timers){
144     if (timers.containsKey(name)) {
145       ((JGFTimer) timers.get(name)).printperf();
146     }
147     else {
148       System.out.println("JGFInstrumentor.printTimer: failed -  timer " + name +
149           " does not exist");
150     }
151   }
152
153   public static void storeData(String name, Object obj, HashMap data){
154     data.put(name,obj); 
155   }
156
157   public static void retrieveData(String name, Object obj, HashMap data){
158     obj = data.get(name); 
159   }
160
161   public static void printHeader(int section, int size,int nthreads) {
162
163     String header, base; 
164
165     header = "";
166     base = "Java Grande Forum Thread Benchmark Suite - Version 1.0 - Section "; 
167
168     if (section == 1)
169     {
170       header = base + "1";
171     }
172     else if (section == 2)
173     {
174       if (size == 0)
175         header = base + "2 - Size A";
176       else if (size == 1)
177         header = base + "2 - Size B";
178       else if (size == 2)
179         header = base + "2 - Size C";
180     }
181     else if (section == 3)
182     {
183       if (size == 0)
184         header = base + "3 - Size A";
185       else if (size == 1)
186         header = base + "3 - Size B";
187     }
188
189     System.out.println(header); 
190
191     if (nthreads == 1) {
192       System.out.println("Executing on " + nthreads + " thread");
193     }
194     else {
195       System.out.println("Executing on " + nthreads + " threads");
196     }
197
198     System.out.println("");
199   } 
200 }