如何为grails应用程序中的每个请求获取内存使用情况

时间:2015-01-14 11:14:14

标签: java grails groovy profiling gvm

是否有任何工具/插件可以识别grails Web应用程序中每个请求的内存,cpu和其他使用信息等配置文件。

1 个答案:

答案 0 :(得分:0)

尝试一下:

public class CrunchifyJVMParameters {


    public static void main(String[] args) {

        int mb = 1024 * 1024; 

        // get Runtime instance
        Runtime instance = Runtime.getRuntime();

        System.out.println("***** Heap utilization statistics [MB] *****\n");

        // available memory
        System.out.println("Total Memory: " + instance.totalMemory() / mb);

        // free memory
        System.out.println("Free Memory: " + instance.freeMemory() / mb);

        // used memory
        System.out.println("Used Memory: "
                + (instance.totalMemory() - instance.freeMemory()) / mb);

        // Maximum available memory
        System.out.println("Max Memory: " + instance.maxMemory() / mb);
    }
}

来源https://crunchify.com/java-runtime-get-free-used-and-total-memory-in-java/