Skip to content

Commit

Permalink
Issue #1996 - two logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz-Trela committed Jan 26, 2018
1 parent cb0b1e5 commit 8c09695
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 31 deletions.
8 changes: 1 addition & 7 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,13 +3014,7 @@ boost::signals2::connection database::any_apply_operation_proxy_impl( const t_op
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 );
}
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() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,38 @@ class advanced_benchmark_dumper
{
public:

class item
struct item
{
public:
std::string op_name;
mutable uint64_t time;

std::string op_name;
mutable uint64_t time;
item( std::string _op_name, uint64_t _time ): op_name( _op_name ), time( _time ) {}

item( std::string _op_name, uint64_t _time )
: op_name( _op_name ), time( _time )
{
bool operator<( const item& obj ) const { return op_name < obj.op_name; }
void inc( uint64_t _time ) const { time += _time; }
};

struct ritem
{
std::string op_name;
uint64_t time;

ritem( std::string _op_name, uint64_t _time ): op_name( _op_name ), time( _time ){}

}
bool operator<( const ritem& obj ) const { return time > obj.time; }
};

template< typename COLLECTION >
struct total_info
{
uint64_t total_time = 0;

bool operator<( const item& obj ) const
{
return op_name < obj.op_name;
}
COLLECTION items;// dla r musi tutaj byc list nie set

total_info(){}
total_info( uint64_t _total_time ): total_time( _total_time ) {}

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

private:
Expand All @@ -47,13 +57,16 @@ class advanced_benchmark_dumper
bool enabled = false;

uint32_t flush_cnt = 0;
uint32_t flush_max = 50000;
uint32_t flush_max = 500000;

uint64_t time_begin = 0;

std::string file_name;

std::set< item > items;
total_info< std::set< item > > info;

template< typename COLLECTION >
void dump_impl( const total_info< COLLECTION >& src, const std::string& src_file_name );

public:

Expand All @@ -62,6 +75,15 @@ class advanced_benchmark_dumper

static std::string& get_virtual_operation_name(){ return virtual_operation_name; }

template< bool IS_PRE_OPERATION >
std::string generate_desc( const std::string& desc1, const std::string& desc2 )
{
std::stringstream s;
s << ( IS_PRE_OPERATION ? "pre--->" : "post--->" ) << desc1 << "--->" << desc2;

return s.str();
}

void set_enabled( bool val ) { enabled = val; }
bool is_enabled() { return enabled; }

Expand All @@ -75,3 +97,8 @@ class advanced_benchmark_dumper
} } } // steem::chain::util

FC_REFLECT( steem::chain::util::advanced_benchmark_dumper::item, (op_name)(time) )
FC_REFLECT( steem::chain::util::advanced_benchmark_dumper::ritem, (op_name)(time) )

FC_REFLECT( steem::chain::util::advanced_benchmark_dumper::total_info< std::set< steem::chain::util::advanced_benchmark_dumper::item > >, (total_time)(items) )
FC_REFLECT( steem::chain::util::advanced_benchmark_dumper::total_info< std::multiset< steem::chain::util::advanced_benchmark_dumper::ritem > >, (total_time)(items) )

28 changes: 23 additions & 5 deletions libraries/chain/util/advanced_benchmark_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ namespace steem { namespace chain { namespace util {
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( APPLY_CONTEXT ? ( apply_context_name + str ) : str, time ) );
std::pair< std::set< item >::iterator, bool > res = info.items.emplace( item( APPLY_CONTEXT ? ( apply_context_name + str ) : str, time ) );
if( !res.second )
res.first->change_time( time );
res.first->inc( time );

info.inc( time );

++flush_cnt;
if( flush_cnt >= flush_max )
Expand All @@ -47,12 +49,13 @@ 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()
template< typename COLLECTION >
void advanced_benchmark_dumper::dump_impl( const total_info< COLLECTION >& src, const std::string& src_file_name )
{
const fc::path path( file_name.c_str() );
const fc::path path( src_file_name.c_str() );
try
{
fc::json::save_to_file( items, path );
fc::json::save_to_file( src, path );
}
catch ( const fc::exception& except )
{
Expand All @@ -61,4 +64,19 @@ 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 ) );
}
);

dump_impl( info, file_name );
dump_impl( rinfo, "r_" + file_name );
}

} } } // steem::chain::util
2 changes: 1 addition & 1 deletion libraries/fc
Submodule fc updated 1 files
+24 −0 include/fc/variant.hpp

0 comments on commit 8c09695

Please sign in to comment.