瀏覽代碼

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/.

Edwin Hoksberg 4 年之前
父節點
當前提交
e68780e1ad
共有 3 個文件被更改,包括 13 次插入5 次删除
  1. 4 0
      AK/Debug.h.in
  2. 1 0
      Meta/CMake/all_the_debug_macros.cmake
  3. 8 5
      Userland/Services/WebServer/Client.cpp

+ 4 - 0
AK/Debug.h.in

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

+ 1 - 0
Meta/CMake/all_the_debug_macros.cmake

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

+ 8 - 5
Userland/Services/WebServer/Client.cpp

@@ -6,6 +6,7 @@
 
 #include "Client.h"
 #include <AK/Base64.h>
+#include <AK/Debug.h>
 #include <AK/LexicalPath.h>
 #include <AK/MappedFile.h>
 #include <AK/MemoryStream.h>
@@ -50,7 +51,7 @@ void Client::start()
         }
 
         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);
         die();
     };
@@ -63,9 +64,11 @@ void Client::handle_request(ReadonlyBytes raw_request)
         return;
     auto& request = request_or_error.value();
 
-    dbgln("Got HTTP request: {} {}", request.method_name(), request.resource());
-    for (auto& header : request.headers()) {
-        dbgln("    {} => {}", header.name, header.value);
+    if constexpr (WEBSERVER_DEBUG) {
+        dbgln("Got HTTP request: {} {}", request.method_name(), request.resource());
+        for (auto& header : request.headers()) {
+            dbgln("    {} => {}", header.name, header.value);
+        }
     }
 
     if (request.method() != HTTP::HttpRequest::Method::GET) {
@@ -74,7 +77,7 @@ void Client::handle_request(ReadonlyBytes raw_request)
     }
 
     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;
     path_builder.append(m_root_path);