blob: e837c6672acffe6209bfbd957c0e9f7a3a4419e2 [file] [log] [blame]
Yuta HIGUCHIa22f69f2014-11-24 22:25:17 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onlab.metrics;
18
19import com.codahale.metrics.Timer;
20import com.codahale.metrics.Timer.Context;
21
22public final class MetricsUtil {
23
24 /**
25 * Starts the Metric Timer.
26 * <p>
27 * If the given timer was null, it will silently return null.
28 * </p>
29 *
30 * @param timer timer to start
31 * @return timing context, if timer was not null
32 */
33 public static final Context startTimer(Timer timer) {
34 if (timer != null) {
35 return timer.time();
36 }
37 return null;
38 }
39
40 /**
41 * Stops the Metric Timer context.
42 * <p>
43 * If the given context was null, it will silently be ignored.
44 * </p>
45 *
46 * @param context timing context to stop, if not null.
47 */
48 public static final void stopTimer(Context context) {
49 if (context != null) {
50 context.stop();
51 }
52 }
53
54 // avoid instantiation
55 private MetricsUtil() {}
56}