Coverage Report - org.kuali.rice.ken.util.PerformanceLog
 
Classes in this File Line Coverage Branch Coverage Complexity
PerformanceLog
0%
0/7
N/A
1
PerformanceLog$PerformanceStopWatch
0%
0/7
N/A
1
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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 org.kuali.rice.ken.util;
 17  
 
 18  
 import org.apache.commons.lang.time.DurationFormatUtils;
 19  
 import org.apache.commons.lang.time.StopWatch;
 20  
 import org.apache.log4j.Logger;
 21  
 
 22  
 /**
 23  
  * Wrapper for the Log4J performance log
 24  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 25  
  */
 26  0
 public final class PerformanceLog {
 27  0
     private static final Logger LOG = Logger.getLogger("Performance");
 28  
 
 29  
     /**
 30  
      * This class 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
      */
 33  0
     public static final class PerformanceStopWatch {
 34  0
         private StopWatch stopWatch = new StopWatch();
 35  
         private String message;
 36  
         
 37  
         /**
 38  
          * Constructs a PerformanceLog.java.
 39  
          * @param message
 40  
          */
 41  0
         public PerformanceStopWatch(String message) {
 42  0
             this.message = message;
 43  0
             stopWatch.start();
 44  0
         }
 45  
 
 46  
         /**
 47  
          * This method records the duration of how long a message delivery takes.
 48  
          */
 49  
         public void recordDuration() {
 50  0
             logDuration(message, stopWatch.getTime());
 51  0
         }
 52  
     }
 53  
 
 54  
     /**
 55  
      * This method returns an instance of the logger object.
 56  
      * @return Logger
 57  
      */
 58  
     public static Logger getInstance() {
 59  0
         return LOG;
 60  
     }
 61  
 
 62  
     /**
 63  
      * This method returns a new stop watch instance.
 64  
      * @param message
 65  
      * @return PerformanceStopWatch
 66  
      */
 67  
     public static PerformanceStopWatch startTimer(String message) {
 68  0
         return new PerformanceStopWatch(message);
 69  
     }
 70  
     
 71  
     /**
 72  
      * This method logs the duration information for a given message.
 73  
      * @param message
 74  
      * @param duration
 75  
      */
 76  
     public static void logDuration(String message, long duration) {
 77  0
         LOG.info(message + ": " + DurationFormatUtils.formatDurationHMS(duration) + " (" + duration+ " ms)");
 78  0
     }
 79  
 }