Coverage Report - org.apache.giraph.graph.GlobalStats
 
Classes in this File Line Coverage Branch Coverage Complexity
GlobalStats
100%
32/32
N/A
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.graph;
 20  
 
 21  
 import java.io.DataInput;
 22  
 import java.io.DataOutput;
 23  
 import java.io.IOException;
 24  
 
 25  
 import org.apache.giraph.graph.partition.PartitionStats;
 26  
 import org.apache.hadoop.io.Writable;
 27  
 
 28  
 /**
 29  
  * Aggregated stats by the master.
 30  
  */
 31  436
 public class GlobalStats implements Writable {
 32  
   /** All vertices in the application */
 33  436
   private long vertexCount = 0;
 34  
   /** All finished vertices in the last superstep */
 35  436
   private long finishedVertexCount = 0;
 36  
   /** All edges in the last superstep */
 37  436
   private long edgeCount = 0;
 38  
   /** All messages sent in the last superstep */
 39  436
   private long messageCount = 0;
 40  
   /** Whether the computation should be halted */
 41  436
   private boolean haltComputation = false;
 42  
 
 43  
   /**
 44  
    * Add the stats of a partition to the global stats.
 45  
    *
 46  
    * @param partitionStats Partition stats to be added.
 47  
    */
 48  
   public void addPartitionStats(PartitionStats partitionStats) {
 49  218
     this.vertexCount += partitionStats.getVertexCount();
 50  218
     this.finishedVertexCount += partitionStats.getFinishedVertexCount();
 51  218
     this.edgeCount += partitionStats.getEdgeCount();
 52  218
   }
 53  
 
 54  
   public long getVertexCount() {
 55  653
     return vertexCount;
 56  
   }
 57  
 
 58  
   public long getFinishedVertexCount() {
 59  435
     return finishedVertexCount;
 60  
   }
 61  
 
 62  
   public long getEdgeCount() {
 63  436
     return edgeCount;
 64  
   }
 65  
 
 66  
   public long getMessageCount() {
 67  255
     return messageCount;
 68  
   }
 69  
 
 70  
   public boolean getHaltComputation() {
 71  436
     return haltComputation;
 72  
   }
 73  
 
 74  
   public void setHaltComputation(boolean value) {
 75  24
     haltComputation = value;
 76  24
   }
 77  
 
 78  
   /**
 79  
    * Add messages to the global stats.
 80  
    *
 81  
    * @param messageCount Number of messages to be added.
 82  
    */
 83  
   public void addMessageCount(long messageCount) {
 84  218
     this.messageCount += messageCount;
 85  218
   }
 86  
 
 87  
   @Override
 88  
   public void readFields(DataInput input) throws IOException {
 89  218
     vertexCount = input.readLong();
 90  218
     finishedVertexCount = input.readLong();
 91  218
     edgeCount = input.readLong();
 92  218
     messageCount = input.readLong();
 93  218
     haltComputation = input.readBoolean();
 94  218
   }
 95  
 
 96  
   @Override
 97  
   public void write(DataOutput output) throws IOException {
 98  218
     output.writeLong(vertexCount);
 99  218
     output.writeLong(finishedVertexCount);
 100  218
     output.writeLong(edgeCount);
 101  218
     output.writeLong(messageCount);
 102  218
     output.writeBoolean(haltComputation);
 103  218
   }
 104  
 
 105  
   @Override
 106  
   public String toString() {
 107  436
     return "(vtx=" + vertexCount + ",finVtx=" +
 108  
         finishedVertexCount + ",edges=" + edgeCount + ",msgCount=" +
 109  
         messageCount + ",haltComputation=" + haltComputation + ")";
 110  
   }
 111  
 }