1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.giraph.block_app.framework.internal; |
19 | |
|
20 | |
import java.lang.reflect.Field; |
21 | |
|
22 | |
import org.apache.giraph.block_app.framework.api.Counter; |
23 | |
import org.apache.giraph.block_app.framework.api.StatusReporter; |
24 | |
import org.apache.giraph.block_app.framework.internal.BlockMasterLogic.TimeStatsPerEvent; |
25 | |
|
26 | |
import org.apache.giraph.counters.CustomCounter; |
27 | |
import org.apache.giraph.counters.CustomCounters; |
28 | |
import org.apache.hadoop.mapreduce.Mapper; |
29 | |
|
30 | |
|
31 | |
public class BlockCounters { |
32 | |
public static final String GROUP = "Blocks Framework"; |
33 | |
|
34 | 0 | private BlockCounters() { } |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public static void setStageCounters( |
43 | |
String prefix, Object stage, StatusReporter reporter) { |
44 | 0 | if (stage != null && reporter != null) { |
45 | 0 | Class<?> clazz = stage.getClass(); |
46 | |
|
47 | 0 | while (clazz != null) { |
48 | 0 | Field[] fields = clazz.getDeclaredFields(); |
49 | |
|
50 | 0 | Field.setAccessible(fields, true); |
51 | 0 | for (Field field : fields) { |
52 | |
try { |
53 | 0 | long value = field.getLong(stage); |
54 | 0 | String counterName = prefix + field.getName(); |
55 | 0 | CustomCounters.addCustomCounter(GROUP, counterName, |
56 | |
CustomCounter.Aggregation.SUM); |
57 | 0 | reporter.getCounter( |
58 | 0 | GROUP, prefix + field.getName()).setValue(value); |
59 | |
|
60 | |
|
61 | 0 | } catch (IllegalArgumentException | IllegalAccessException e) { |
62 | 0 | } |
63 | |
|
64 | |
} |
65 | 0 | clazz = clazz.getSuperclass(); |
66 | 0 | } |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
public static void setMasterTimeCounter( |
71 | |
PairedPieceAndStage<?> masterPiece, long superstep, |
72 | |
long millis, StatusReporter reporter, |
73 | |
TimeStatsPerEvent timeStats) { |
74 | 0 | String name = masterPiece.getPiece().toString(); |
75 | 0 | String groupName = GROUP + " Master Timers"; |
76 | 0 | String counterName = String.format( |
77 | 0 | "In %6.1f %s (s)", superstep - 0.5, name); |
78 | 0 | CustomCounters.addCustomCounter(groupName, counterName, |
79 | |
CustomCounter.Aggregation.SUM); |
80 | 0 | reporter.getCounter(groupName, counterName).setValue(millis / 1000); |
81 | 0 | timeStats.inc(name, millis); |
82 | 0 | } |
83 | |
|
84 | |
public static void setWorkerTimeCounter( |
85 | |
BlockWorkerPieces<?> workerPieces, long superstep, |
86 | |
long millis, StatusReporter reporter, |
87 | |
TimeStatsPerEvent timeStats) { |
88 | 0 | String name = workerPieces.toStringShort(); |
89 | 0 | String groupName = GROUP + " Worker Timers"; |
90 | 0 | String counterName = String.format("In %6d %s (s)", superstep, name); |
91 | 0 | CustomCounters.addCustomCounter(groupName, counterName, |
92 | |
CustomCounter.Aggregation.SUM); |
93 | 0 | reporter.getCounter(groupName, counterName).setValue(millis / 1000); |
94 | 0 | timeStats.inc(name, millis); |
95 | 0 | } |
96 | |
|
97 | |
public static Counter getCounter( |
98 | |
Mapper.Context context, String group, String name) { |
99 | 0 | final org.apache.hadoop.mapreduce.Counter counter = |
100 | 0 | context.getCounter(group, name); |
101 | 0 | return new Counter() { |
102 | |
@Override |
103 | |
public void increment(long incr) { |
104 | 0 | counter.increment(incr); |
105 | 0 | } |
106 | |
|
107 | |
@Override |
108 | |
public void setValue(long value) { |
109 | 0 | counter.setValue(value); |
110 | 0 | } |
111 | |
}; |
112 | |
} |
113 | |
|
114 | |
public static Counter getNoOpCounter() { |
115 | 0 | return new Counter() { |
116 | |
@Override |
117 | 0 | public void setValue(long value) { } |
118 | |
|
119 | |
@Override |
120 | 0 | public void increment(long incr) { } |
121 | |
}; |
122 | |
} |
123 | |
} |