Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Add opcode benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jun 5, 2019
1 parent 25372c6 commit 932fdd9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
13 changes: 13 additions & 0 deletions libethereum/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <libdevcore/TrieHash.h>
#include <libethcore/BlockHeader.h>
#include <libethcore/Exceptions.h>
#include <libevm/LegacyVM.h>

#include <boost/exception/errinfo_nested_exception.hpp>
#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -707,6 +708,18 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&

performanceLogger.onStageFinished("enactment");

if (_block.info.number() % 10000 == 0)
{
std::string filename = "metrics_to_" + toString(_block.info.number());
std::ofstream f(filename);
f << "[";
for (auto const& meter : g_measurements)
f << "{\"Num\":" << meter.count << ",\"Time\":" << meter.time.count() << "},";
f.seekp(-1, ios_base::cur);
f << "]";
clog(VerbosityInfo, "chain") << "Dumped stats to " << filename;
}

#if ETH_PARANOIA
checkConsistency();
#endif // ETH_PARANOIA
Expand Down
2 changes: 2 additions & 0 deletions libethereum/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <libdevcore/DBFactory.h>
#include <libdevcore/TrieHash.h>
#include <libevm/VMFactory.h>
#include <libevm/LegacyVM.h>
#include <boost/filesystem.hpp>
#include <boost/timer.hpp>

Expand Down Expand Up @@ -610,6 +611,7 @@ std::pair<ExecutionResult, TransactionReceipt> State::execute(EnvInfo const& _en
#endif
u256 const startGasUsed = _envInfo.gasUsed();
bool const statusCode = executeTransaction(e, _t, onOp);
g_currentOp = 0;

bool removeEmptyAccounts = false;
switch (_p)
Expand Down
4 changes: 4 additions & 0 deletions libevm/LegacyVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ using namespace std;
using namespace dev;
using namespace dev::eth;

std::array<OpcodeMeter, 256> dev::eth::g_measurements{};
std::chrono::high_resolution_clock::time_point dev::eth::g_startTime;
int dev::eth::g_currentOp = 0;

uint64_t LegacyVM::memNeed(u256 const& _offset, u256 const& _size)
{
return toInt63(_size ? u512(_offset) + _size : u512(0));
Expand Down
11 changes: 11 additions & 0 deletions libevm/LegacyVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,16 @@ class LegacyVM: public VMFace
#endif
};

struct OpcodeMeter
{
uint64_t count = 0;
std::chrono::high_resolution_clock::duration time{0};
};

extern std::array<OpcodeMeter, 256> g_measurements;

extern std::chrono::high_resolution_clock::time_point g_startTime;
extern int g_currentOp;

}
}
7 changes: 6 additions & 1 deletion libevm/LegacyVMConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ namespace dev
fetchInstruction(); \
goto* jumpTable[(int)m_OP];
#define CASE(name) \
name:
name: \
if (g_currentOp != 0) { \
g_measurements[g_currentOp].time += std::chrono::high_resolution_clock::now() - g_startTime; \
++g_measurements[g_currentOp].count; }\
g_currentOp = (int)m_OP; \
g_startTime = std::chrono::high_resolution_clock::now();
#define NEXT \
++m_PC; \
fetchInstruction(); \
Expand Down

0 comments on commit 932fdd9

Please sign in to comment.