Coverage Summary for Class: SyncStatistics (org.ethereum.sync)

Class Class, % Method, % Line, %
SyncStatistics 0% (0/1) 0% (0/11) 0% (0/22)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.sync; 21  22 /** 23  * Manages sync measurements 24  * 25  * @author Mikhail Kalinin 26  * @since 20.08.2015 27  */ 28 public class SyncStatistics { 29  private long updatedAt; 30  private long blocksCount; 31  private long headersCount; 32  private int headerBunchesCount; 33  34  // RSK new fields 35  private long statusCount; 36  private long getBlocksCount; 37  38  public SyncStatistics() { 39  reset(); 40  } 41  42  public void reset() { 43  updatedAt = System.currentTimeMillis(); 44  blocksCount = 0; 45  headersCount = 0; 46  headerBunchesCount = 0; 47  statusCount = 0; 48  getBlocksCount = 0; 49  } 50  51  // RSK new method 52  public void getBlock() { 53  getBlocksCount++; 54  fixCommon(1); 55  } 56  57  // RSK new method 58  public void addStatus() { 59  statusCount++; 60  fixCommon(1); 61  } 62  63  public void addBlocks(long cnt) { 64  blocksCount += cnt; 65  fixCommon(cnt); 66  } 67  68  public void addHeaders(long cnt) { 69  headerBunchesCount++; 70  headersCount += cnt; 71  fixCommon(cnt); 72  } 73  74  private void fixCommon(long cnt) { 75  updatedAt = System.currentTimeMillis(); 76  } 77  78  public long getBlocksCount() { 79  return blocksCount; 80  } 81  82  public long getHeadersCount() { 83  return headersCount; 84  } 85  86  public long secondsSinceLastUpdate() { 87  return (System.currentTimeMillis() - updatedAt) / 1000; 88  } 89  90  public int getHeaderBunchesCount() { 91  return headerBunchesCount; 92  } 93 }