Skip to content

Commit

Permalink
Implement debug_busy_wait API steemit#1699
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Oct 24, 2017
1 parent 48eef81 commit 7efeecf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libraries/plugins/debug_node/debug_node_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class debug_node_api_impl
void debug_set_dev_key_prefix( std::string prefix );
void debug_mine( debug_mine_result& result, const debug_mine_args& args );
void debug_get_dev_key( get_dev_key_result& result, const get_dev_key_args& args );
void debug_busy_wait( debug_busy_wait_result& result, const debug_busy_wait_args& args );

std::shared_ptr< steemit::plugin::debug_node::debug_node_plugin > get_plugin();

steemit::app::application& app;
Expand Down Expand Up @@ -169,6 +171,25 @@ void debug_node_api_impl::debug_mine( debug_mine_result& result, const debug_min
return;
}

void debug_node_api_impl::debug_busy_wait( debug_busy_wait_result& result, const debug_busy_wait_args& args )
{
fc::time_point bt = fc::time_point::now();
fc::time_point qt = bt + fc::microseconds( args.microseconds );
fc::time_point et = bt;
uint64_t i = 0;
while( et < qt )
{
for( int j=0; j<100; j++ )
{
std::string i_str = std::to_string( i );
fc::sha256::hash( i_str.c_str(), i_str.size() );
++i;
}
et = fc::time_point::now();
}
result.hash_count = i;
}

uint32_t debug_node_api_impl::debug_push_blocks( const std::string& src_filename, uint32_t count, bool skip_validate_invariants )
{
if( count == 0 )
Expand Down Expand Up @@ -426,4 +447,11 @@ std::string debug_node_api::debug_get_json_schema()
return result;
}

debug_busy_wait_result debug_node_api::debug_busy_wait( debug_busy_wait_args args )
{
debug_busy_wait_result result;
my->debug_busy_wait( result, args );
return result;
}

} } } // steemit::plugin::debug_node
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ struct debug_mine_result
{
};

struct debug_busy_wait_args
{
uint64_t microseconds = 0;
};

struct debug_busy_wait_result
{
uint64_t hash_count = 0;
};

class debug_node_api
{
public:
Expand Down Expand Up @@ -135,6 +145,8 @@ class debug_node_api

std::string debug_get_json_schema();

debug_busy_wait_result debug_busy_wait( debug_busy_wait_args args );

std::shared_ptr< detail::debug_node_api_impl > my;
};

Expand All @@ -157,6 +169,14 @@ FC_REFLECT( steemit::plugin::debug_node::debug_mine_args,
FC_REFLECT( steemit::plugin::debug_node::debug_mine_result,
)

FC_REFLECT( steemit::plugin::debug_node::debug_busy_wait_args,
(microseconds)
)

FC_REFLECT( steemit::plugin::debug_node::debug_busy_wait_result,
(hash_count)
)

FC_API(steemit::plugin::debug_node::debug_node_api,
(debug_push_blocks)
(debug_generate_blocks)
Expand All @@ -176,4 +196,5 @@ FC_API(steemit::plugin::debug_node::debug_node_api,
(debug_set_dev_key_prefix)
(debug_get_dev_key)
(debug_mine)
(debug_busy_wait)
)

0 comments on commit 7efeecf

Please sign in to comment.