Skip to content

Commit

Permalink
parialt commit (add next signals connect proxy)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkochanowicz committed Feb 9, 2018
1 parent 2aae90e commit 523d7ca
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 39 deletions.
79 changes: 54 additions & 25 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void database::open( const open_args& args )
init_genesis( args.initial_supply );
});

benchmark_dumper.set_enabled( args.benchmark_is_enabled );
_benchmark_dumper.set_enabled( args.benchmark_is_enabled );

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

Expand Down Expand Up @@ -160,6 +160,8 @@ uint32_t database::reindex( const open_args& args )
bool reindex_success = false;
uint32_t last_block_number = 0; // result

on_reindex_done_connect([&](bool ,uint32_t ) {});

BOOST_SCOPE_EXIT(this_,&reindex_success,&last_block_number) {
STEEM_TRY_NOTIFY(this_->_on_reindex_done, reindex_success, last_block_number);
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -3005,62 +3007,89 @@ void database::apply_operation(const operation& op)
operation_notification note(op);
notify_pre_apply_operation( note );

if( benchmark_dumper.is_enabled() )
benchmark_dumper.begin();
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 ) );
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 TSignal, typename TNotification>
boost::signals2::connection database::connect_impl( TSignal& signal, const TNotification& complex_func,
int32_t group )
{
if( group == -1 )
return signal.connect( complex_func );
else
return signal.connect( group, complex_func );
}

template <typename TSignal, typename TNotification, typename... TArgs>
boost::signals2::connection database::on_apply_proxy_impl( TSignal& signal, const TNotification& func,
int32_t group, const std::string& plugin_name, const std::string& item_name )
{
auto complex_func = [=] (TArgs... args)
{
if( _benchmark_dumper.is_enabled() )
_benchmark_dumper.begin();

func( o );

if( _benchmark_dumper.is_enabled() )
_benchmark_dumper.end( plugin_name, item_name );
};
}

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 )
boost::signals2::connection database::any_apply_operation_proxy_impl( const operation_notification_t& func,
int32_t group, const std::string& plugin_name )
{
auto complex_func = [=]( const operation_notification& o )
{
if( benchmark_dumper.is_enabled() )
benchmark_dumper.begin();
if( _benchmark_dumper.is_enabled() )
_benchmark_dumper.begin();

func( o );

if( benchmark_dumper.is_enabled() )
if( _benchmark_dumper.is_enabled() )
{
if( _my->_evaluator_registry.is_evaluator( o.op ) )
benchmark_dumper.end( benchmark_dumper.generate_desc< IS_PRE_OPERATION >( name, _my->_evaluator_registry.get_evaluator( o.op ).get_name( o.op ) ) );
_benchmark_dumper.end( _benchmark_dumper.generate_desc< IS_PRE_OPERATION >( name, _my->_evaluator_registry.get_evaluator( o.op ).get_name( o.op ) ) );
else
benchmark_dumper.end( util::advanced_benchmark_dumper::get_virtual_operation_name() );
_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 );
}
return connect_impl(pre_apply_operation, complex_func, group);
else
{
if( group == -1 )
return post_apply_operation.connect( complex_func );
else
return post_apply_operation.connect( group, complex_func );
}
return connect_impl(post_apply_operation, complex_func, group);
}

boost::signals2::connection database::pre_apply_operation_proxy( const t_operation_notification& func, int32_t group, const std::string& name )
boost::signals2::connection database::pre_apply_operation_proxy( const operation_notification_t& 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 )
boost::signals2::connection database::post_apply_operation_proxy( const operation_notification_t& func, int32_t group, const std::string& name )
{
return any_apply_operation_proxy_impl< false/*IS_PRE_OPERATION*/ >( func, group, name );
}

boost::signals2::connection database::on_pre_apply_transaction_proxy( const transaction_notification_t& func, int32_t group , const std::string& name )
{

}

boost::signals2::connection database::applied_block_proxy( const block_notification_t& func, int32_t group , const std::string& name )
{

}

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
22 changes: 18 additions & 4 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,31 @@ 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&) >;
using operation_notification_t = std::function< void(const operation_notification&) >;
using transaction_notification_t = std::function< void(const signed_transaction&) >;
using block_notification_t = std::function< void(const signed_block&) >;

private:

template <typename TSignal,
typename TNotification = std::function<typename TSignal::signature_type>,
typename... TArgs>
boost::signals2::connection connect_impl( TSignal& signal, const TNotification& func, int32_t group,
const std::string& plugin_name = "", const std::string& item_name = "" );

template <typename TSignal, typename TNotification, typename... TArgs>
boost::signals2::connection on_apply_proxy_impl( TSignal& signal, const TNotification& func, int32_t group,
const std::string& plugin_name = "", const std::string& item_name = "" );

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 );
boost::signals2::connection any_apply_operation_proxy_impl( const operation_notification_t& func, int32_t group, const std::string& plugin_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" );
boost::signals2::connection pre_apply_operation_proxy( const operation_notification_t& func, int32_t group = -1, const std::string& plugin_name = "unknown_name" );
boost::signals2::connection post_apply_operation_proxy( const operation_notification_t& func, int32_t group = -1, const std::string& plugin_name = "unknown_name" );
boost::signals2::connection on_pre_apply_transaction_proxy( const transaction_notification_t& func, int32_t group = -1, const std::string& plugin_name = "unknown_name" );
boost::signals2::connection applied_block_proxy( const block_notification_t& func, int32_t group = -1, const std::string& plugin_name = "unknown_name" );

/**
* This signal is emitted after all operations and virtual operation for a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,30 @@

#include <sys/time.h>

#include <utility>

namespace steem { namespace chain { namespace util {

template <typename T>
struct is_associative_cntr : public std::false_type {};
template <typename... TArgs>
struct is_associative_cntr<std::set<TArgs...>> : public std::true_type {};
template <typename... TArgs>
struct is_associative_cntr<std::multiset<TArgs...>> : public std::true_type {};
template <typename... TArgs>
struct is_associative_cntr<std::map<TArgs...>> : public std::true_type {};
template <typename... TArgs>
struct is_associative_cntr<std::multimap<TArgs...>> : public std::true_type {};

template <typename TCntr,
typename T = decltype(std::declval<TCntr>().emplace(std::declval<typename TCntr::value_type>()))>
struct enable_if_associative_cntr
: public std::enable_if<is_associative_cntr<TCntr>::value, T> {};

template <typename TCntr, typename T = typename TCntr::iterator>
struct enable_if_not_associative_cntr
: public std::enable_if<!is_associative_cntr<TCntr>::value, T> {};

class advanced_benchmark_dumper
{
public:
Expand Down Expand Up @@ -46,6 +68,14 @@ class advanced_benchmark_dumper
total_info( uint64_t _total_time ): total_time( _total_time ) {}

void inc( uint64_t _time ) { total_time += _time; }

template <typename... TArgs, typename TType = COLLECTION>
typename enable_if_associative_cntr<TType>::type add_item(TArgs&&... args)
{ return items.emplace(std::forward<TArgs>(args)...); }

template <typename... TArgs, typename TType = COLLECTION>
typename enable_if_not_associative_cntr<TType>::type add_item(TArgs&&... args)
{ return items.emplace_back(std::forward<TArgs>(args)...); }
};

private:
Expand Down Expand Up @@ -90,6 +120,7 @@ class advanced_benchmark_dumper
void begin();
template< bool APPLY_CONTEXT = false >
void end( const std::string& str );
void end( const std::string& plugin_name, const std::string& item_name );

void dump();
};
Expand Down
24 changes: 15 additions & 9 deletions libraries/chain/util/advanced_benchmark_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ namespace steem { namespace chain { namespace util {
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 = info.items.emplace( item( APPLY_CONTEXT ? ( apply_context_name + str ) : str, time ) );
uint64_t time = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch() ).count() - time_begin;
auto res = info.add_item( APPLY_CONTEXT ? (apply_context_name + str) : str, time );
//auto res = info.items.emplace( APPLY_CONTEXT ? (apply_context_name + str) : str, time );
if( !res.second )
res.first->inc( time );

Expand All @@ -46,6 +48,12 @@ namespace steem { namespace chain { namespace util {
}
}

void advanced_benchmark_dumper::end( const std::string& plugin_name, const std::string& item_name )
{
std::string str(plugin_name + "::" + item_name);
end<false>(str);
}

template void advanced_benchmark_dumper::end< true >( const std::string& str );
template void advanced_benchmark_dumper::end< false >( const std::string& str );

Expand All @@ -67,13 +75,11 @@ namespace steem { namespace chain { namespace util {
void advanced_benchmark_dumper::dump()
{
total_info< std::multiset< ritem > > rinfo( info.total_time );
std::for_each
(
info.items.begin(), info.items.end(), [&]( const item& obj )
{
rinfo.items.insert( ritem( obj.op_name, obj.time ) );
}
);
std::for_each(info.items.begin(), info.items.end(), [&rinfo]( const item& obj )
{
//rinfo.items.emplace( obj.op_name, obj.time );
rinfo.add_item( obj.op_name, obj.time );
});

dump_impl( info, file_name );
dump_impl( rinfo, "r_" + file_name );
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/chain/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class chain_plugin_impl
bool readonly = false;
bool check_locks = false;
bool validate_invariants = false;
bool dump_memory_details = false;
bool benchmark_is_enabled =false;
uint32_t stop_replay_at = 0;
uint32_t benchmark_interval = 0;
Expand Down

0 comments on commit 523d7ca

Please sign in to comment.