Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 124   Methods: 11
NCLOC: 80   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Stopwatch.java 11.1% 22.5% 36.4% 21.7%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: Stopwatch.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice;
 21   
 22    /**
 23    * Stopwatch is a debugging tool for manually profiling code execution.
 24    * This class will probably be removed for a production release.
 25    *
 26    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 27    */
 28    public final class Stopwatch {
 29    String label = null;
 30    long total = 0;
 31    long begin = 0;
 32    long end = 0;
 33   
 34  0 public Stopwatch() {
 35    }
 36   
 37  0 public Stopwatch(boolean immediate) {
 38  0 if (immediate) {
 39  0 start();
 40    }
 41    }
 42   
 43  0 public Stopwatch(String label) {
 44  0 this.label = label;
 45    }
 46   
 47  84 public Stopwatch(String label, boolean immediate) {
 48  84 this.label = label;
 49  84 if (immediate) {
 50  84 start();
 51    }
 52    }
 53   
 54  84 public void start() {
 55  84 begin = System.currentTimeMillis();
 56    }
 57   
 58  84 public long stop() {
 59  84 end = System.currentTimeMillis();
 60  84 total += (end - begin);
 61  84 return total;
 62    }
 63   
 64  0 public void cancel() {
 65  0 begin = 0;
 66  0 end = 0;
 67    }
 68   
 69  0 public void reset() {
 70  0 total = 0;
 71  0 begin = 0;
 72  0 end = 0;
 73    }
 74   
 75  84 public long elapsed() {
 76  84 if (end != 0) {
 77  84 return (end - begin);
 78    } else {
 79  0 return System.currentTimeMillis() - begin;
 80    }
 81    }
 82   
 83  0 public long total() {
 84  0 if (end != 0) {
 85  0 return total;
 86    } else {
 87  0 return (System.currentTimeMillis() - begin) + total;
 88    }
 89    }
 90   
 91  0 public String toString() {
 92  0 long t = total();
 93   
 94  0 StringBuffer sb = new StringBuffer();
 95  0 if (label != null) {
 96  0 sb.append(label + ": ");
 97    }
 98   
 99  0 long hour = t / 3600000;
 100  0 if (hour > 0) {
 101  0 sb.append(hour + "h ");
 102  0 t = t % 3600000;
 103    }
 104   
 105  0 long min = t / 60000;
 106  0 if (min > 0) {
 107  0 sb.append(min + "m ");
 108  0 t = t % 60000;
 109    }
 110   
 111  0 long sec = t / 1000;
 112  0 if (sec > 0) {
 113  0 sb.append(sec + "s ");
 114  0 t = t % 1000;
 115    }
 116   
 117  0 if (t > 0) {
 118  0 sb.append(t + "ms");
 119    }
 120   
 121  0 return sb.toString();
 122    }
 123    }
 124