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 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 super(registry, reporter, groupName, type);
51 }
52
53
54
55
56
57
58
59
60 public static SuperstepMetricsRegistry create(GiraphConfiguration conf,
61 long superstep) {
62 if (conf.metricsEnabled()) {
63 MetricsRegistry registry = new MetricsRegistry();
64 SuperstepMetricsRegistry superstepMetrics = new SuperstepMetricsRegistry(
65 registry, new JmxReporter(registry),
66 "giraph.superstep", String.valueOf(superstep));
67 superstepMetrics.superstep = superstep;
68 return superstepMetrics;
69 } else {
70 return createFake();
71 }
72 }
73
74
75
76
77
78 public static SuperstepMetricsRegistry createFake() {
79 return new SuperstepMetricsRegistry(new NoOpMetricsRegistry(), null,
80 "", "");
81 }
82
83
84
85
86
87 public long getSuperstep() {
88 return superstep;
89 }
90
91
92
93
94
95
96 public void setSuperstep(long superstep) {
97 super.setType(String.valueOf(superstep));
98 this.superstep = superstep;
99 }
100
101
102
103
104
105
106 public void printSummary(PrintStream out) {
107 new WorkerSuperstepMetrics().readFromRegistry().print(superstep, out);
108 out.println("");
109 MetricPredicate superstepFilter = new MetricPredicate() {
110 @Override
111 public boolean matches(MetricName name, Metric metric) {
112 return name.getType().equals(getType());
113 }
114 };
115 new ConsoleReporter(getInternalRegistry(), out, superstepFilter) {
116 @Override
117 public void processHistogram(MetricName name, Histogram histogram,
118 PrintStream stream) {
119 stream.printf(" sum = %,2.2f%n", histogram.sum());
120 super.processHistogram(name, histogram, stream);
121 stream.printf(" count = %d%n", histogram.count());
122 }
123 } .run();
124 }
125 }