1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.inno.env;
\r
27 * <h1>TimeTaken</h1>
\r
28 * This simple interface allows for many different kinds of
\r
29 * Audit Logs to be accomplished, by assuming that the creation
\r
30 * of this object indicates "start", and the calling of "done"
\r
33 * The implementor of this class can easily be stored in efficient
\r
34 * mechanisms to minimize impact of Auditing on performance.
\r
38 public abstract class TimeTaken {
\r
39 public final long start;
\r
40 protected long end, size;
\r
41 public final int flag;
\r
42 public final String name;
\r
45 * The name is as it will appear when written to output (abstract method)
\r
47 * The flag is an integer which can be System type (XML, REMOTE, etc), or End User defined for reporting purposes
\r
52 public TimeTaken(String name, int flag) {
\r
53 start = System.nanoTime();
\r
61 * Call this when process is done to state ending time.<p>
\r
63 * It is <i>exceedingly prudent</i> to wrap the process called with a try-finally:<p>
\r
66 * TimeTaken tt = env.startSubTime();
\r
68 * process.me(); // code to be timed.
\r
74 public void done() {
\r
75 end = System.nanoTime();
\r
80 * For sizable contents, set the size. Implementations can simply write a no-op if they don't wish to
\r
85 public void size(long theSize) {
\r
90 * Give readonly access to End, which isn't final
\r
98 * Time is taken in NanoSeconds. This method converts to decimals of Milliseconds
\r
101 public float millis() {
\r
102 return (end-start)/1000000f;
\r
105 * Write self to a String Builder (for making Audits)
\r
108 public abstract void output(StringBuilder sb);
\r
113 public String toString() {
\r
114 return name + ' ' + millis() + "ms " + (size>0?Long.toString(size):"");
\r