Here you can find the source of logDuration(org.slf4j.Logger log, String prefix, long startTimeNanos)
Parameter | Description |
---|---|
log | the log to write to |
prefix | text to write to log before the amount of time that the activity took |
startTimeNanos | the starting time of this iteration, in nanoseconds (e.g., System.nanoTime()) |
public static void logDuration(org.slf4j.Logger log, String prefix, long startTimeNanos)
//package com.java2s; /*//w ww. j a v a2s . co m * Copyright (C) 2017 University of South Florida. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.concurrent.TimeUnit; public class Main { /** * Logs the amount of time that a particular activity took, based on the given start time * * @param log the log to write to * @param prefix text to write to log before the amount of time that the activity took * @param startTimeNanos the starting time of this iteration, in nanoseconds (e.g., System.nanoTime()) */ public static void logDuration(org.slf4j.Logger log, String prefix, long startTimeNanos) { long durationNanos = System.nanoTime() - startTimeNanos; long durationMillis = TimeUnit.NANOSECONDS.toMillis(durationNanos); long durationSeconds = TimeUnit.NANOSECONDS.toSeconds(durationNanos); double elapsedTime = (double) durationSeconds + (double) durationMillis / 1000.0; elapsedTime = Math.round(elapsedTime * 1000.0) / 1000.0; log.info(prefix + elapsedTime + " seconds"); } }