1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.metrics; |
20 | |
|
21 | |
import java.io.PrintStream; |
22 | |
|
23 | |
import org.apache.giraph.bsp.BspService; |
24 | |
import org.apache.giraph.conf.GiraphConfiguration; |
25 | |
|
26 | |
import com.yammer.metrics.core.Histogram; |
27 | |
import com.yammer.metrics.core.Metric; |
28 | |
import com.yammer.metrics.core.MetricName; |
29 | |
import com.yammer.metrics.core.MetricPredicate; |
30 | |
import com.yammer.metrics.core.MetricsRegistry; |
31 | |
import com.yammer.metrics.reporting.ConsoleReporter; |
32 | |
import com.yammer.metrics.reporting.JmxReporter; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class SuperstepMetricsRegistry extends GiraphMetricsRegistry { |
38 | |
|
39 | 0 | private long superstep = BspService.INPUT_SUPERSTEP; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
protected SuperstepMetricsRegistry(MetricsRegistry registry, |
49 | |
JmxReporter reporter, String groupName, String type) { |
50 | 0 | super(registry, reporter, groupName, type); |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public static SuperstepMetricsRegistry create(GiraphConfiguration conf, |
61 | |
long superstep) { |
62 | 0 | if (conf.metricsEnabled()) { |
63 | 0 | MetricsRegistry registry = new MetricsRegistry(); |
64 | 0 | SuperstepMetricsRegistry superstepMetrics = new SuperstepMetricsRegistry( |
65 | |
registry, new JmxReporter(registry), |
66 | 0 | "giraph.superstep", String.valueOf(superstep)); |
67 | 0 | superstepMetrics.superstep = superstep; |
68 | 0 | return superstepMetrics; |
69 | |
} else { |
70 | 0 | return createFake(); |
71 | |
} |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public static SuperstepMetricsRegistry createFake() { |
79 | 0 | return new SuperstepMetricsRegistry(new NoOpMetricsRegistry(), null, |
80 | |
"", ""); |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public long getSuperstep() { |
88 | 0 | return superstep; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public void setSuperstep(long superstep) { |
97 | 0 | super.setType(String.valueOf(superstep)); |
98 | 0 | this.superstep = superstep; |
99 | 0 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public void printSummary(PrintStream out) { |
107 | 0 | new WorkerSuperstepMetrics().readFromRegistry().print(superstep, out); |
108 | 0 | out.println(""); |
109 | 0 | MetricPredicate superstepFilter = new MetricPredicate() { |
110 | |
@Override |
111 | |
public boolean matches(MetricName name, Metric metric) { |
112 | 0 | return name.getType().equals(getType()); |
113 | |
} |
114 | |
}; |
115 | 0 | new ConsoleReporter(getInternalRegistry(), out, superstepFilter) { |
116 | |
@Override |
117 | |
public void processHistogram(MetricName name, Histogram histogram, |
118 | |
PrintStream stream) { |
119 | 0 | stream.printf(" sum = %,2.2f%n", histogram.sum()); |
120 | 0 | super.processHistogram(name, histogram, stream); |
121 | 0 | stream.printf(" count = %d%n", histogram.count()); |
122 | 0 | } |
123 | 0 | } .run(); |
124 | 0 | } |
125 | |
} |