From 601c5f9b3ac7b914d0dbe441514d4644b3a9cd98 Mon Sep 17 00:00:00 2001 From: Roman Mandeleil Date: Fri, 6 Feb 2015 10:34:42 +0200 Subject: [PATCH] Measure block execution time --- .../org/ethereum/core/BlockchainImpl.java | 5 +++++ .../java/org/ethereum/manager/AdminInfo.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java index ef2761bf..250d0174 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java @@ -327,6 +327,7 @@ public class BlockchainImpl implements Blockchain { private List applyBlock(Block block) { + long saveTime = System.nanoTime(); int i = 1; long totalGasUsed = 0; List 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; } diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java b/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java index 70e41b6e..ac638eaf 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/AdminInfo.java @@ -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 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 getBlockExecTime(){ + return blockExecTime; + } }