Skip to content

Commit

Permalink
Merge branch 'master' of github.com:steemit/fc
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Mar 18, 2017
2 parents f5f19d2 + 5cfcb5c commit 1f41494
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
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
14 changes: 14 additions & 0 deletions src/rpc/websocket_api.cpp
Expand Up @@ -95,7 +95,21 @@ 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::milliseconds( LOG_LONG_API_MAX_MS ) )
elog( "API call execution time limit exceeded. method: ${m} params: ${p} time: ${t}", ("m",call.method)("p",call.params)("t", end - start) );
else if( end - start > fc::milliseconds( LOG_LONG_API_WARN_MS ) )
wlog( "API call execution time nearing limit. method: ${m} params: ${p} time: ${t}", ("m",call.method)("p",call.params)("t", end - start) );
#endif

if( call.id )
{
auto reply = fc::json::to_string( response( *call.id, result ) );
Expand Down

0 comments on commit 1f41494

Please sign in to comment.