Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1996 bench #2149

Merged
merged 12 commits into from
Mar 21, 2018
4 changes: 3 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ add_library( steem_chain

util/reward.cpp
util/impacted.cpp
util/advanced_benchmark_dumper.cpp

${HEADERS}
)

target_link_libraries( steem_chain steem_jsonball steem_protocol fc chainbase steem_schema ${PATCH_MERGE_LIB} )
target_link_libraries( steem_chain steem_jsonball steem_protocol fc chainbase steem_schema appbase
${PATCH_MERGE_LIB} )
target_include_directories( steem_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )

Expand Down
164 changes: 158 additions & 6 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void database::open( const open_args& args )
init_genesis( args.initial_supply );
});

_benchmark_dumper.set_enabled( args.benchmark_is_enabled );

_block_log.open( args.data_dir / "block_log" );

auto log_head = _block_log.head();
Expand Down Expand Up @@ -916,12 +918,12 @@ void database::notify_pre_apply_operation( operation_notification& note )
note.trx_in_block = _current_trx_in_block;
note.op_in_trx = _current_op_in_trx;

STEEM_TRY_NOTIFY( pre_apply_operation, note )
STEEM_TRY_NOTIFY( _pre_apply_operation, note )
}

void database::notify_post_apply_operation( const operation_notification& note )
{
STEEM_TRY_NOTIFY( post_apply_operation, note )
STEEM_TRY_NOTIFY( _post_apply_operation, note )
}

inline const void database::push_virtual_operation( const operation& op, bool force )
Expand All @@ -943,22 +945,22 @@ inline const void database::push_virtual_operation( const operation& op, bool fo

void database::notify_applied_block( const signed_block& block )
{
STEEM_TRY_NOTIFY( applied_block, block )
STEEM_TRY_NOTIFY( _applied_block, block )
}

void database::notify_on_pending_transaction( const signed_transaction& tx )
{
STEEM_TRY_NOTIFY( on_pending_transaction, tx )
STEEM_TRY_NOTIFY( _on_pending_transaction, tx )
}

void database::notify_on_pre_apply_transaction( const signed_transaction& tx )
{
STEEM_TRY_NOTIFY( on_pre_apply_transaction, tx )
STEEM_TRY_NOTIFY( _on_pre_apply_transaction, tx )
}

void database::notify_on_applied_transaction( const signed_transaction& tx )
{
STEEM_TRY_NOTIFY( on_applied_transaction, tx )
STEEM_TRY_NOTIFY( _on_applied_transaction, tx )
}

account_name_type database::get_scheduled_witness( uint32_t slot_num )const
Expand Down Expand Up @@ -3010,10 +3012,160 @@ void database::apply_operation(const operation& op)
{
operation_notification note(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 <typename TFunction> struct fcall {};

template <typename TResult, typename... TArgs>
struct fcall<TResult(TArgs...)>
{
using TNotification = std::function<TResult(TArgs...)>;

fcall() = default;
fcall(const TNotification& func, util::advanced_benchmark_dumper& dumper,
const abstract_plugin& plugin, const std::string& item_name)
: _func(func), _benchmark_dumper(dumper), _plugin(plugin)
{
_name = plugin.get_name() + "--->" + item_name;
}

void operator () (TArgs&&... args)
{
if (_benchmark_dumper.is_enabled())
_benchmark_dumper.begin();

_func(std::forward<TArgs>(args)...);

if (_benchmark_dumper.is_enabled())
_benchmark_dumper.end(_name);
}

private:
TNotification _func;
util::advanced_benchmark_dumper& _benchmark_dumper;
const abstract_plugin& _plugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, this isn't needed anywhere. Is there a reason we are saving the reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is: for future uses - but ofkoz you are right here - I removed this member.

std::string _name;
};

template <typename TResult, typename... TArgs>
struct fcall<std::function<TResult(TArgs...)>>
: public fcall<TResult(TArgs...)>
{
typedef fcall<TResult(TArgs...)> TBase;
using TBase::TBase;
};

template <typename TSignal, typename TNotification>
boost::signals2::connection database::connect_impl( TSignal& signal, const TNotification& func,
const abstract_plugin& plugin, int32_t group, const std::string& item_name )
{
fcall<TNotification> fcall_wrapper(func,_benchmark_dumper,plugin,item_name);

if (group == -1)
return signal.connect(fcall_wrapper);
else
return signal.connect(group, fcall_wrapper);
}

template< bool IS_PRE_OPERATION >
boost::signals2::connection database::any_apply_operation_proxy_impl( const operation_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
auto complex_func = [this, func, &plugin]( const operation_notification& o )
{
std::string name;

if (_benchmark_dumper.is_enabled())
{
if( _my->_evaluator_registry.is_evaluator( o.op ) )
name = _benchmark_dumper.generate_desc< IS_PRE_OPERATION >( plugin.get_name(), _my->_evaluator_registry.get_evaluator( o.op ).get_name( o.op ) );
else
name = util::advanced_benchmark_dumper::get_virtual_operation_name();

_benchmark_dumper.begin();
}

func( o );

if (_benchmark_dumper.is_enabled())
_benchmark_dumper.end( 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);
}
}

boost::signals2::connection database::pre_apply_operation_proxy( const operation_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return any_apply_operation_proxy_impl< true/*IS_PRE_OPERATION*/ >( func, plugin, group );
}

boost::signals2::connection database::post_apply_operation_proxy( const operation_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return any_apply_operation_proxy_impl< false/*IS_PRE_OPERATION*/ >( func, plugin, group );
}

boost::signals2::connection database::on_pending_transaction_proxy( const transaction_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_on_pending_transaction, func, plugin, group, "@transaction");
}

boost::signals2::connection database::on_pre_apply_transaction_proxy( const transaction_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_on_pre_apply_transaction, func, plugin, group, "->transaction");
}

boost::signals2::connection database::on_applied_transaction_proxy( const transaction_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_on_pre_apply_transaction, func, plugin, group, "<-transaction");
}

boost::signals2::connection database::applied_block_proxy( const block_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_applied_block, func, plugin, group, "<-block");
}

boost::signals2::connection database::on_reindex_start_proxy(const on_reindex_start_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_on_reindex_start, func, plugin, group, "->reindex");
}

boost::signals2::connection database::on_reindex_done_proxy(const on_reindex_done_notification_t& func,
const abstract_plugin& plugin, int32_t group )
{
return connect_impl(_on_reindex_done, func, plugin, group, "<-reindex");
}

const witness_object& database::validate_block_header( uint32_t skip, const signed_block& next_block )const
{ try {
FC_ASSERT( head_block_id() == next_block.previous, "", ("head_block_id",head_block_id())("next.prev",next_block.previous) );
Expand Down
Loading