1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.utils; |
20 | |
|
21 | |
import org.apache.giraph.conf.GiraphConstants; |
22 | |
import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration; |
23 | |
import org.apache.giraph.master.MasterObserver; |
24 | |
import org.apache.giraph.metrics.AggregatedMetrics; |
25 | |
import org.apache.giraph.partition.PartitionStats; |
26 | |
import org.apache.giraph.worker.WorkerObserver; |
27 | |
import org.apache.log4j.Logger; |
28 | |
|
29 | |
import java.util.List; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class JMapHistoDumper implements MasterObserver, WorkerObserver { |
36 | |
|
37 | 0 | private static final Logger LOG = Logger.getLogger(JMapHistoDumper.class); |
38 | |
|
39 | |
|
40 | |
private int sleepMillis; |
41 | |
|
42 | |
private int linesToPrint; |
43 | |
|
44 | |
private boolean liveObjectsOnly; |
45 | |
|
46 | |
|
47 | |
private Thread thread; |
48 | |
|
49 | 0 | private volatile boolean stop = false; |
50 | |
|
51 | |
private String jmapPath; |
52 | |
|
53 | |
@Override |
54 | |
public void preLoad() { |
55 | |
|
56 | 0 | startJMapThread(); |
57 | 0 | } |
58 | |
|
59 | |
@Override |
60 | |
public void postSave() { |
61 | |
|
62 | 0 | joinJMapThread(); |
63 | 0 | } |
64 | |
|
65 | |
@Override |
66 | |
public void preApplication() { |
67 | 0 | } |
68 | |
|
69 | |
@Override |
70 | |
public void postApplication() { |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private void joinJMapThread() { |
77 | 0 | stop = true; |
78 | |
try { |
79 | 0 | thread.interrupt(); |
80 | 0 | thread.join(sleepMillis + 5000); |
81 | 0 | } catch (InterruptedException e) { |
82 | 0 | LOG.error("Failed to join jmap thread"); |
83 | 0 | } |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void startJMapThread() { |
90 | 0 | stop = false; |
91 | 0 | thread = ThreadUtils.startThread(new Runnable() { |
92 | |
@Override |
93 | |
public void run() { |
94 | 0 | while (!stop) { |
95 | 0 | JMap.heapHistogramDump(linesToPrint, liveObjectsOnly, jmapPath); |
96 | 0 | ThreadUtils.trySleep(sleepMillis); |
97 | |
} |
98 | 0 | } |
99 | |
}, "jmap-dumper"); |
100 | 0 | } |
101 | |
|
102 | |
@Override |
103 | 0 | public void preSuperstep(long superstep) { } |
104 | |
|
105 | |
@Override |
106 | 0 | public void postSuperstep(long superstep) { } |
107 | |
|
108 | |
@Override |
109 | |
public void superstepMetricsUpdate(long superstep, |
110 | |
AggregatedMetrics aggregatedMetrics, |
111 | 0 | List<PartitionStats> partitionStatsList) { } |
112 | |
|
113 | |
@Override |
114 | 0 | public void applicationFailed(Exception e) { } |
115 | |
|
116 | |
@Override |
117 | |
public void setConf(ImmutableClassesGiraphConfiguration configuration) { |
118 | 0 | sleepMillis = GiraphConstants.JMAP_SLEEP_MILLIS.get(configuration); |
119 | 0 | linesToPrint = GiraphConstants.JMAP_PRINT_LINES.get(configuration); |
120 | 0 | liveObjectsOnly = GiraphConstants.JMAP_LIVE_ONLY.get(configuration); |
121 | 0 | jmapPath = GiraphConstants.JMAP_PATH.get(configuration); |
122 | 0 | } |
123 | |
|
124 | |
@Override |
125 | |
public ImmutableClassesGiraphConfiguration getConf() { |
126 | 0 | return null; |
127 | |
} |
128 | |
} |