Title: [290654] trunk/Source/WebKit
Revision
290654
Author
jer.no...@apple.com
Date
2022-03-01 10:12:13 -0800 (Tue, 01 Mar 2022)

Log Message

[Cocoa] Allow logging to be configured by NSDefaults (without regressing launch time)
https://bugs.webkit.org/show_bug.cgi?id=237183

Reviewed by Darin Adler.

In r220780, code was added to WebProcessPoolCocoa to explicitly pass the results of a NSUserDefaults
to newly created WebContent processes to determine log channel levels. Later, in r232158, NSUserDefaults
were removed from the default logLevelString() implementations in WTF, WebCore, and WebKit to improve
process launch time performance. In r279796, the same technique sued in WebProcessPoolCocoa was added
to GPUProcessProxyCocoa to pass those log level strings to the GPUProcess. And then in r286484, all the
uses of NSUserDefaults were removed from WebProcessPoolCocoa and GPUProcessProxyCocoa were removed,
removing the ability to increase the log channel levels at runtime through NSUserDefualts.

Add back in the ability to define log levels for the UIProcess and all AuxiliaryProcesses without
regressing launch time by only checking the NSUserDefault once, only in the UIProcess, storing the result
in a static variable, and passing the results of that check to all AuxiliaryProcesses at creation time.

* UIProcess/AuxiliaryProcessProxy.cpp:
(WebKit::AuxiliaryProcessProxy::auxiliaryProcessParameters):
* UIProcess/Cocoa/UIProcessLogInitializationCocoa.mm: Added.
(WebKit::UIProcess::wtfLogLevelString):
(WebKit::UIProcess::webCoreLogLevelString):
(WebKit::UIProcess::webKitLogLevelString):
* UIProcess/UIProcessLogInitialization.cpp: Added.
(WebKit::UIProcess::initializeLoggingIfNecessary):
(WebKit::UIProcess::wtfLogLevelString):
(WebKit::UIProcess::webCoreLogLevelString):
(WebKit::UIProcess::webKitLogLevelString):
* UIProcess/UIProcessLogInitialization.h: Added.
* UIProcess/WebProcessPool.cpp:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290653 => 290654)


--- trunk/Source/WebKit/ChangeLog	2022-03-01 17:56:49 UTC (rev 290653)
+++ trunk/Source/WebKit/ChangeLog	2022-03-01 18:12:13 UTC (rev 290654)
@@ -1,3 +1,36 @@
+2022-03-01  Jer Noble  <jer.no...@apple.com>
+
+        [Cocoa] Allow logging to be configured by NSDefaults (without regressing launch time)
+        https://bugs.webkit.org/show_bug.cgi?id=237183
+
+        Reviewed by Darin Adler.
+
+        In r220780, code was added to WebProcessPoolCocoa to explicitly pass the results of a NSUserDefaults
+        to newly created WebContent processes to determine log channel levels. Later, in r232158, NSUserDefaults
+        were removed from the default logLevelString() implementations in WTF, WebCore, and WebKit to improve
+        process launch time performance. In r279796, the same technique sued in WebProcessPoolCocoa was added
+        to GPUProcessProxyCocoa to pass those log level strings to the GPUProcess. And then in r286484, all the
+        uses of NSUserDefaults were removed from WebProcessPoolCocoa and GPUProcessProxyCocoa were removed,
+        removing the ability to increase the log channel levels at runtime through NSUserDefualts.
+
+        Add back in the ability to define log levels for the UIProcess and all AuxiliaryProcesses without
+        regressing launch time by only checking the NSUserDefault once, only in the UIProcess, storing the result
+        in a static variable, and passing the results of that check to all AuxiliaryProcesses at creation time.
+
+        * UIProcess/AuxiliaryProcessProxy.cpp:
+        (WebKit::AuxiliaryProcessProxy::auxiliaryProcessParameters):
+        * UIProcess/Cocoa/UIProcessLogInitializationCocoa.mm: Added.
+        (WebKit::UIProcess::wtfLogLevelString):
+        (WebKit::UIProcess::webCoreLogLevelString):
+        (WebKit::UIProcess::webKitLogLevelString):
+        * UIProcess/UIProcessLogInitialization.cpp: Added.
+        (WebKit::UIProcess::initializeLoggingIfNecessary):
+        (WebKit::UIProcess::wtfLogLevelString):
+        (WebKit::UIProcess::webCoreLogLevelString):
+        (WebKit::UIProcess::webKitLogLevelString):
+        * UIProcess/UIProcessLogInitialization.h: Added.
+        * UIProcess/WebProcessPool.cpp:
+
 2022-03-01  Youenn Fablet  <you...@apple.com>
 
         Annotate LibWebRTC with thread safety macros

Modified: trunk/Source/WebKit/Sources.txt (290653 => 290654)


--- trunk/Source/WebKit/Sources.txt	2022-03-01 17:56:49 UTC (rev 290653)
+++ trunk/Source/WebKit/Sources.txt	2022-03-01 18:12:13 UTC (rev 290654)
@@ -427,6 +427,7 @@
 UIProcess/SpeechRecognitionPermissionManager.cpp
 UIProcess/TextChecker.cpp
 UIProcess/TextCheckerCompletion.cpp
+UIProcess/UIProcessLogInitialization.cpp
 UIProcess/UserMediaPermissionCheckProxy.cpp
 UIProcess/UserMediaPermissionRequestManagerProxy.cpp
 UIProcess/UserMediaPermissionRequestProxy.cpp

Modified: trunk/Source/WebKit/SourcesCocoa.txt (290653 => 290654)


--- trunk/Source/WebKit/SourcesCocoa.txt	2022-03-01 17:56:49 UTC (rev 290653)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2022-03-01 18:12:13 UTC (rev 290654)
@@ -423,6 +423,7 @@
 UIProcess/Cocoa/SystemPreviewControllerCocoa.mm
 UIProcess/Cocoa/TextCheckingController.mm
 UIProcess/Cocoa/UIDelegate.mm
+UIProcess/Cocoa/UIProcessLogInitializationCocoa.mm
 UIProcess/Cocoa/UIRemoteObjectRegistry.cpp
 UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp
 UIProcess/Cocoa/UserMediaPermissionRequestManagerProxy.mm

Modified: trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp (290653 => 290654)


--- trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp	2022-03-01 17:56:49 UTC (rev 290653)
+++ trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp	2022-03-01 18:12:13 UTC (rev 290654)
@@ -27,12 +27,10 @@
 #include "AuxiliaryProcessProxy.h"
 
 #include "AuxiliaryProcessMessages.h"
-#include "LogInitialization.h"
 #include "Logging.h"
+#include "UIProcessLogInitialization.h"
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
-#include <WebCore/LogInitialization.h>
-#include <wtf/LogInitialization.h>
 #include <wtf/RunLoop.h>
 
 #if PLATFORM(COCOA)
@@ -408,9 +406,9 @@
 {
     AuxiliaryProcessCreationParameters parameters;
 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
-    parameters.wtfLoggingChannels = WTF::logLevelString();
-    parameters.webCoreLoggingChannels = WebCore::logLevelString();
-    parameters.webKitLoggingChannels = WebKit::logLevelString();
+    parameters.wtfLoggingChannels = UIProcess::wtfLogLevelString();
+    parameters.webCoreLoggingChannels = UIProcess::webCoreLogLevelString();
+    parameters.webKitLoggingChannels = UIProcess::webKitLogLevelString();
 #endif
     return parameters;
 }

Added: trunk/Source/WebKit/UIProcess/Cocoa/UIProcessLogInitializationCocoa.mm (0 => 290654)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIProcessLogInitializationCocoa.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIProcessLogInitializationCocoa.mm	2022-03-01 18:12:13 UTC (rev 290654)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import "config.h"
+#import "UIProcessLogInitialization.h"
+
+#if PLATFORM(COCOA)
+
+namespace WebKit {
+
+namespace UIProcess {
+
+String wtfLogLevelString()
+{
+    static NeverDestroyed<RetainPtr<NSString>> logString;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, [&] {
+        logString.get() = [[NSUserDefaults standardUserDefaults] stringForKey:@"WTFLogging"];
+    });
+    return logString.get().get();
+}
+
+String webCoreLogLevelString()
+{
+    static NeverDestroyed<RetainPtr<NSString>> logString;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, [&] {
+        logString.get() = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebCoreLogging"];
+    });
+    return logString.get().get();
+}
+
+String webKitLogLevelString()
+{
+    static NeverDestroyed<RetainPtr<NSString>> logString;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, [&] {
+        logString.get() = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebKit2Logging"];
+    });
+    return logString.get().get();
+}
+
+}
+
+}
+
+#endif

Added: trunk/Source/WebKit/UIProcess/UIProcessLogInitialization.cpp (0 => 290654)


--- trunk/Source/WebKit/UIProcess/UIProcessLogInitialization.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/UIProcessLogInitialization.cpp	2022-03-01 18:12:13 UTC (rev 290654)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UIProcessLogInitialization.h"
+
+#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
+
+#include "LogInitialization.h"
+#include <WebCore/LogInitialization.h>
+#include <wtf/LogInitialization.h>
+
+namespace WebKit {
+
+namespace UIProcess {
+
+void initializeLoggingIfNecessary()
+{
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        WTF::logChannels().initializeLogChannelsIfNecessary(wtfLogLevelString());
+        WebCore::logChannels().initializeLogChannelsIfNecessary(webCoreLogLevelString());
+        WebKit::logChannels().initializeLogChannelsIfNecessary(webKitLogLevelString());
+    });
+}
+
+#if !PLATFORM(COCOA)
+String wtfLogLevelString()
+{
+    return WTF::logLevelString();
+}
+
+String webCoreLogLevelString()
+{
+    return WebCore::logLevelString();
+}
+
+String webKitLogLevelString()
+{
+    return WebKit::logLevelString();
+}
+#endif
+
+}
+
+}
+
+#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
+

Added: trunk/Source/WebKit/UIProcess/UIProcessLogInitialization.h (0 => 290654)


--- trunk/Source/WebKit/UIProcess/UIProcessLogInitialization.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/UIProcessLogInitialization.h	2022-03-01 18:12:13 UTC (rev 290654)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Forward.h>
+
+// NOTE: These methods configure logging separately and differently for the UIProcess
+// than similar methods elsewhere. Specifically, the log strings returned from these
+// methods are initialized once, rather than repeatedly, and are intended to be passed
+// through to AuxiliaryProcesses to further reduce the runtime cost of log string
+// initialization.
+
+#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
+
+namespace WebKit {
+
+namespace UIProcess {
+
+void initializeLoggingIfNecessary();
+String wtfLogLevelString();
+String webCoreLogLevelString();
+String webKitLogLevelString();
+
+}
+
+}
+
+#endif

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (290653 => 290654)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-03-01 17:56:49 UTC (rev 290653)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-03-01 18:12:13 UTC (rev 290654)
@@ -45,7 +45,6 @@
 #include "GamepadData.h"
 #include "HighPerformanceGraphicsUsageSampler.h"
 #include "LegacyGlobalSettings.h"
-#include "LogInitialization.h"
 #include "Logging.h"
 #include "NetworkProcessCreationParameters.h"
 #include "NetworkProcessMessages.h"
@@ -56,6 +55,7 @@
 #include "TextChecker.h"
 #include "UIGamepad.h"
 #include "UIGamepadProvider.h"
+#include "UIProcessLogInitialization.h"
 #include "WKContextPrivate.h"
 #include "WebAutomationSession.h"
 #include "WebBackForwardCache.h"
@@ -85,7 +85,6 @@
 #include "WebsiteDataStoreParameters.h"
 #include <_javascript_Core/JSCInlines.h>
 #include <WebCore/ApplicationCacheStorage.h>
-#include <WebCore/LogInitialization.h>
 #include <WebCore/MockRealtimeMediaSourceCenter.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/PlatformScreen.h>
@@ -97,7 +96,6 @@
 #include <WebCore/RuntimeApplicationChecks.h>
 #include <pal/SessionID.h>
 #include <wtf/CallbackAggregator.h>
-#include <wtf/LogInitialization.h>
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/ProcessPrivilege.h>
@@ -269,9 +267,7 @@
     resolvePathsForSandboxExtensions();
 
 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
-    WTF::logChannels().initializeLogChannelsIfNecessary();
-    WebCore::logChannels().initializeLogChannelsIfNecessary();
-    WebKit::logChannels().initializeLogChannelsIfNecessary();
+    UIProcess::initializeLoggingIfNecessary();
 #endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
 
 #ifndef NDEBUG

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (290653 => 290654)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-03-01 17:56:49 UTC (rev 290653)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-03-01 18:12:13 UTC (rev 290654)
@@ -6265,6 +6265,9 @@
 		CD8252E025D4918400862FD8 /* RemoteRemoteCommandListenerMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteRemoteCommandListenerMessageReceiver.cpp; sourceTree = "<group>"; };
 		CD8252E125D4918500862FD8 /* RemoteRemoteCommandListenerMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteRemoteCommandListenerMessages.h; sourceTree = "<group>"; };
 		CD95493526159004008372D9 /* libWebKitSwift.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libWebKitSwift.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+		CD9A649F27C8972C003827C0 /* UIProcessLogInitialization.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIProcessLogInitialization.h; sourceTree = "<group>"; };
+		CD9A64A027C8972C003827C0 /* UIProcessLogInitialization.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UIProcessLogInitialization.cpp; sourceTree = "<group>"; };
+		CD9A64A127C89742003827C0 /* UIProcessLogInitializationCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIProcessLogInitializationCocoa.mm; sourceTree = "<group>"; };
 		CDA041F31ACE2105004A13EC /* BackBoardServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackBoardServicesSPI.h; sourceTree = "<group>"; };
 		CDA29A181CBDBF4100901CCF /* PlaybackSessionManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlaybackSessionManager.mm; sourceTree = "<group>"; };
 		CDA29A191CBDBF4100901CCF /* PlaybackSessionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlaybackSessionManager.h; sourceTree = "<group>"; };
@@ -7631,6 +7634,7 @@
 				2D0CF64B21F2A80300787566 /* TextCheckingController.mm */,
 				1AFE436418B6C081009C7A48 /* UIDelegate.h */,
 				1AFE436318B6C081009C7A48 /* UIDelegate.mm */,
+				CD9A64A127C89742003827C0 /* UIProcessLogInitializationCocoa.mm */,
 				463236862314833F00A48FA7 /* UIRemoteObjectRegistry.cpp */,
 				463236852314833F00A48FA7 /* UIRemoteObjectRegistry.h */,
 				070259BE2522841C00153405 /* UserMediaPermissionRequestManagerProxy.mm */,
@@ -11156,6 +11160,8 @@
 				1AA417C912C00CCA002BE67B /* TextChecker.h */,
 				53CFBBC62224D1B000266546 /* TextCheckerCompletion.cpp */,
 				53CFBBC72224D1B000266546 /* TextCheckerCompletion.h */,
+				CD9A64A027C8972C003827C0 /* UIProcessLogInitialization.cpp */,
+				CD9A649F27C8972C003827C0 /* UIProcessLogInitialization.h */,
 				07297F9C1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.cpp */,
 				07297F9D1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.h */,
 				4A410F3919AF7B04002EBAB5 /* UserMediaPermissionRequestManagerProxy.cpp */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to