758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco/*
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * CDDL HEADER START
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco *
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * The contents of this file are subject to the terms of the
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * Common Development and Distribution License (the "License").
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * You may not use this file except in compliance with the License.
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco *
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * See LICENSE.txt included in this distribution for the specific
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * language governing permissions and limitations under the License.
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco *
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * When distributing Covered Code, include this CDDL HEADER in each
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * file and include the License file at LICENSE.txt.
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * If applicable, add the following below this CDDL HEADER, with the
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * fields enclosed by brackets "[]" replaced with your own identifying
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * information: Portions Copyright [yyyy] [name of copyright owner]
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco *
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * CDDL HEADER END
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco */
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco/*
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco */
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Koscopackage org.opensolaris.opengrok.util;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Koscoimport java.util.logging.Level;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Koscoimport java.util.logging.Logger;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Koscoimport static org.opensolaris.opengrok.util.StringUtils.getReadableTime;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Koscopublic class Statistics {
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco private final long startTime;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco public Statistics() {
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco startTime = System.currentTimeMillis();
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco }
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
4a83e85110f9ac15f6a7a01bec98ff3dd9501d77Vladimir Kotal public void report(Logger log, String msg) {
4a83e85110f9ac15f6a7a01bec98ff3dd9501d77Vladimir Kotal long stopTime = System.currentTimeMillis();
4a83e85110f9ac15f6a7a01bec98ff3dd9501d77Vladimir Kotal String time_str = StringUtils.getReadableTime(stopTime - startTime);
4a83e85110f9ac15f6a7a01bec98ff3dd9501d77Vladimir Kotal log.log(Level.INFO, msg + " (took {0})", time_str);
4a83e85110f9ac15f6a7a01bec98ff3dd9501d77Vladimir Kotal }
4a83e85110f9ac15f6a7a01bec98ff3dd9501d77Vladimir Kotal
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco public void report(Logger log) {
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco long stopTime = System.currentTimeMillis() - startTime;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco log.log(Level.INFO, "Total time: {0}", getReadableTime(stopTime));
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco System.gc();
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco Runtime r = Runtime.getRuntime();
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco long mb = 1024L * 1024;
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco log.log(Level.INFO, "Final Memory: {0}M/{1}M",
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco new Object[]{(r.totalMemory() - r.freeMemory()) /
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco mb, r.totalMemory() / mb});
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco }
758c57dc78eb2a3e32e2748bef420359fc03c39dLubos Kosco}