2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.statistics;
11 import java.util.concurrent.TimeUnit;
14 * Moving average - measure and compute
16 public class TimeCounter {
17 private long beginningOfLap;
19 private int marksCount = 0;
21 public void markStart() {
22 beginningOfLap = System.nanoTime();
27 public void addTimeMark() {
28 final long now = System.nanoTime();
29 delta += now - beginningOfLap;
34 public long getAverageTimeBetweenMarks() {
37 average = delta / marksCount;
39 return TimeUnit.NANOSECONDS.toMillis(average);