aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpplugin.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-12-16 15:37:47 +0100
committerGitHub Enterprise <[email protected]>2024-12-16 15:37:47 +0100
commit0cf7291ee2c4ae7461b4dcc082fb3778532e3df3 (patch)
tree7735061b5c242a34baea0b4497cbb9381efe76b3 /src/zenhttp/servers/httpplugin.cpp
parent5.5.16 (diff)
downloadzen-0cf7291ee2c4ae7461b4dcc082fb3778532e3df3.tar.xz
zen-0cf7291ee2c4ae7461b4dcc082fb3778532e3df3.zip
more memory tagging and fixes (#263)
This change adds more instrumentation for memory tracking, so that as little as possible comes through as Unknown in Insights analysis.
Diffstat (limited to 'src/zenhttp/servers/httpplugin.cpp')
-rw-r--r--src/zenhttp/servers/httpplugin.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/zenhttp/servers/httpplugin.cpp b/src/zenhttp/servers/httpplugin.cpp
index 9c2110476..b55d80af8 100644
--- a/src/zenhttp/servers/httpplugin.cpp
+++ b/src/zenhttp/servers/httpplugin.cpp
@@ -12,6 +12,7 @@
# include <zencore/filesystem.h>
# include <zencore/fmtutils.h>
# include <zencore/logging.h>
+# include <zencore/memory/llm.h>
# include <zencore/scopeguard.h>
# include <zencore/session.h>
# include <zencore/thread.h>
@@ -34,6 +35,14 @@ struct HttpPluginResponse;
using namespace std::literals;
+const FLLMTag&
+GetHttppluginTag()
+{
+ static FLLMTag _("httpplugin");
+
+ return _;
+}
+
//////////////////////////////////////////////////////////////////////////
struct HttpPluginConnectionHandler : public TransportServerConnection, public HttpRequestParserCallbacks, RefCounted
@@ -183,6 +192,7 @@ private:
void
HttpPluginResponse::InitializeForPayload(uint16_t ResponseCode, std::span<IoBuffer> BlobList)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
ZEN_TRACE_CPU("http_plugin::InitializeForPayload");
m_ResponseCode = ResponseCode;
@@ -224,6 +234,8 @@ HttpPluginResponse::InitializeForPayload(uint16_t ResponseCode, std::span<IoBuff
std::string_view
HttpPluginResponse::GetHeaders()
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
if (m_Headers.Size() == 0)
{
m_Headers << "HTTP/1.1 " << ResponseCode() << " " << ReasonStringForHttpResultCode(ResponseCode()) << "\r\n"
@@ -258,6 +270,8 @@ HttpPluginConnectionHandler::~HttpPluginConnectionHandler()
void
HttpPluginConnectionHandler::Initialize(TransportConnection* Transport, HttpPluginServerImpl& Server, uint32_t ConnectionId)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
m_TransportConnection = Transport;
m_Server = &Server;
m_ConnectionId = ConnectionId;
@@ -290,6 +304,8 @@ HttpPluginConnectionHandler::Release() const
void
HttpPluginConnectionHandler::OnBytesRead(const void* Buffer, size_t AvailableBytes)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
ZEN_ASSERT(m_Server);
ZEN_LOG_TRACE(m_Server->m_RequestLog, "connection #{} OnBytesRead: {}", m_ConnectionId, AvailableBytes);
@@ -317,6 +333,8 @@ HttpPluginConnectionHandler::OnBytesRead(const void* Buffer, size_t AvailableByt
void
HttpPluginConnectionHandler::HandleRequest()
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
ZEN_ASSERT(m_Server);
const uint32_t RequestNumber = m_RequestCounter.fetch_add(1);
@@ -516,6 +534,7 @@ HttpPluginConnectionHandler::HandleRequest()
void
HttpPluginConnectionHandler::TerminateConnection()
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
ZEN_ASSERT(m_TransportConnection);
m_TransportConnection->CloseConnection();
}
@@ -526,6 +545,8 @@ HttpPluginServerRequest::HttpPluginServerRequest(HttpRequestParser& Request, Htt
: m_Request(Request)
, m_PayloadBuffer(std::move(PayloadBuffer))
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
const int PrefixLength = Service.UriPrefixLength();
std::string_view Uri = Request.Url();
@@ -606,6 +627,7 @@ void
HttpPluginServerRequest::WriteResponse(HttpResponseCode ResponseCode)
{
ZEN_ASSERT(!m_Response);
+ ZEN_MEMSCOPE(GetHttppluginTag());
m_Response.reset(new HttpPluginResponse(HttpContentType::kBinary));
std::array<IoBuffer, 0> Empty;
@@ -617,6 +639,7 @@ void
HttpPluginServerRequest::WriteResponse(HttpResponseCode ResponseCode, HttpContentType ContentType, std::span<IoBuffer> Blobs)
{
ZEN_ASSERT(!m_Response);
+ ZEN_MEMSCOPE(GetHttppluginTag());
m_Response.reset(new HttpPluginResponse(ContentType));
m_Response->InitializeForPayload((uint16_t)ResponseCode, Blobs);
@@ -626,6 +649,8 @@ void
HttpPluginServerRequest::WriteResponse(HttpResponseCode ResponseCode, HttpContentType ContentType, std::u8string_view ResponseString)
{
ZEN_ASSERT(!m_Response);
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
m_Response.reset(new HttpPluginResponse(ContentType));
IoBuffer MessageBuffer(IoBuffer::Wrap, ResponseString.data(), ResponseString.size());
@@ -638,6 +663,7 @@ void
HttpPluginServerRequest::WriteResponseAsync(std::function<void(HttpServerRequest&)>&& ContinuationHandler)
{
ZEN_ASSERT(!m_Response);
+ ZEN_MEMSCOPE(GetHttppluginTag());
// Not one bit async, innit
ContinuationHandler(*this);
@@ -662,6 +688,7 @@ HttpPluginServerImpl::~HttpPluginServerImpl()
TransportServerConnection*
HttpPluginServerImpl::CreateConnectionHandler(TransportConnection* Connection)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
HttpPluginConnectionHandler* Handler{new HttpPluginConnectionHandler()};
const uint32_t ConnectionId = m_ConnectionIdCounter.fetch_add(1);
Handler->Initialize(Connection, *this, ConnectionId);
@@ -671,6 +698,7 @@ HttpPluginServerImpl::CreateConnectionHandler(TransportConnection* Connection)
int
HttpPluginServerImpl::Initialize(int BasePort, std::filesystem::path DataDir)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
m_RequestTracer.Initialize(DataDir);
try
@@ -705,6 +733,8 @@ HttpPluginServerImpl::Close()
if (!m_IsInitialized)
return;
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
try
{
RwLock::ExclusiveLockScope _(m_Lock);
@@ -736,6 +766,8 @@ HttpPluginServerImpl::Close()
void
HttpPluginServerImpl::Run(bool IsInteractive)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
const bool TestMode = !IsInteractive;
int WaitTimeout = -1;
@@ -786,6 +818,8 @@ HttpPluginServerImpl::RequestExit()
void
HttpPluginServerImpl::AddPlugin(Ref<TransportPlugin> Plugin)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
RwLock::ExclusiveLockScope _(m_Lock);
m_Plugins.emplace_back(std::move(Plugin));
}
@@ -793,6 +827,8 @@ HttpPluginServerImpl::AddPlugin(Ref<TransportPlugin> Plugin)
void
HttpPluginServerImpl::RemovePlugin(Ref<TransportPlugin> Plugin)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
RwLock::ExclusiveLockScope _(m_Lock);
auto It = std::find(begin(m_Plugins), end(m_Plugins), Plugin);
if (It != m_Plugins.end())
@@ -804,6 +840,8 @@ HttpPluginServerImpl::RemovePlugin(Ref<TransportPlugin> Plugin)
void
HttpPluginServerImpl::RegisterService(HttpService& Service)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
std::string_view UrlPath(Service.BaseUri());
Service.SetUriPrefixLength(UrlPath.size());
@@ -819,6 +857,8 @@ HttpPluginServerImpl::RegisterService(HttpService& Service)
HttpService*
HttpPluginServerImpl::RouteRequest(std::string_view Url)
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
+
RwLock::SharedLockScope _(m_Lock);
HttpService* CandidateService = nullptr;
@@ -845,6 +885,7 @@ struct HttpPluginServerImpl;
Ref<HttpPluginServer>
CreateHttpPluginServer()
{
+ ZEN_MEMSCOPE(GetHttppluginTag());
return Ref<HttpPluginServer>(new HttpPluginServerImpl);
}