Coverage Report - org.perfidix.result.BenchmarkResult
 
Classes in this File Line Coverage Branch Coverage Complexity
BenchmarkResult
84%
22/26
100%
8/8
1.667
 
 1  
 /**
 2  
  * Copyright (c) 2012, University of Konstanz, Distributed Systems Group
 3  
  * All rights reserved.
 4  
  * 
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions are met:
 7  
  * * Redistributions of source code must retain the above copyright
 8  
  * notice, this list of conditions and the following disclaimer.
 9  
  * * Redistributions in binary form must reproduce the above copyright
 10  
  * notice, this list of conditions and the following disclaimer in the
 11  
  * documentation and/or other materials provided with the distribution.
 12  
  * * Neither the name of the University of Konstanz nor the
 13  
  * names of its contributors may be used to endorse or promote products
 14  
  * derived from this software without specific prior written permission.
 15  
  * 
 16  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 17  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 18  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 19  
  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 20  
  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 21  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 22  
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 23  
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 24  
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 25  
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 26  
  */
 27  
 package org.perfidix.result;
 28  
 
 29  
 import java.lang.reflect.Method;
 30  
 import java.util.HashSet;
 31  
 import java.util.Set;
 32  
 
 33  
 import org.perfidix.exceptions.AbstractPerfidixMethodException;
 34  
 import org.perfidix.meter.AbstractMeter;
 35  
 import org.perfidix.ouput.AbstractOutput;
 36  
 
 37  
 /**
 38  
  * This class holds the data of a complete Benchmark. Only one <code>BenchmarkResult</code> is generated per
 39  
  * Benchmark-Run. The different
 40  
  * components are {@link ClassResult} objects. This class is the container for
 41  
  * the results of a Benchmark and therefore the input for different Outputs.
 42  
  * 
 43  
  * @see org.perfidix.Benchmark
 44  
  * @see AbstractOutput
 45  
  * @author Sebastian Graf, University of Konstanz
 46  
  * @author Alexander Onea, neue Couch
 47  
  */
 48  
 public final class BenchmarkResult extends AbstractResultContainer<ClassResult> {
 49  
 
 50  
     /** All occured exceptions. */
 51  
     private transient final Set<AbstractPerfidixMethodException> exceptions;
 52  
 
 53  
     /** Outputs for listeners. */
 54  
     private transient final AbstractOutput[] outputs;
 55  
 
 56  
     /**
 57  
      * Constructor.
 58  
      * 
 59  
      * @param paramOutputs
 60  
      *            {@link AbstractOutput} instances for listener
 61  
      */
 62  
     public BenchmarkResult(final AbstractOutput... paramOutputs) {
 63  135
         super(null);
 64  135
         this.exceptions = new HashSet<AbstractPerfidixMethodException>();
 65  135
         outputs = paramOutputs;
 66  135
     }
 67  
 
 68  
     /** {@inheritDoc} */
 69  
     @Override
 70  
     public String getElementName() {
 71  0
         return "Benchmark";
 72  
     }
 73  
 
 74  
     /**
 75  
      * Adding a dataset to a given meter and adapting the underlaying result
 76  
      * model.
 77  
      * 
 78  
      * @param meth
 79  
      *            where the result is corresponding to
 80  
      * @param meter
 81  
      *            where the result is corresponding to
 82  
      * @param data
 83  
      *            the data itself
 84  
      */
 85  
     public void addData(final Method meth, final AbstractMeter meter, final double data) {
 86  
 
 87  12743
         final Class<?> clazz = meth.getDeclaringClass();
 88  12743
         if (!elements.containsKey(clazz)) {
 89  145
             elements.put(clazz, new ClassResult(clazz));
 90  
         }
 91  
 
 92  12743
         final ClassResult clazzResult = elements.get(clazz);
 93  12743
         if (!clazzResult.elements.containsKey(meth)) {
 94  285
             clazzResult.elements.put(meth, new MethodResult(meth));
 95  
         }
 96  
 
 97  12743
         final MethodResult methodResult = clazzResult.elements.get(meth);
 98  12743
         methodResult.addData(meter, data);
 99  12743
         clazzResult.addData(meter, data);
 100  12743
         this.addData(meter, data);
 101  
 
 102  18801
         for (final AbstractOutput output : outputs) {
 103  6058
             output.listenToResultSet(meth, meter, data);
 104  
         }
 105  
 
 106  12743
     }
 107  
 
 108  
     /**
 109  
      * Adding an exception to this result.
 110  
      * 
 111  
      * @param exec
 112  
      *            the exception stored to this result
 113  
      */
 114  
     public void addException(final AbstractPerfidixMethodException exec) {
 115  96
         this.getExceptions().add(exec);
 116  117
         for (final AbstractOutput output : outputs) {
 117  21
             output.listenToException(exec);
 118  
         }
 119  96
     }
 120  
 
 121  
     /**
 122  
      * Getter for member exceptions.
 123  
      * 
 124  
      * @return the exceptions
 125  
      */
 126  
     public Set<AbstractPerfidixMethodException> getExceptions() {
 127  151
         return exceptions;
 128  
     }
 129  
 
 130  
     /**
 131  
      * {@inheritDoc}
 132  
      */
 133  
     @Override
 134  
     public String toString() {
 135  0
         final StringBuilder builder = new StringBuilder(super.toString());
 136  0
         builder.append("\nexceptions: ").append(getExceptions());
 137  0
         return builder.toString();
 138  
     }
 139  
 
 140  
 }