Measure block execution time

This commit is contained in:
Roman Mandeleil 2015-02-06 10:34:42 +02:00
parent 06c2d6ae73
commit 601c5f9b3a
2 changed files with 27 additions and 0 deletions

View File

@ -327,6 +327,7 @@ public class BlockchainImpl implements Blockchain {
private List<TransactionReceipt> applyBlock(Block block) {
long saveTime = System.nanoTime();
int i = 1;
long totalGasUsed = 0;
List<TransactionReceipt> receipts = new ArrayList<>();
@ -369,6 +370,10 @@ public class BlockchainImpl implements Blockchain {
if (block.getNumber() >= CONFIG.traceStartBlock())
repository.dumpState(block, totalGasUsed, 0, null);
long totalTime = System.nanoTime() - saveTime;
adminInfo.addBlockExecTime(totalTime);
logger.info("block: num: [{}] hash: [{}], executed after: [{}]nano", block.getNumber(), block.getShortHash(), totalTime);
return receipts;
}

View File

@ -3,6 +3,9 @@ package org.ethereum.manager;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* @author Roman Mandeleil
@ -14,6 +17,7 @@ public class AdminInfo {
private long startupTimeStamp;
private boolean consensus = true;
private List<Long> blockExecTime = new LinkedList<>();
@PostConstruct
@ -32,4 +36,22 @@ public class AdminInfo {
public void lostConsensus() {
consensus = false;
}
public void addBlockExecTime(long time){
blockExecTime.add(time);
}
public Long getExecAvg(){
long sum = 0;
for (int i = 0; i < blockExecTime.size(); ++i){
sum += blockExecTime.get(i);
}
return sum / blockExecTime.size();
}
public List<Long> getBlockExecTime(){
return blockExecTime;
}
}