Skip to content

Commit

Permalink
Log is extended.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz-Trela committed Jan 23, 2018
1 parent 5717be7 commit cb0b1e5
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 24 deletions.
55 changes: 51 additions & 4 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ namespace steem { namespace chain {
fc::signal<void(const operation_notification&)> pre_apply_operation;
fc::signal<void(const operation_notification&)> 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.
Expand Down
46 changes: 41 additions & 5 deletions libraries/chain/include/steem/chain/evaluator_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,54 @@ class evaluator_registry
_op_evaluators[ OperationType::template tag< typename EvaluatorType::operation_type >::value ].reset( new EvaluatorType(_db, args...) );
}

evaluator<OperationType>& get_evaluator( const OperationType& op )
private:
template< bool CHECK >
unique_ptr< evaluator<OperationType> >& get_evaluator_impl( const OperationType& op )
{
static unique_ptr< evaluator<OperationType> > 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<OperationType> >& 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<OperationType>& get_evaluator( const OperationType& op )
{
return *get_evaluator_impl< false/*CHECK*/ >( op );
}

std::vector< std::unique_ptr< evaluator<OperationType> > > _op_evaluators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
};

Expand Down
8 changes: 7 additions & 1 deletion libraries/chain/util/advanced_benchmark_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -26,10 +28,11 @@ namespace steem { namespace chain { namespace util {
time_begin = std::chrono::duration_cast<std::chrono::milliseconds>( 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::milliseconds>( 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 );

Expand All @@ -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() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions libraries/plugins/account_by_key/account_by_key_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions libraries/plugins/follow/follow_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/market_history/market_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions libraries/plugins/smt_test/smt_test_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/plugins/tags/tags_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 >() )
{
Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/witness/witness_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit cb0b1e5

Please sign in to comment.