| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.runtime.common.metric; |
| |
| import java.util.Date; |
| |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| /** |
| * The Class TimeLogger. |
| */ |
| public class TimeLogger { |
| |
| /** The Constant LOGGER. */ |
| private static final Logger LOGGER = LoggerFactory |
| .getLogger(TimeLogger.class); |
| |
| /** The clazz. */ |
| private final Class<?> clazz; |
| |
| /** The start. */ |
| private final long start; |
| |
| /** |
| * Start. |
| * |
| * @param clazz |
| * the clazz |
| * @return the time logger |
| */ |
| public static TimeLogger start(Class<?> clazz) { |
| return new TimeLogger(clazz); |
| } |
| |
| /** |
| * Instantiates a new time logger. |
| * |
| * @param clazz |
| * the clazz |
| */ |
| private TimeLogger(Class<?> clazz) { |
| this.clazz = clazz; |
| start = new Date().getTime(); |
| } |
| |
| /** |
| * Stop. |
| * |
| * @param message |
| * the message |
| */ |
| public void stop(String message) { |
| long stop = new Date().getTime(); |
| LOGGER.info(clazz.getName() + ": " + message + " " + (stop - start) + "ms"); |
| } |
| |
| } |