浏览代码

RequestServer+AK: Move happy-path logging behind REQUESTSERVER_DEBUG

vdbgln() was responsible for ~10% of samples on pv's flamegraph for
RequestServer (under request_did_finish) when loading github.com in
Browser and recording a whole-system profile. This makes that almost
completely disappear.
Nico Weber 3 年之前
父节点
当前提交
6d532649d4

+ 4 - 0
AK/Debug.h.in

@@ -346,6 +346,10 @@
 #cmakedefine01 REGEX_DEBUG
 #endif
 
+#ifndef REQUESTSERVER_DEBUG
+#cmakedefine01 REQUESTSERVER_DEBUG
+#endif
+
 #ifndef RESIZE_DEBUG
 #cmakedefine01 RESIZE_DEBUG
 #endif

+ 1 - 0
Meta/CMake/all_the_debug_macros.cmake

@@ -145,6 +145,7 @@ set(PTHREAD_DEBUG ON)
 set(PTMX_DEBUG ON)
 set(REACHABLE_DEBUG ON)
 set(REGEX_DEBUG ON)
+set(REQUESTSERVER_DEBUG ON)
 set(RESIZE_DEBUG ON)
 set(RESOURCE_DEBUG ON)
 set(ROUTING_DEBUG ON)

+ 5 - 4
Userland/Services/RequestServer/ConnectionCache.cpp

@@ -5,6 +5,7 @@
  */
 
 #include "ConnectionCache.h"
+#include <AK/Debug.h>
 #include <LibCore/EventLoop.h>
 
 namespace RequestServer::ConnectionCache {
@@ -19,7 +20,7 @@ void request_did_finish(URL const& url, Core::Socket const* socket)
         return;
     }
 
-    dbgln("Request for {} finished", url);
+    dbgln_if(REQUESTSERVER_DEBUG, "Request for {} finished", url);
 
     ConnectionKey key { url.host(), url.port_or_default() };
     auto fire_off_next_job = [&](auto& cache) {
@@ -40,7 +41,7 @@ void request_did_finish(URL const& url, Core::Socket const* socket)
             connection->current_url = {};
             connection->removal_timer->on_timeout = [ptr = connection.ptr(), &cache_entry = *it->value, key = it->key, &cache]() mutable {
                 Core::deferred_invoke([&, key = move(key), ptr] {
-                    dbgln("Removing no-longer-used connection {} (socket {})", ptr, ptr->socket);
+                    dbgln_if(REQUESTSERVER_DEBUG, "Removing no-longer-used connection {} (socket {})", ptr, ptr->socket);
                     auto did_remove = cache_entry.remove_first_matching([&](auto& entry) { return entry == ptr; });
                     VERIFY(did_remove);
                     if (cache_entry.is_empty())
@@ -58,9 +59,9 @@ void request_did_finish(URL const& url, Core::Socket const* socket)
             if (!is_connected) {
                 // Create another socket for the connection.
                 connection->socket = SocketType::construct(nullptr);
-                dbgln("Creating a new socket for {} -> {}", url, connection->socket);
+                dbgln_if(REQUESTSERVER_DEBUG, "Creating a new socket for {} -> {}", url, connection->socket);
             }
-            dbgln("Running next job in queue for connection {} @{}", &connection, connection->socket);
+            dbgln_if(REQUESTSERVER_DEBUG, "Running next job in queue for connection {} @{}", &connection, connection->socket);
             auto request = connection->request_queue.take_first();
             connection->timer.start();
             connection->current_url = url;

+ 2 - 2
Userland/Services/RequestServer/ConnectionCache.h

@@ -105,14 +105,14 @@ decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job)
     }
     auto& connection = sockets_for_url[index];
     if (!connection.has_started) {
-        dbgln("Immediately start request for url {} in {} - {}", url, &connection, connection.socket);
+        dbgln_if(REQUESTSERVER_DEBUG, "Immediately start request for url {} in {} - {}", url, &connection, connection.socket);
         connection.has_started = true;
         connection.removal_timer->stop();
         connection.timer.start();
         connection.current_url = url;
         start_job(*connection.socket);
     } else {
-        dbgln("Enqueue request for URL {} in {} - {}", url, &connection, connection.socket);
+        dbgln_if(REQUESTSERVER_DEBUG, "Enqueue request for URL {} in {} - {}", url, &connection, connection.socket);
         connection.request_queue.append(move(start_job));
     }
     return connection;