mirror of
https://github.com/drogonframework/drogon.git
synced 2025-08-29 00:02:44 -04:00
Add causal profiling with coz (#414)
This commit is contained in:
parent
6d6a7acd09
commit
eafdc5d357
@ -5,6 +5,7 @@ message(STATUS "compiler: " ${CMAKE_CXX_COMPILER_ID})
|
||||
option(BUILD_CTL "Build drogon_ctl" ON)
|
||||
option(BUILD_EXAMPLES "Build examples" ON)
|
||||
option(BUILD_ORM "Build orm" ON)
|
||||
option(COZ_PROFILING "Use coz for profiling" OFF)
|
||||
option(LIBPQ_BATCH_MODE "Use batch mode for libpq" ON)
|
||||
option(BUILD_DROGON_SHARED "Build drogon as a shared lib" OFF)
|
||||
|
||||
@ -237,6 +238,16 @@ if(BUILD_CTL)
|
||||
add_subdirectory(drogon_ctl)
|
||||
endif(BUILD_CTL)
|
||||
|
||||
if(COZ_PROFILING)
|
||||
find_package(coz-profiler REQUIRED)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE -DCOZ_PROFILING=1)
|
||||
# If linked will not need to be ran with `coz run --- [executable]` to run the
|
||||
# profiler, but drogon_ctl currently won't build because it doesn't find debug
|
||||
# information while trying to generate it's own sources
|
||||
# target_link_libraries(${PROJECT_NAME} PUBLIC coz::coz)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${COZ_INCLUDE_DIRS})
|
||||
endif(COZ_PROFILING)
|
||||
|
||||
if(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND)
|
||||
set(DROGON_SOURCES
|
||||
${DROGON_SOURCES}
|
||||
@ -439,6 +450,7 @@ install(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindMySQL.cmake"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/Findpg.cmake"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindBrotli.cmake"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/Findcoz-profiler.cmake"
|
||||
DESTINATION "${INSTALL_DROGON_CMAKE_DIR}"
|
||||
COMPONENT dev)
|
||||
|
||||
|
@ -33,6 +33,9 @@ endif()
|
||||
if(@Brotli_FOUND@)
|
||||
find_dependency(Brotli)
|
||||
endif()
|
||||
if(@COZ-PROFILER_FOUND@)
|
||||
find_dependency(coz-profiler)
|
||||
endif()
|
||||
|
||||
# Our library dependencies (contains definitions for IMPORTED targets)
|
||||
|
||||
|
23
cmake_modules/Findcoz-profiler.cmake
Normal file
23
cmake_modules/Findcoz-profiler.cmake
Normal file
@ -0,0 +1,23 @@
|
||||
find_path(COZ_INCLUDE_DIRS NAMES coz.h)
|
||||
|
||||
find_library(COZ_LIBRARIES NAMES coz PATH_SUFFIXES coz-profiler)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(coz-profiler
|
||||
DEFAULT_MSG
|
||||
COZ_LIBRARIES
|
||||
COZ_INCLUDE_DIRS)
|
||||
|
||||
if(COZ-PROFILER_FOUND)
|
||||
add_library(coz::coz INTERFACE IMPORTED)
|
||||
set_target_properties(coz::coz
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
${COZ_INCLUDE_DIRS}
|
||||
INTERFACE_LINK_LIBRARIES
|
||||
${COZ_LIBRARIES})
|
||||
else(COZ-PROFILER_FOUND)
|
||||
set(COZ_LIBRARIES)
|
||||
set(COZ_INCLUDE_DIRS)
|
||||
endif(COZ-PROFILER_FOUND)
|
||||
|
||||
mark_as_advanced(COZ_INCLUDE_DIRS COZ_LIBRARIES)
|
@ -24,6 +24,15 @@
|
||||
#include <functional>
|
||||
#include <trantor/utils/Logger.h>
|
||||
|
||||
#if COZ_PROFILING
|
||||
#include <coz.h>
|
||||
#else
|
||||
#define COZ_PROGRESS
|
||||
#define COZ_PROGRESS_NAMED(name)
|
||||
#define COZ_BEGIN(name)
|
||||
#define COZ_END(name)
|
||||
#endif
|
||||
|
||||
using namespace std::placeholders;
|
||||
using namespace drogon;
|
||||
using namespace trantor;
|
||||
@ -258,6 +267,7 @@ void HttpServer::onMessage(const TcpConnectionPtr &conn, MsgBuffer *buf)
|
||||
((HttpResponseImpl *)resp.get())
|
||||
->renderToBuffer();
|
||||
conn->send(httpString);
|
||||
COZ_PROGRESS
|
||||
}
|
||||
},
|
||||
wsConn);
|
||||
@ -495,16 +505,19 @@ void HttpServer::sendResponse(const TcpConnectionPtr &conn,
|
||||
{
|
||||
conn->sendFile(sendfileName.c_str());
|
||||
}
|
||||
COZ_PROGRESS
|
||||
}
|
||||
else
|
||||
{
|
||||
auto httpString = respImplPtr->renderHeaderForHeadMethod();
|
||||
conn->send(std::move(*httpString));
|
||||
COZ_PROGRESS
|
||||
}
|
||||
|
||||
if (response->ifCloseConnection())
|
||||
{
|
||||
conn->shutdown();
|
||||
COZ_PROGRESS
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,6 +547,7 @@ void HttpServer::sendResponses(
|
||||
conn->send(buffer);
|
||||
buffer.retrieveAll();
|
||||
conn->sendFile(sendfileName.c_str());
|
||||
COZ_PROGRESS
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -547,6 +561,7 @@ void HttpServer::sendResponses(
|
||||
{
|
||||
conn->send(buffer);
|
||||
buffer.retrieveAll();
|
||||
COZ_PROGRESS
|
||||
}
|
||||
conn->shutdown();
|
||||
return;
|
||||
@ -555,6 +570,7 @@ void HttpServer::sendResponses(
|
||||
if (conn->connected() && buffer.readableBytes() > 0)
|
||||
{
|
||||
conn->send(buffer);
|
||||
COZ_PROGRESS
|
||||
}
|
||||
buffer.retrieveAll();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user