WebServer: Put dbgln's behind WEBSERVER_DEBUG

These dbgln's caused excessive load in the WebServer process,
accounting for ~67% of the processing time when serving a webpage
with a bunch of resources like serenityos.org/happy/2nd/.
This commit is contained in:
Edwin Hoksberg 2021-05-30 16:42:03 +02:00 committed by Linus Groh
parent a557f83f8c
commit e68780e1ad
Notes: sideshowbarker 2024-07-18 17:09:40 +09:00
3 changed files with 13 additions and 5 deletions

View file

@ -422,6 +422,10 @@
#cmakedefine01 WASM_TRACE_DEBUG #cmakedefine01 WASM_TRACE_DEBUG
#endif #endif
#ifndef WEBSERVER_DEBUG
#cmakedefine01 WEBSERVER_DEBUG
#endif
#ifndef WINDOWMANAGER_DEBUG #ifndef WINDOWMANAGER_DEBUG
#cmakedefine01 WINDOWMANAGER_DEBUG #cmakedefine01 WINDOWMANAGER_DEBUG
#endif #endif

View file

@ -186,6 +186,7 @@ set(WASM_TRACE_DEBUG ON)
set(PDF_DEBUG ON) set(PDF_DEBUG ON)
set(SOLITAIRE_DEBUG ON) set(SOLITAIRE_DEBUG ON)
set(DDS_DEBUG ON) set(DDS_DEBUG ON)
set(WEBSERVER_DEBUG ON)
# False positive: DEBUG is a flag but it works differently. # False positive: DEBUG is a flag but it works differently.
# set(DEBUG ON) # set(DEBUG ON)

View file

@ -6,6 +6,7 @@
#include "Client.h" #include "Client.h"
#include <AK/Base64.h> #include <AK/Base64.h>
#include <AK/Debug.h>
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/MappedFile.h> #include <AK/MappedFile.h>
#include <AK/MemoryStream.h> #include <AK/MemoryStream.h>
@ -50,7 +51,7 @@ void Client::start()
} }
auto request = builder.to_byte_buffer(); auto request = builder.to_byte_buffer();
dbgln("Got raw request: '{}'", String::copy(request)); dbgln_if(WEBSERVER_DEBUG, "Got raw request: '{}'", String::copy(request));
handle_request(request); handle_request(request);
die(); die();
}; };
@ -63,10 +64,12 @@ void Client::handle_request(ReadonlyBytes raw_request)
return; return;
auto& request = request_or_error.value(); auto& request = request_or_error.value();
if constexpr (WEBSERVER_DEBUG) {
dbgln("Got HTTP request: {} {}", request.method_name(), request.resource()); dbgln("Got HTTP request: {} {}", request.method_name(), request.resource());
for (auto& header : request.headers()) { for (auto& header : request.headers()) {
dbgln(" {} => {}", header.name, header.value); dbgln(" {} => {}", header.name, header.value);
} }
}
if (request.method() != HTTP::HttpRequest::Method::GET) { if (request.method() != HTTP::HttpRequest::Method::GET) {
send_error_response(403, "Forbidden!", request); send_error_response(403, "Forbidden!", request);
@ -74,7 +77,7 @@ void Client::handle_request(ReadonlyBytes raw_request)
} }
auto requested_path = LexicalPath::join("/", request.resource()).string(); auto requested_path = LexicalPath::join("/", request.resource()).string();
dbgln("Canonical requested path: '{}'", requested_path); dbgln_if(WEBSERVER_DEBUG, "Canonical requested path: '{}'", requested_path);
StringBuilder path_builder; StringBuilder path_builder;
path_builder.append(m_root_path); path_builder.append(m_root_path);