-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
159a143
commit 5717be7
Showing
7 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
libraries/chain/include/steem/chain/util/advanced_benchmark_dumper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include <fc/time.hpp> | ||
#include <fc/variant.hpp> | ||
#include <fc/reflect/variant.hpp> | ||
#include <fc/exception/exception.hpp> | ||
#include <fc/io/json.hpp> | ||
|
||
#include <sys/time.h> | ||
|
||
namespace steem { namespace chain { namespace util { | ||
|
||
class advanced_benchmark_dumper | ||
{ | ||
public: | ||
|
||
class item | ||
{ | ||
public: | ||
|
||
std::string op_name; | ||
mutable uint64_t 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 change_time( uint64_t _time ) const | ||
{ | ||
time += _time; | ||
} | ||
}; | ||
|
||
private: | ||
|
||
static uint32_t cnt; | ||
|
||
bool enabled = false; | ||
|
||
uint32_t flush_cnt = 0; | ||
uint32_t flush_max = 50000; | ||
|
||
uint64_t time_begin = 0; | ||
|
||
std::string file_name; | ||
|
||
std::set< item > items; | ||
|
||
public: | ||
|
||
advanced_benchmark_dumper(); | ||
~advanced_benchmark_dumper(); | ||
|
||
void set_enabled( bool val ) { enabled = val; } | ||
bool is_enabled() { return enabled; } | ||
|
||
void begin(); | ||
void end( const std::string& str ); | ||
void dump(); | ||
}; | ||
|
||
} } } // steem::chain::util | ||
|
||
FC_REFLECT( steem::chain::util::advanced_benchmark_dumper::item, (op_name)(time) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
#include <steem/chain/util/advanced_benchmark_dumper.hpp> | ||
#include <chrono> | ||
|
||
namespace steem { namespace chain { namespace util { | ||
|
||
uint32_t advanced_benchmark_dumper::cnt = 0; | ||
|
||
advanced_benchmark_dumper::advanced_benchmark_dumper() | ||
{ | ||
if( cnt == 0 ) | ||
file_name = "advanced_benchmark.json"; | ||
else | ||
file_name = std::to_string( cnt ) + "_advanced_benchmark.json"; | ||
|
||
++cnt; | ||
} | ||
|
||
advanced_benchmark_dumper::~advanced_benchmark_dumper() | ||
{ | ||
dump(); | ||
} | ||
|
||
void advanced_benchmark_dumper::begin() | ||
{ | ||
time_begin = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch() ).count(); | ||
} | ||
|
||
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 ) ); | ||
if( !res.second ) | ||
res.first->change_time( time ); | ||
|
||
++flush_cnt; | ||
if( flush_cnt >= flush_max ) | ||
{ | ||
flush_cnt = 0; | ||
dump(); | ||
} | ||
} | ||
|
||
void advanced_benchmark_dumper::dump() | ||
{ | ||
const fc::path path( file_name.c_str() ); | ||
try | ||
{ | ||
fc::json::save_to_file( items, path ); | ||
} | ||
catch ( const fc::exception& except ) | ||
{ | ||
elog( "error writing benchmark data to file ${filename}: ${error}", | ||
( "filename", path )("error", except.to_detail_string() ) ); | ||
} | ||
} | ||
|
||
} } } // steem::chain::util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters