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;
021
022import org.apache.hadoop.hbase.HBaseInterfaceAudience;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.yetus.audience.InterfaceStability;
025
026/**
027 * A metric which encompasses a {@link Histogram} and {@link Meter}.
028 */
029@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
030@InterfaceStability.Evolving
031public interface Timer extends Metric {
032  /**
033   * Update the timer with the given duration in given time unit.
034   * @param duration the duration of the event
035   * @param unit the time unit for the duration
036   */
037  void update(long duration, TimeUnit unit);
038
039  /**
040   * Update the timer with the given duration in milliseconds
041   * @param durationMillis the duration of the event in ms
042   */
043  default void updateMillis(long durationMillis) {
044    update(durationMillis, TimeUnit.NANOSECONDS);
045  }
046
047  /**
048   * Update the timer with the given duration in microseconds
049   * @param durationMicros the duration of the event in microseconds
050   */
051  default void updateMicros(long durationMicros) {
052    update(durationMicros, TimeUnit.MICROSECONDS);
053  }
054
055  /**
056   * Update the timer with the given duration in nanoseconds
057   * @param durationNanos the duration of the event in ns
058   */
059  default void updateNanos(long durationNanos) {
060    update(durationNanos, TimeUnit.NANOSECONDS);
061  }
062
063  @InterfaceAudience.Private
064  Histogram getHistogram();
065
066  @InterfaceAudience.Private
067  Meter getMeter();
068}