Coverage Report - org.apache.giraph.metrics.AggregatedMetric
 
Classes in this File Line Coverage Branch Coverage Complexity
AggregatedMetric
0%
0/6
0%
0/2
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.metrics;
 20  
 
 21  
 /**
 22  
  * An aggregator over metrics from multiple hosts. Computes min, max, and mean.
 23  
  *
 24  
  * @param <T> value type
 25  
  */
 26  0
 public abstract class AggregatedMetric<T extends Number> {
 27  
   /** Minimum value seen with the host that it came from */
 28  
   protected ValueWithHostname<T> min;
 29  
   /** Maximum value seen with the host that it came from */
 30  
   protected ValueWithHostname<T> max;
 31  
   /** Total of all the values seen */
 32  
   protected T sum;
 33  
   /** Number of values seen */
 34  
   protected long count;
 35  
 
 36  
   /**
 37  
    * Add another item to the aggregation.
 38  
    *
 39  
    * @param value value to add
 40  
    * @param hostnamePartitionId String hostname it came from
 41  
    */
 42  
   public abstract void addItem(T value, String hostnamePartitionId);
 43  
 
 44  
   /**
 45  
    * Whether this AggregatedMetric has any data.
 46  
    *
 47  
    * @return true if we have any data.
 48  
    */
 49  
   public boolean hasData() {
 50  0
     return count > 0;
 51  
   }
 52  
 
 53  
   /**
 54  
    * Get minimum value together with host it came from.
 55  
    *
 56  
    * @return ValueWithHostname for minimum
 57  
    */
 58  
   public ValueWithHostname<T> min() {
 59  0
     return min;
 60  
   }
 61  
 
 62  
   /**
 63  
    * Get maximum value together with host it came from.
 64  
    *
 65  
    * @return ValueWithHostname for maximum
 66  
    */
 67  
   public ValueWithHostname<T> max() {
 68  0
     return max;
 69  
   }
 70  
 
 71  
   /**
 72  
    * Get total of all the values seen
 73  
    *
 74  
    * @return total of values seen
 75  
    */
 76  
   public T sum() {
 77  0
     return sum;
 78  
   }
 79  
 
 80  
   /**
 81  
    * Get average of all the values
 82  
    *
 83  
    * @return computed average of all the values
 84  
    */
 85  
   public abstract double mean();
 86  
 
 87  
   /**
 88  
    * Get number of values seen
 89  
    *
 90  
    * @return count of values
 91  
    */
 92  
   public long count() {
 93  0
     return count;
 94  
   }
 95  
 }
 96