From 0cf7291ee2c4ae7461b4dcc082fb3778532e3df3 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 16 Dec 2024 15:37:47 +0100 Subject: 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. --- src/zenhttp/servers/httpplugin.cpp | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/zenhttp/servers/httpplugin.cpp') 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 # include # include +# include # include # include # include @@ -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 BlobList) { + ZEN_MEMSCOPE(GetHttppluginTag()); ZEN_TRACE_CPU("http_plugin::InitializeForPayload"); m_ResponseCode = ResponseCode; @@ -224,6 +234,8 @@ HttpPluginResponse::InitializeForPayload(uint16_t ResponseCode, std::spanm_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 Empty; @@ -617,6 +639,7 @@ void HttpPluginServerRequest::WriteResponse(HttpResponseCode ResponseCode, HttpContentType ContentType, std::span 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&& 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 Plugin) { + ZEN_MEMSCOPE(GetHttppluginTag()); + RwLock::ExclusiveLockScope _(m_Lock); m_Plugins.emplace_back(std::move(Plugin)); } @@ -793,6 +827,8 @@ HttpPluginServerImpl::AddPlugin(Ref Plugin) void HttpPluginServerImpl::RemovePlugin(Ref 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 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 CreateHttpPluginServer() { + ZEN_MEMSCOPE(GetHttppluginTag()); return Ref(new HttpPluginServerImpl); } -- cgit v1.2.3