File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
api/src/main/java/com/graphhopper/util Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 20
20
import com .graphhopper .util .shapes .BBox ;
21
21
22
22
import java .io .*;
23
+ import java .lang .management .GarbageCollectorMXBean ;
24
+ import java .lang .management .ManagementFactory ;
23
25
import java .nio .ByteBuffer ;
24
26
import java .nio .MappedByteBuffer ;
25
27
import java .nio .charset .Charset ;
@@ -174,6 +176,29 @@ public static String getMemInfo() {
174
176
return "totalMB:" + getTotalMB () + ", usedMB:" + getUsedMB ();
175
177
}
176
178
179
+ public static int getUsedMBAfterGC () {
180
+ long before = getTotalGcCount ();
181
+ // trigger gc
182
+ System .gc ();
183
+ while (getTotalGcCount () == before ) {
184
+ // wait for the gc to have completed
185
+ }
186
+ long result = (ManagementFactory .getMemoryMXBean ().getHeapMemoryUsage ().getUsed () +
187
+ ManagementFactory .getMemoryMXBean ().getNonHeapMemoryUsage ().getUsed ()) / (1024 * 1024 );
188
+ return (int ) result ;
189
+ }
190
+
191
+ private static long getTotalGcCount () {
192
+ long sum = 0 ;
193
+ for (GarbageCollectorMXBean b : ManagementFactory .getGarbageCollectorMXBeans ()) {
194
+ long count = b .getCollectionCount ();
195
+ if (count != -1 ) {
196
+ sum += count ;
197
+ }
198
+ }
199
+ return sum ;
200
+ }
201
+
177
202
public static int getSizeOfObjectRef (int factor ) {
178
203
// pointer to class, flags, lock
179
204
return factor * (4 + 4 + 4 );
You can’t perform that action at this time.
0 commit comments