001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.metrics;
019
020import java.util.concurrent.TimeUnit;
021import org.apache.hadoop.hbase.HBaseInterfaceAudience;
022import org.apache.yetus.audience.InterfaceAudience;
023import org.apache.yetus.audience.InterfaceStability;
024
025/**
026 * A metric which encompasses a {@link Histogram} and {@link Meter}.
027 */
028@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
029@InterfaceStability.Evolving
030public interface Timer extends Metric {
031  /**
032   * Update the timer with the given duration in given time unit.
033   * @param duration the duration of the event
034   * @param unit     the time unit for the duration
035   */
036  void update(long duration, TimeUnit unit);
037
038  /**
039   * Update the timer with the given duration in milliseconds
040   * @param durationMillis the duration of the event in ms
041   */
042  default void updateMillis(long durationMillis) {
043    update(durationMillis, TimeUnit.NANOSECONDS);
044  }
045
046  /**
047   * Update the timer with the given duration in microseconds
048   * @param durationMicros the duration of the event in microseconds
049   */
050  default void updateMicros(long durationMicros) {
051    update(durationMicros, TimeUnit.MICROSECONDS);
052  }
053
054  /**
055   * Update the timer with the given duration in nanoseconds
056   * @param durationNanos the duration of the event in ns
057   */
058  default void updateNanos(long durationNanos) {
059    update(durationNanos, TimeUnit.NANOSECONDS);
060  }
061
062  @InterfaceAudience.Private
063  Histogram getHistogram();
064
065  @InterfaceAudience.Private
066  Meter getMeter();
067}