Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PartitionStats |
|
| 1.0;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.partition; | |
20 | ||
21 | import java.io.DataInput; | |
22 | import java.io.DataOutput; | |
23 | import java.io.IOException; | |
24 | ||
25 | import org.apache.hadoop.io.Writable; | |
26 | ||
27 | /** | |
28 | * Used to keep track of statistics of every {@link Partition}. Contains no | |
29 | * actual partition data, only the statistics. | |
30 | */ | |
31 | public class PartitionStats implements Writable { | |
32 | /** Id of partition to keep stats for */ | |
33 | 654 | private int partitionId = -1; |
34 | /** Vertices in this partition */ | |
35 | 654 | private long vertexCount = 0; |
36 | /** Finished vertices in this partition */ | |
37 | 654 | private long finishedVertexCount = 0; |
38 | /** Edges in this partition */ | |
39 | 654 | private long edgeCount = 0; |
40 | ||
41 | /** | |
42 | * Default constructor for reflection. | |
43 | */ | |
44 | 872 | public PartitionStats() { } |
45 | ||
46 | /** | |
47 | * Constructor with the initial stats. | |
48 | * | |
49 | * @param partitionId Partition count. | |
50 | * @param vertexCount Vertex count. | |
51 | * @param finishedVertexCount Finished vertex count. | |
52 | * @param edgeCount Edge count. | |
53 | */ | |
54 | public PartitionStats(int partitionId, | |
55 | long vertexCount, | |
56 | long finishedVertexCount, | |
57 | 218 | long edgeCount) { |
58 | 218 | this.partitionId = partitionId; |
59 | 218 | this.vertexCount = vertexCount; |
60 | 218 | this.finishedVertexCount = finishedVertexCount; |
61 | 218 | this.edgeCount = edgeCount; |
62 | 218 | } |
63 | ||
64 | /** | |
65 | * Set the partition id. | |
66 | * | |
67 | * @param partitionId New partition id. | |
68 | */ | |
69 | public void setPartitionId(int partitionId) { | |
70 | 0 | this.partitionId = partitionId; |
71 | 0 | } |
72 | ||
73 | /** | |
74 | * Get partition id. | |
75 | * | |
76 | * @return Partition id. | |
77 | */ | |
78 | public int getPartitionId() { | |
79 | 202 | return partitionId; |
80 | } | |
81 | ||
82 | /** | |
83 | * Increment the vertex count by one. | |
84 | */ | |
85 | public void incrVertexCount() { | |
86 | 2373 | ++vertexCount; |
87 | 2373 | } |
88 | ||
89 | /** | |
90 | * Get the vertex count. | |
91 | * | |
92 | * @return Vertex count. | |
93 | */ | |
94 | public long getVertexCount() { | |
95 | 614 | return vertexCount; |
96 | } | |
97 | ||
98 | /** | |
99 | * Increment the finished vertex count by one. | |
100 | */ | |
101 | public void incrFinishedVertexCount() { | |
102 | 546 | ++finishedVertexCount; |
103 | 546 | } |
104 | ||
105 | /** | |
106 | * Get the finished vertex count. | |
107 | * | |
108 | * @return Finished vertex count. | |
109 | */ | |
110 | public long getFinishedVertexCount() { | |
111 | 218 | return finishedVertexCount; |
112 | } | |
113 | ||
114 | /** | |
115 | * Add edges to the edge count. | |
116 | * | |
117 | * @param edgeCount Number of edges to add. | |
118 | */ | |
119 | public void addEdgeCount(long edgeCount) { | |
120 | 2373 | this.edgeCount += edgeCount; |
121 | 2373 | } |
122 | ||
123 | /** | |
124 | * Get the edge count. | |
125 | * | |
126 | * @return Edge count. | |
127 | */ | |
128 | public long getEdgeCount() { | |
129 | 606 | return edgeCount; |
130 | } | |
131 | ||
132 | @Override | |
133 | public void readFields(DataInput input) throws IOException { | |
134 | 218 | partitionId = input.readInt(); |
135 | 218 | vertexCount = input.readLong(); |
136 | 218 | finishedVertexCount = input.readLong(); |
137 | 218 | edgeCount = input.readLong(); |
138 | 218 | } |
139 | ||
140 | @Override | |
141 | public void write(DataOutput output) throws IOException { | |
142 | 218 | output.writeInt(partitionId); |
143 | 218 | output.writeLong(vertexCount); |
144 | 218 | output.writeLong(finishedVertexCount); |
145 | 218 | output.writeLong(edgeCount); |
146 | 218 | } |
147 | ||
148 | @Override | |
149 | public String toString() { | |
150 | 0 | return "(id=" + partitionId + ",vtx=" + vertexCount + ",finVtx=" + |
151 | finishedVertexCount + ",edges=" + edgeCount + ")"; | |
152 | } | |
153 | } |