1 /*
2 * Copyright 2016 Function1, Inc. All Rights Reserved.
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 package tools.gsf.time;
17
18 /**
19 * Stateful stopwatch object used for measuring elapsed time. Can be used to record cumulative time as well as split times.
20 * Very lightweight. After creation, start() must be called to start the stopwatch. split() records the time since
21 * the last split() call (or start() call if split() has not yet been called).
22 * elapsed() records the total time elapsed since the timer was started. Elapsed() does not reset the stopwatch or
23 * save the latest split.
24 *
25 * The stopwatch can be restarted by calling start().
26 * @author Tony Field
27 * @since 2016-07-17
28 */
29 public interface Stopwatch {
30
31 /**
32 * Starts the stopwatch. Must be called before taking a split or elapsed time.
33 */
34 void start();
35
36 /**
37 * Record time elapsed since the last interval measurement or since started/restarted.
38 * Resets the interval timer.
39 * @param message message to record (typically a description of the functionality measured, like a component name.)
40 */
41 void split(String message);
42
43 /**
44 * Record time elapsed since the last interval measurement or since started/restarted.
45 * Resets the interval timer.
46 * @param message message to record (typically a description of the functionality measured, like a component name.)
47 * @param arguments arguments to be substituted into the message. Parameterization operates as in slf4j:
48 * http://www.slf4j.org/faq.html#logging_performance
49 */
50 void split(String message, Object... arguments);
51
52 /**
53 * Record the elapsed time since the stopwatch was started/restarted.
54 * Does not reset either the interval timer or the cumulative timer.
55 * @param message message to record (typically a description of the functionality measured, like a component name.)
56 */
57 void elapsed(String message);
58
59 /**
60 * Record the elapsed time since the stopwatch was started/restarted.
61 * Does not reset either the interval timer or the cumulative timer.
62 * @param message message to record (typically a description of the functionality measured, like a component name.)
63 * @param arguments arguments to be substituted into the message. Parameterization operates as in slf4j:
64 * http://www.slf4j.org/faq.html#logging_performance
65 */
66 void elapsed(String message, Object... arguments);
67 }