1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.counters; |
20 | |
|
21 | |
import org.apache.hadoop.mapreduce.Mapper.Context; |
22 | |
|
23 | |
import com.google.common.collect.Iterators; |
24 | |
import com.google.common.collect.Maps; |
25 | |
|
26 | |
import java.util.ArrayList; |
27 | |
import java.util.Arrays; |
28 | |
import java.util.Iterator; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class GiraphTimers extends HadoopCountersBase { |
36 | |
|
37 | |
public static final String GROUP_NAME = "Giraph Timers"; |
38 | |
|
39 | |
public static final String SETUP_MS_NAME = "Setup (ms)"; |
40 | |
|
41 | |
public static final String TOTAL_MS_NAME = "Total (ms)"; |
42 | |
|
43 | |
public static final String SHUTDOWN_MS_NAME = "Shutdown (ms)"; |
44 | |
|
45 | |
public static final String INITIALIZE_MS_NAME = "Initialize (ms)"; |
46 | |
|
47 | |
|
48 | |
private static GiraphTimers INSTANCE; |
49 | |
|
50 | |
|
51 | |
private static final int SETUP_MS = 0; |
52 | |
|
53 | |
private static final int TOTAL_MS = 1; |
54 | |
|
55 | |
private static final int SHUTDOWN_MS = 2; |
56 | |
|
57 | |
private static final int INITIALIZE_MS = 3; |
58 | |
|
59 | |
private static final int NUM_COUNTERS = 4; |
60 | |
|
61 | |
|
62 | |
private final Map<Long, GiraphHadoopCounter> superstepMsec; |
63 | |
|
64 | |
|
65 | |
private final GiraphHadoopCounter[] jobCounters; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
private GiraphTimers(Context context) { |
73 | 0 | super(context, GROUP_NAME); |
74 | 0 | jobCounters = new GiraphHadoopCounter[NUM_COUNTERS]; |
75 | 0 | jobCounters[SETUP_MS] = getCounter(SETUP_MS_NAME); |
76 | 0 | jobCounters[TOTAL_MS] = getCounter(TOTAL_MS_NAME); |
77 | 0 | jobCounters[SHUTDOWN_MS] = getCounter(SHUTDOWN_MS_NAME); |
78 | 0 | jobCounters[INITIALIZE_MS] = getCounter(INITIALIZE_MS_NAME); |
79 | 0 | superstepMsec = Maps.newHashMap(); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public static void init(Context context) { |
88 | 0 | INSTANCE = new GiraphTimers(context); |
89 | 0 | } |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public static GiraphTimers getInstance() { |
97 | 0 | return INSTANCE; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public GiraphHadoopCounter getSetupMs() { |
106 | 0 | return jobCounters[SETUP_MS]; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public GiraphHadoopCounter getSuperstepMs(long superstep, |
117 | |
String computationName) { |
118 | 0 | GiraphHadoopCounter counter = superstepMsec.get(superstep); |
119 | 0 | if (counter == null) { |
120 | |
String counterPrefix; |
121 | 0 | if (superstep == -1) { |
122 | 0 | counterPrefix = "Input superstep"; |
123 | |
} else { |
124 | 0 | counterPrefix = "Superstep " + superstep + |
125 | |
(computationName == null ? "" : " " + computationName); |
126 | |
} |
127 | 0 | counter = getCounter(counterPrefix + " (ms)"); |
128 | 0 | superstepMsec.put(superstep, counter); |
129 | |
} |
130 | 0 | return counter; |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public GiraphHadoopCounter getTotalMs() { |
140 | 0 | return jobCounters[TOTAL_MS]; |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public GiraphHadoopCounter getShutdownMs() { |
149 | 0 | return jobCounters[SHUTDOWN_MS]; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public GiraphHadoopCounter getInitializeMs() { |
159 | 0 | return jobCounters[INITIALIZE_MS]; |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public Map<Long, GiraphHadoopCounter> superstepCounters() { |
168 | 0 | return superstepMsec; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
public Iterable<GiraphHadoopCounter> jobCounters() { |
177 | 0 | return Arrays.asList(jobCounters); |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public Iterator<GiraphHadoopCounter> iterator() { |
182 | 0 | return Iterators.concat(jobCounters().iterator(), |
183 | 0 | superstepCounters().values().iterator()); |
184 | |
} |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public List<CustomCounter> getCounterList(long superstep) { |
194 | 0 | List<CustomCounter> countersList = new ArrayList<>(); |
195 | 0 | for (GiraphHadoopCounter counter: jobCounters) { |
196 | 0 | CustomCounter customCounter = new CustomCounter( |
197 | 0 | GROUP_NAME, counter.getName(), |
198 | 0 | CustomCounter.Aggregation.SUM, counter.getValue()); |
199 | 0 | countersList.add(customCounter); |
200 | |
} |
201 | 0 | GiraphHadoopCounter giraphHadoopCounter = superstepMsec.get(superstep); |
202 | 0 | if (giraphHadoopCounter != null) { |
203 | 0 | CustomCounter customCounter = new CustomCounter( |
204 | 0 | GROUP_NAME, giraphHadoopCounter.getName(), |
205 | |
CustomCounter.Aggregation.SUM, |
206 | 0 | giraphHadoopCounter.getValue()); |
207 | 0 | countersList.add(customCounter); |
208 | |
} |
209 | 0 | return countersList; |
210 | |
} |
211 | |
} |