Skip to content

Commit

Permalink
Refactor to use cmake build options bitshares#9
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Jan 25, 2017
1 parent 0688b7e commit c1a0dca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWEBSOCKETPP_STRICT_MASKING")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_ASIO_HAS_STD_CHRONO")

OPTION( LOG_LONG_API "Log long API calls over websocket (ON OR OFF)" ON )
MESSAGE( STATUS "LOG_LONG_API: ${LOG_LONG_API}" )
if( LOG_LONG_API )
SET( LOG_LONG_API_MAX_MS 1000 CACHE STRING "Max API execution time in ms" )
SET( LOG_LONG_API_WARN_MS 750 CACHE STRING "API execution time in ms at which to warn" )
MESSAGE( STATUS " " )
MESSAGE( STATUS " LOGGING LONG API CALLS" )
MESSAGE( STATUS " MAX MS: ${LOG_LONG_API_MAX_MS}" )
MESSAGE( STATUS " WARN MS: ${LOG_LONG_API_WARN_MS}" )
MESSAGE( STATUS " " )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLOG_LONG_API -DLOG_LONG_API_MAX_MS=${LOG_LONG_API_MAX_MS} -DLOG_LONG_API_WARN_MS=${LOG_LONG_API_WARN_MS}" )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLOG_LONG_API -DLOG_LONG_API_MAX_MS=${LOG_LONG_API_MAX_MS} -DLOG_LONG_API_WARN_MS=${LOG_LONG_API_WARN_MS}" )
endif()

target_include_directories(fc
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
${Boost_INCLUDE_DIR}
Expand Down
10 changes: 8 additions & 2 deletions src/rpc/websocket_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,20 @@ std::string websocket_api_connection::on_message(
{
try
{
#ifdef LOG_LONG_API
auto start = time_point::now();
#endif

auto result = _rpc_state.local_call( call.method, call.params );

#ifdef LOG_LONG_API
auto end = time_point::now();

if( end - start > fc::seconds( 1 ) )
if( end - start > fc::milliseconds( LOG_LONG_API_MAX_MS ) )
elog( "API call execution time limit exceeded.", ("method",call.method)("params",call.params)("time", end - start) );
else if( end - start > fc::milliseconds( 750 ) )
else if( end - start > fc::milliseconds( LOG_LONG_API_WARN_MS ) )
wlog( "API call execution time nearing limit.", ("method",call.method)("params",call.params)("time", end - start) );
#endif

if( call.id )
{
Expand Down

0 comments on commit c1a0dca

Please sign in to comment.