From 8c096954f29ef2bad6e8bdce26320828876bca0a Mon Sep 17 00:00:00 2001 From: mtrela Date: Fri, 26 Jan 2018 14:37:32 +0100 Subject: [PATCH] Issue #1996 - two logs. --- libraries/chain/database.cpp | 8 +-- .../chain/util/advanced_benchmark_dumper.hpp | 63 +++++++++++++------ .../chain/util/advanced_benchmark_dumper.cpp | 28 +++++++-- libraries/fc | 2 +- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 232bc9957d..4ad4dc601f 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -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() ); } 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 730067dff3..85ee6758aa 100644 --- a/libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp +++ b/libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp @@ -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: @@ -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: @@ -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; } @@ -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) ) + diff --git a/libraries/chain/util/advanced_benchmark_dumper.cpp b/libraries/chain/util/advanced_benchmark_dumper.cpp index af30efc231..d2ca09d4af 100644 --- a/libraries/chain/util/advanced_benchmark_dumper.cpp +++ b/libraries/chain/util/advanced_benchmark_dumper.cpp @@ -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::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 ) @@ -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 ) { @@ -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 diff --git a/libraries/fc b/libraries/fc index a285209b51..064db8f729 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit a285209b51734521c267df8ffd08664deddadec4 +Subproject commit 064db8f7299dcb8f6332c21cb2cad4a5dac8c1dc