From cb0b1e5827a802f2f709aa23f72338e34a1bd8f9 Mon Sep 17 00:00:00 2001 From: mtrela Date: Tue, 23 Jan 2018 14:00:06 +0100 Subject: [PATCH] Log is extended. --- libraries/chain/database.cpp | 55 +++++++++++++++++-- .../chain/include/steem/chain/database.hpp | 12 ++++ .../steem/chain/evaluator_registry.hpp | 46 ++++++++++++++-- .../chain/util/advanced_benchmark_dumper.hpp | 6 ++ .../chain/util/advanced_benchmark_dumper.cpp | 8 ++- .../account_statistics_plugin.cpp | 2 +- .../blockchain_statistics_plugin.cpp | 4 +- .../account_by_key/account_by_key_plugin.cpp | 4 +- .../account_history_plugin.cpp | 2 +- libraries/plugins/follow/follow_plugin.cpp | 4 +- .../market_history/market_history_plugin.cpp | 2 +- .../plugins/smt_test/smt_test_plugin.cpp | 4 +- libraries/plugins/tags/tags_plugin.cpp | 4 +- libraries/plugins/witness/witness_plugin.cpp | 2 +- 14 files changed, 131 insertions(+), 24 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 8e432fef97..232bc9957d 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -2991,18 +2991,65 @@ void database::apply_operation(const operation& op) notify_pre_apply_operation( note ); if( benchmark_dumper.is_enabled() ) - { benchmark_dumper.begin(); - } _my->_evaluator_registry.get_evaluator( op ).apply( op ); if( benchmark_dumper.is_enabled() ) + benchmark_dumper.end< true/*APPLY_CONTEXT*/ >( _my->_evaluator_registry.get_evaluator( op ).get_name( op ) ); + + notify_post_apply_operation( note ); +} + +template< bool IS_PRE_OPERATION > +boost::signals2::connection database::any_apply_operation_proxy_impl( const t_operation_notification& func, int32_t group, const std::string& name ) +{ + auto complex_func = [=]( const operation_notification& o ) { - benchmark_dumper.end( _my->_evaluator_registry.get_evaluator( op ).get_name( op ) ); + if( benchmark_dumper.is_enabled() ) + benchmark_dumper.begin(); + + func( o ); + + if( benchmark_dumper.is_enabled() ) + { + if( _my->_evaluator_registry.is_evaluator( o.op ) ) + { + std::string _name = IS_PRE_OPERATION ? "pre--->" : "post--->"; + _name += name; + _name += "--->"; + _name += _my->_evaluator_registry.get_evaluator( o.op ).get_name( o.op ); + benchmark_dumper.end( _name ); + } + else + benchmark_dumper.end( util::advanced_benchmark_dumper::get_virtual_operation_name() ); + } + }; + + if( IS_PRE_OPERATION ) + { + if( group == -1 ) + return pre_apply_operation.connect( complex_func ); + else + return pre_apply_operation.connect( group, complex_func ); + } + else + { + if( group == -1 ) + return post_apply_operation.connect( complex_func ); + else + return post_apply_operation.connect( group, complex_func ); } +} - notify_post_apply_operation( note ); +boost::signals2::connection database::pre_apply_operation_proxy( const t_operation_notification& func, int32_t group, const std::string& name ) +{ + return any_apply_operation_proxy_impl< true/*IS_PRE_OPERATION*/ >( func, group, name ); +} + +boost::signals2::connection database::post_apply_operation_proxy( const t_operation_notification& func, int32_t group, const std::string& name ) +{ + return any_apply_operation_proxy_impl< false/*IS_PRE_OPERATION*/ >( func, group, name ); } const witness_object& database::validate_block_header( uint32_t skip, const signed_block& next_block )const diff --git a/libraries/chain/include/steem/chain/database.hpp b/libraries/chain/include/steem/chain/database.hpp index b5ed07c2ee..f15cab07f9 100644 --- a/libraries/chain/include/steem/chain/database.hpp +++ b/libraries/chain/include/steem/chain/database.hpp @@ -232,6 +232,18 @@ namespace steem { namespace chain { fc::signal pre_apply_operation; fc::signal post_apply_operation; + using t_operation_notification = std::function< void(const operation_notification&) >; + + private: + + template< bool IS_PRE_OPERATION > + boost::signals2::connection any_apply_operation_proxy_impl( const t_operation_notification& func, int32_t group, const std::string& name ); + + public: + + boost::signals2::connection pre_apply_operation_proxy( const t_operation_notification& func, int32_t group = -1, const std::string& name = "unknown_name" ); + boost::signals2::connection post_apply_operation_proxy( const t_operation_notification& func, int32_t group = -1, const std::string& name = "unknown_name" ); + /** * This signal is emitted after all operations and virtual operation for a * block have been applied but before the get_applied_operations() are cleared. diff --git a/libraries/chain/include/steem/chain/evaluator_registry.hpp b/libraries/chain/include/steem/chain/evaluator_registry.hpp index cfb62e72f3..5f1c455c68 100644 --- a/libraries/chain/include/steem/chain/evaluator_registry.hpp +++ b/libraries/chain/include/steem/chain/evaluator_registry.hpp @@ -21,18 +21,54 @@ class evaluator_registry _op_evaluators[ OperationType::template tag< typename EvaluatorType::operation_type >::value ].reset( new EvaluatorType(_db, args...) ); } - evaluator& get_evaluator( const OperationType& op ) + private: + template< bool CHECK > + unique_ptr< evaluator >& get_evaluator_impl( const OperationType& op ) { + static unique_ptr< evaluator > empty; + int i_which = op.which(); uint64_t u_which = uint64_t( i_which ); + if( i_which < 0 ) - assert( "Negative operation tag" && false ); + { + if( CHECK ) + return empty; + else + assert( "Negative operation tag" && false ); + } + if( u_which >= _op_evaluators.size() ) - assert( "No registered evaluator for this operation" && false ); + { + if( CHECK ) + return empty; + else + assert( "No registered evaluator for this operation" && false ); + } + unique_ptr< evaluator >& eval = _op_evaluators[ u_which ]; + if( !eval ) - assert( "No registered evaluator for this operation" && false ); - return *eval; + { + if( CHECK ) + return empty; + else + assert( "No registered evaluator for this operation" && false ); + } + + return eval; + } + + public: + + bool is_evaluator( const OperationType& op ) + { + return get_evaluator_impl< true/*CHECK*/ >( op ) != false; + } + + evaluator& get_evaluator( const OperationType& op ) + { + return *get_evaluator_impl< false/*CHECK*/ >( op ); } std::vector< std::unique_ptr< evaluator > > _op_evaluators; diff --git a/libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp b/libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp index 8aeb58f64a..730067dff3 100644 --- a/libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp +++ b/libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp @@ -41,6 +41,8 @@ class advanced_benchmark_dumper private: static uint32_t cnt; + static std::string virtual_operation_name; + static std::string apply_context_name; bool enabled = false; @@ -58,11 +60,15 @@ class advanced_benchmark_dumper advanced_benchmark_dumper(); ~advanced_benchmark_dumper(); + static std::string& get_virtual_operation_name(){ return virtual_operation_name; } + void set_enabled( bool val ) { enabled = val; } bool is_enabled() { return enabled; } void begin(); + template< bool APPLY_CONTEXT = false > void end( const std::string& str ); + void dump(); }; diff --git a/libraries/chain/util/advanced_benchmark_dumper.cpp b/libraries/chain/util/advanced_benchmark_dumper.cpp index 2c79b22036..af30efc231 100644 --- a/libraries/chain/util/advanced_benchmark_dumper.cpp +++ b/libraries/chain/util/advanced_benchmark_dumper.cpp @@ -5,6 +5,8 @@ namespace steem { namespace chain { namespace util { uint32_t advanced_benchmark_dumper::cnt = 0; + std::string advanced_benchmark_dumper::virtual_operation_name = "virtual_operation"; + std::string advanced_benchmark_dumper::apply_context_name = "apply_context--->"; advanced_benchmark_dumper::advanced_benchmark_dumper() { @@ -26,10 +28,11 @@ namespace steem { namespace chain { namespace util { time_begin = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count(); } + template< bool APPLY_CONTEXT > void advanced_benchmark_dumper::end( const std::string& str ) { uint64_t time = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count() - time_begin; - std::pair< std::set< item >::iterator, bool > res = items.emplace( item( str, time ) ); + std::pair< std::set< item >::iterator, bool > res = items.emplace( item( APPLY_CONTEXT ? ( apply_context_name + str ) : str, time ) ); if( !res.second ) res.first->change_time( time ); @@ -41,6 +44,9 @@ namespace steem { namespace chain { namespace util { } } + template void advanced_benchmark_dumper::end< true >( const std::string& str ); + template void advanced_benchmark_dumper::end< false >( const std::string& str ); + void advanced_benchmark_dumper::dump() { const fc::path path( file_name.c_str() ); diff --git a/libraries/legacy_plugins/account_statistics/account_statistics_plugin.cpp b/libraries/legacy_plugins/account_statistics/account_statistics_plugin.cpp index 2067769018..db4b9d84cd 100644 --- a/libraries/legacy_plugins/account_statistics/account_statistics_plugin.cpp +++ b/libraries/legacy_plugins/account_statistics/account_statistics_plugin.cpp @@ -75,7 +75,7 @@ void account_statistics_plugin::plugin_initialize( const boost::program_options: { ilog( "account_stats plugin: plugin_initialize() begin" ); - database().post_apply_operation.connect( [&]( const operation_notification& o ){ _my->on_operation( o ); } ); + database().post_apply_operation_proxy( [&]( const operation_notification& o ){ _my->on_operation( o ); } ); ilog( "account_stats plugin: plugin_initialize() end" ); } FC_CAPTURE_AND_RETHROW() diff --git a/libraries/legacy_plugins/blockchain_statistics/blockchain_statistics_plugin.cpp b/libraries/legacy_plugins/blockchain_statistics/blockchain_statistics_plugin.cpp index 47e700d1a4..7c9ec65dff 100644 --- a/libraries/legacy_plugins/blockchain_statistics/blockchain_statistics_plugin.cpp +++ b/libraries/legacy_plugins/blockchain_statistics/blockchain_statistics_plugin.cpp @@ -429,8 +429,8 @@ void blockchain_statistics_plugin::plugin_initialize( const boost::program_optio chain::database& db = database(); db.applied_block.connect( [&]( const signed_block& b ){ _my->on_block( b ); } ); - db.pre_apply_operation.connect( [&]( const operation_notification& o ){ _my->pre_operation( o ); } ); - db.post_apply_operation.connect( [&]( const operation_notification& o ){ _my->post_operation( o ); } ); + db.pre_apply_operation_proxy( [&]( const operation_notification& o ){ _my->pre_operation( o ); }, -1, STEEM_BLOCKCHAIN_STATISTICS_PLUGIN_NAME ); + db.post_apply_operation_proxy( [&]( const operation_notification& o ){ _my->post_operation( o ); }, -1, STEEM_BLOCKCHAIN_STATISTICS_PLUGIN_NAME ); add_plugin_index< bucket_index >(db); diff --git a/libraries/plugins/account_by_key/account_by_key_plugin.cpp b/libraries/plugins/account_by_key/account_by_key_plugin.cpp index bbb7549ceb..ed3a65c9db 100644 --- a/libraries/plugins/account_by_key/account_by_key_plugin.cpp +++ b/libraries/plugins/account_by_key/account_by_key_plugin.cpp @@ -249,8 +249,8 @@ void account_by_key_plugin::plugin_initialize( const boost::program_options::var ilog( "Initializing account_by_key plugin" ); chain::database& db = appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db(); - my->pre_apply_connection = db.pre_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->pre_operation( o ); } ); - my->post_apply_connection = db.post_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->post_operation( o ); } ); + my->pre_apply_connection = db.pre_apply_operation_proxy( [&]( const operation_notification& o ){ my->pre_operation( o ); }, 0, STEEM_ACCOUNT_BY_KEY_PLUGIN_NAME ); + my->post_apply_connection = db.post_apply_operation_proxy( [&]( const operation_notification& o ){ my->post_operation( o ); }, 0, STEEM_ACCOUNT_BY_KEY_PLUGIN_NAME ); add_plugin_index< key_lookup_index >(db); } diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index cb0aff84c7..de6f319b85 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -220,7 +220,7 @@ void account_history_plugin::plugin_initialize( const boost::program_options::va { my = std::make_unique< detail::account_history_plugin_impl >(); - my->pre_apply_connection = my->_db.pre_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->on_operation(note); } ); + my->pre_apply_connection = my->_db.pre_apply_operation_proxy( [&]( const operation_notification& note ){ my->on_operation(note); }, 0, STEEM_ACCOUNT_HISTORY_PLUGIN_NAME ); typedef pair< account_name_type, account_name_type > pairstring; STEEM_LOAD_VALUE_SET(options, "account-history-track-account-range", my->_tracked_accounts, pairstring); diff --git a/libraries/plugins/follow/follow_plugin.cpp b/libraries/plugins/follow/follow_plugin.cpp index ff92b78849..5d207b6fad 100644 --- a/libraries/plugins/follow/follow_plugin.cpp +++ b/libraries/plugins/follow/follow_plugin.cpp @@ -349,8 +349,8 @@ void follow_plugin::plugin_initialize( const boost::program_options::variables_m // Add the registry to the database so the database can delegate custom ops to the plugin my->_db.set_custom_operation_interpreter( name(), _custom_operation_interpreter ); - my->pre_apply_connection = my->_db.pre_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->pre_operation( o ); } ); - my->post_apply_connection = my->_db.post_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->post_operation( o ); } ); + my->pre_apply_connection = my->_db.pre_apply_operation_proxy( [&]( const operation_notification& o ){ my->pre_operation( o ); }, 0, STEEM_FOLLOW_PLUGIN_NAME ); + my->post_apply_connection = my->_db.post_apply_operation_proxy( [&]( const operation_notification& o ){ my->post_operation( o ); }, 0, STEEM_FOLLOW_PLUGIN_NAME ); add_plugin_index< follow_index >( my->_db ); add_plugin_index< feed_index >( my->_db ); add_plugin_index< blog_index >( my->_db ); diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index 5a923ed660..fd31ac6d50 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -165,7 +165,7 @@ void market_history_plugin::plugin_initialize( const boost::program_options::var ilog( "market_history: plugin_initialize() begin" ); my = std::make_unique< detail::market_history_plugin_impl >(); - my->post_apply_connection = my->_db.post_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->update_market_histories( o ); } ); + my->post_apply_connection = my->_db.post_apply_operation_proxy( [&]( const operation_notification& o ){ my->update_market_histories( o ); }, 0, STEEM_MARKET_HISTORY_PLUGIN_NAME ); add_plugin_index< bucket_index >( my->_db ); add_plugin_index< order_history_index >( my->_db ); diff --git a/libraries/plugins/smt_test/smt_test_plugin.cpp b/libraries/plugins/smt_test/smt_test_plugin.cpp index a78e520c49..8f57036ae6 100644 --- a/libraries/plugins/smt_test/smt_test_plugin.cpp +++ b/libraries/plugins/smt_test/smt_test_plugin.cpp @@ -269,8 +269,8 @@ void smt_test_plugin::plugin_initialize( const boost::program_options::variables ilog( "Initializing smt_test plugin" ); chain::database& db = appbase::app().get_plugin< steem::plugins::chain::chain_plugin >().db(); - db.pre_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->pre_operation( o ); } ); - db.post_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->post_operation( o ); } ); + db.pre_apply_operation_proxy( [&]( const operation_notification& o ){ my->pre_operation( o ); }, 0, STEEM_SMT_TEST_PLUGIN_NAME ); + db.post_apply_operation_proxy( [&]( const operation_notification& o ){ my->post_operation( o ); }, 0, STEEM_SMT_TEST_PLUGIN_NAME ); // add_plugin_index< key_lookup_index >(db); } diff --git a/libraries/plugins/tags/tags_plugin.cpp b/libraries/plugins/tags/tags_plugin.cpp index f3a4b9c003..38be7c4ad7 100644 --- a/libraries/plugins/tags/tags_plugin.cpp +++ b/libraries/plugins/tags/tags_plugin.cpp @@ -506,8 +506,8 @@ void tags_plugin::plugin_initialize(const boost::program_options::variables_map& ilog("Intializing tags plugin" ); my = std::make_unique< detail::tags_plugin_impl >(); - my->pre_apply_connection = my->_db.pre_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->pre_operation( note ); } ); - my->post_apply_connection = my->_db.post_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->on_operation( note ); } ); + my->pre_apply_connection = my->_db.pre_apply_operation_proxy( [&]( const operation_notification& note ){ my->pre_operation( note ); }, 0, STEEM_TAGS_PLUGIN_NAME ); + my->post_apply_connection = my->_db.post_apply_operation_proxy( [&]( const operation_notification& note ){ my->on_operation( note ); }, 0, STEEM_TAGS_PLUGIN_NAME ); if( !options.at( "tags-skip-startup-update" ).as< bool >() ) { diff --git a/libraries/plugins/witness/witness_plugin.cpp b/libraries/plugins/witness/witness_plugin.cpp index b17cecd196..6a099b26a7 100644 --- a/libraries/plugins/witness/witness_plugin.cpp +++ b/libraries/plugins/witness/witness_plugin.cpp @@ -582,7 +582,7 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m } my->on_pre_apply_transaction_connection = my->_db.on_pre_apply_transaction.connect( 0, [&]( const signed_transaction& tx ){ my->pre_transaction( tx ); } ); - my->pre_apply_connection = my->_db.pre_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->pre_operation( note ); } ); + my->pre_apply_connection = my->_db.pre_apply_operation_proxy( [&]( const operation_notification& note ){ my->pre_operation( note ); }, 0, STEEM_WITNESS_PLUGIN_NAME ); my->applied_block_connection = my->_db.applied_block.connect( 0, [&]( const signed_block& b ){ my->on_block( b ); } ); add_plugin_index< account_bandwidth_index >( my->_db );