1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.giraph.metrics;
19
20 import org.apache.giraph.conf.GiraphConfiguration;
21 import org.apache.giraph.utils.GcTracker;
22
23 import com.google.common.collect.Lists;
24
25 import java.io.PrintStream;
26 import java.util.List;
27
28 import static org.apache.giraph.bsp.BspService.INPUT_SUPERSTEP;
29
30
31
32
33 public class GiraphMetrics {
34
35 private static GiraphMetrics INSTANCE = new GiraphMetrics();
36
37
38 private final SuperstepMetricsRegistry perSuperstep;
39
40
41 private final GiraphMetricsRegistry perJobOptional;
42
43
44 private final GiraphMetricsRegistry perJobRequired;
45
46
47 private final GcTracker gcTracker;
48
49
50 private final List<ResetSuperstepMetricsObserver> observers =
51 Lists.newArrayList();
52
53
54
55
56 private GiraphMetrics() {
57 perJobOptional = GiraphMetricsRegistry.createFake();
58 perSuperstep = SuperstepMetricsRegistry.createFake();
59 perJobRequired = GiraphMetricsRegistry.createWithOptional("giraph", "job");
60 gcTracker = new GcTracker();
61 }
62
63
64
65
66
67
68 private GiraphMetrics(GiraphConfiguration conf) {
69 perJobOptional = GiraphMetricsRegistry.create(conf, "giraph", "job");
70 perSuperstep = SuperstepMetricsRegistry.create(conf, INPUT_SUPERSTEP);
71 perJobRequired = GiraphMetricsRegistry.createWithOptional("giraph", "job");
72 gcTracker = new GcTracker(conf);
73 }
74
75
76
77
78
79
80 public static GiraphMetrics get() {
81 return INSTANCE;
82 }
83
84
85
86
87
88
89 public static void init(GiraphConfiguration conf) {
90 INSTANCE = new GiraphMetrics(conf);
91 }
92
93
94
95
96
97
98 public GiraphMetricsRegistry perJobOptional() {
99 return perJobOptional;
100 }
101
102
103
104
105
106
107 public GiraphMetricsRegistry perJobRequired() {
108 return perJobRequired;
109 }
110
111
112
113
114
115
116 public SuperstepMetricsRegistry perSuperstep() {
117 return perSuperstep;
118 }
119
120
121
122
123
124
125 public GcTracker getGcTracker() {
126 return gcTracker;
127 }
128
129
130
131
132
133
134
135
136
137 public synchronized void addSuperstepResetObserver(
138 ResetSuperstepMetricsObserver observer) {
139 observers.add(observer);
140 }
141
142
143
144
145
146
147 public synchronized void resetSuperstepMetrics(long superstep) {
148 perSuperstep.setSuperstep(superstep);
149 for (ResetSuperstepMetricsObserver observer : observers) {
150 observer.newSuperstep(perSuperstep);
151 }
152 }
153
154
155
156
157
158
159 public void dumpToStream(PrintStream out) {
160 perJobOptional.printToStream(out);
161 perJobRequired.printToStream(out);
162 }
163
164
165
166
167 public void shutdown() {
168 perJobOptional.shutdown();
169 perJobRequired.shutdown();
170 perSuperstep.shutdown();
171 }
172 }