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