Add profiling to block and tx processing

This commit is contained in:
warptangent 2015-02-11 15:55:53 -08:00
parent ce71abd0fe
commit 3676ac5841
No known key found for this signature in database
GPG key ID: 0E490BEBFBE4E92D
2 changed files with 48 additions and 0 deletions

View file

@ -28,6 +28,7 @@
#include "cryptonote_core/blockchain_db.h" #include "cryptonote_core/blockchain_db.h"
#include "cryptonote_format_utils.h" #include "cryptonote_format_utils.h"
#include "profile_tools.h"
using epee::string_tools::pod_to_hex; using epee::string_tools::pod_to_hex;
@ -73,18 +74,29 @@ uint64_t BlockchainDB::add_block( const block& blk
, const std::vector<transaction>& txs , const std::vector<transaction>& txs
) )
{ {
TIME_MEASURE_START(time1);
crypto::hash blk_hash = get_block_hash(blk); crypto::hash blk_hash = get_block_hash(blk);
TIME_MEASURE_FINISH(time1);
time_blk_hash += time1;
// call out to subclass implementation to add the block & metadata // call out to subclass implementation to add the block & metadata
time1 = epee::misc_utils::get_tick_count();
add_block(blk, block_size, cumulative_difficulty, coins_generated); add_block(blk, block_size, cumulative_difficulty, coins_generated);
TIME_MEASURE_FINISH(time1);
time_add_block1 += time1;
// call out to add the transactions // call out to add the transactions
time1 = epee::misc_utils::get_tick_count();
add_transaction(blk_hash, blk.miner_tx); add_transaction(blk_hash, blk.miner_tx);
for (const transaction& tx : txs) for (const transaction& tx : txs)
{ {
add_transaction(blk_hash, tx); add_transaction(blk_hash, tx);
} }
TIME_MEASURE_FINISH(time1);
time_add_transaction += time1;
++num_calls;
return height(); return height();
} }
@ -119,4 +131,30 @@ void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
remove_transaction_data(tx_hash, tx); remove_transaction_data(tx_hash, tx);
} }
void BlockchainDB::reset_stats()
{
num_calls = 0;
time_blk_hash = 0;
time_add_block1 = 0;
time_add_transaction = 0;
}
void BlockchainDB::show_stats()
{
LOG_PRINT_L1(ENDL
<< "*********************************"
<< ENDL
<< "num_calls: " << num_calls
<< ENDL
<< "time_blk_hash: " << time_blk_hash << "ms"
<< ENDL
<< "time_add_block1: " << time_add_block1 << "ms"
<< ENDL
<< "time_add_transaction: " << time_add_transaction << "ms"
<< ENDL
<< "*********************************"
<< ENDL
);
}
} // namespace cryptonote } // namespace cryptonote

View file

@ -301,12 +301,22 @@ private:
// helper function to remove transaction from blockchain // helper function to remove transaction from blockchain
void remove_transaction(const crypto::hash& tx_hash); void remove_transaction(const crypto::hash& tx_hash);
uint64_t num_calls = 0;
uint64_t time_blk_hash = 0;
uint64_t time_add_block1 = 0;
uint64_t time_add_transaction = 0;
public: public:
// virtual dtor // virtual dtor
virtual ~BlockchainDB() { }; virtual ~BlockchainDB() { };
// reset profiling stats
void reset_stats();
// show profiling stats
void show_stats();
// open the db at location <filename>, or create it if there isn't one. // open the db at location <filename>, or create it if there isn't one.
virtual void open(const std::string& filename) = 0; virtual void open(const std::string& filename) = 0;