All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jp.kobe_u.sugar.Logger Maven / Gradle / Ivy

Go to download

This is a JSR331 interface for the open source Java constraint programming library "Sugar" v. 2.1.3

There is a newer version: 2.3.1
Show newest version
package jp.kobe_u.sugar;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;

public class Logger {
    private static final long MEGA = 1024*1024;
    public static int verboseLevel = 0;

    public static void print(String message) {
        System.out.print(message);
    }

    public static void println(String message) {
        System.out.println(message);
    }

    public static void info(String message) {
        if (verboseLevel >= 1) {
            println("c " + message);
        }
    }

    public static void fine(String message) {
        if (verboseLevel >= 2) {
            println("c " + message);
        }
    }

    static void status() {
        MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
        MemoryUsage heapUsage = mbean.getHeapMemoryUsage();
//      long heapInit = heapUsage.getInit() / MEGA;
        long heapUsed = heapUsage.getUsed() / Logger.MEGA;
//      long heapCommitted = heapUsage.getCommitted() / MEGA;
        long heapMax = heapUsage.getMax() / Logger.MEGA;
        MemoryUsage nonHeapUsage = mbean.getNonHeapMemoryUsage();
//      long nonHeapInit = nonHeapUsage.getInit() / MEGA;
        long nonHeapUsed = nonHeapUsage.getUsed() / Logger.MEGA;
//      long nonHeapCommitted = nonHeapUsage.getCommitted() / MEGA;
        long nonHeapMax = nonHeapUsage.getMax() / Logger.MEGA;
        fine(
                "Heap : " + heapUsed + " MiB used (max " + heapMax + " MiB), " +
                "NonHeap : " + nonHeapUsed + " MiB used (max " + nonHeapMax + " MiB)"
        );
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy