1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.profiler;
|
10
|
|
11
|
import org.apache.logging.log4j.LogManager;
|
12
|
import org.apache.logging.log4j.Logger;
|
13
|
|
14
|
import com.yourkit.api.Controller;
|
15
|
|
16
|
//TODO move to common
|
17
|
public class ProfilerController {
|
18
|
|
19
|
private static final Logger logger = LogManager.getLogger();
|
20
|
|
21
|
private static Controller controller;
|
22
|
private static int memSnapshotCnt = 0;
|
23
|
|
24
|
private static void init(){
|
25
|
if(controller == null){
|
26
|
try {
|
27
|
controller = new Controller();
|
28
|
memSnapshotCnt = 0;
|
29
|
} catch (Exception e) {
|
30
|
logger.info("The initialization of ProfilerController fails");
|
31
|
}
|
32
|
}
|
33
|
}
|
34
|
|
35
|
public static void memorySnapshot() {
|
36
|
init();
|
37
|
try {
|
38
|
controller.forceGC();
|
39
|
logger.info("snapshot " + memSnapshotCnt++ + " to file: " + controller.captureMemorySnapshot());
|
40
|
} catch (Exception e) {
|
41
|
logger.info("taking memory snapshot " + memSnapshotCnt + " failed");
|
42
|
}
|
43
|
}
|
44
|
|
45
|
}
|