Title: [253702] trunk/Source
Revision
253702
Author
[email protected]
Date
2019-12-18 11:28:53 -0800 (Wed, 18 Dec 2019)

Log Message

Add network loading signposts
https://bugs.webkit.org/show_bug.cgi?id=204822
<rdar://problem/57608824>

Patch by Ben Nham <[email protected]> on 2019-12-18
Reviewed by Alex Christensen.

This adds os_signposts related to network loads to aid in debugging networking performance
issues. Since URLs are logged in the signposts, this capability is only enabled on Apple
internal builds when an environment variable is set.

Source/WebCore/PAL:

* PAL.xcodeproj/project.pbxproj:
* pal/PlatformMac.cmake:
* pal/spi/cocoa/OSVariantSPI.h: Added.

Source/WebKit:

* NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::signpostLogHandle):
(WebKit::signpostsEnabled):
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
(WebKit::NetworkDataTaskCocoa::didSendData):
(WebKit::NetworkDataTaskCocoa::didReceiveChallenge):
(WebKit::NetworkDataTaskCocoa::didCompleteWithError):
(WebKit::NetworkDataTaskCocoa::didReceiveData):
(WebKit::NetworkDataTaskCocoa::didReceiveResponse):
(WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
(WebKit::NetworkDataTaskCocoa::cancel):
(WebKit::NetworkDataTaskCocoa::resume):

Source/WTF:

* wtf/Platform.h:
Add HAVE_OS_SIGNPOST.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (253701 => 253702)


--- trunk/Source/WTF/ChangeLog	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WTF/ChangeLog	2019-12-18 19:28:53 UTC (rev 253702)
@@ -1,3 +1,18 @@
+2019-12-18  Ben Nham  <[email protected]>
+
+        Add network loading signposts
+        https://bugs.webkit.org/show_bug.cgi?id=204822
+        <rdar://problem/57608824>
+
+        Reviewed by Alex Christensen.
+
+        This adds os_signposts related to network loads to aid in debugging networking performance
+        issues. Since URLs are logged in the signposts, this capability is only enabled on Apple
+        internal builds when an environment variable is set.
+
+        * wtf/Platform.h:
+        Add HAVE_OS_SIGNPOST.
+
 2019-12-17  Myles C. Maxfield  <[email protected]>
 
         [iOS] Update to use CTFontCreateForCharactersWithLanguageAndOption()

Modified: trunk/Source/WTF/wtf/Platform.h (253701 => 253702)


--- trunk/Source/WTF/wtf/Platform.h	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WTF/wtf/Platform.h	2019-12-18 19:28:53 UTC (rev 253702)
@@ -1666,3 +1666,7 @@
 #if PLATFORM(IOS_FAMILY) || (!(defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC) && (OS(LINUX) && (PLATFORM(GTK) || PLATFORM(WPE))))
 #define USE_BMALLOC_MEMORY_FOOTPRINT_API 1
 #endif
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(IOS_FAMILY)
+#define HAVE_OS_SIGNPOST 1
+#endif

Modified: trunk/Source/WebCore/PAL/ChangeLog (253701 => 253702)


--- trunk/Source/WebCore/PAL/ChangeLog	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WebCore/PAL/ChangeLog	2019-12-18 19:28:53 UTC (rev 253702)
@@ -1,3 +1,19 @@
+2019-12-18  Ben Nham  <[email protected]>
+
+        Add network loading signposts
+        https://bugs.webkit.org/show_bug.cgi?id=204822
+        <rdar://problem/57608824>
+
+        Reviewed by Alex Christensen.
+
+        This adds os_signposts related to network loads to aid in debugging networking performance
+        issues. Since URLs are logged in the signposts, this capability is only enabled on Apple
+        internal builds when an environment variable is set.
+
+        * PAL.xcodeproj/project.pbxproj:
+        * pal/PlatformMac.cmake:
+        * pal/spi/cocoa/OSVariantSPI.h: Added.
+
 2019-12-05  Chris Dumez  <[email protected]>
 
         [IPC] Fail PAL::SessionID decoding if the decoded integer is not a valid session ID

Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (253701 => 253702)


--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2019-12-18 19:28:53 UTC (rev 253702)
@@ -168,6 +168,7 @@
 		CE5673872151A7B9002F92D7 /* IOKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5673862151A7B9002F92D7 /* IOKitSPI.h */; };
 		E5D45D122106A07400D2B738 /* NSColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D112106A07400D2B738 /* NSColorWellSPI.h */; };
 		E5D45D142106A18700D2B738 /* NSPopoverColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */; };
+		EB707FA5239737F80059053A /* OSVariantSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = EB707FA4239737F80059053A /* OSVariantSPI.h */; };
 		F442915E1FA52473002CC93E /* NSFileSizeFormatterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */; };
 		F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915F1FA5261E002CC93E /* FileSizeFormatter.h */; };
 		F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44291621FA52670002CC93E /* FileSizeFormatter.cpp */; };
@@ -342,6 +343,7 @@
 		CE5673862151A7B9002F92D7 /* IOKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOKitSPI.h; sourceTree = "<group>"; };
 		E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
 		E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPopoverColorWellSPI.h; sourceTree = "<group>"; };
+		EB707FA4239737F80059053A /* OSVariantSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSVariantSPI.h; sourceTree = "<group>"; };
 		F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFileSizeFormatterSPI.h; sourceTree = "<group>"; };
 		F442915F1FA5261E002CC93E /* FileSizeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileSizeFormatter.h; sourceTree = "<group>"; };
 		F44291621FA52670002CC93E /* FileSizeFormatter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileSizeFormatter.cpp; sourceTree = "<group>"; };
@@ -438,6 +440,7 @@
 				0C2DA1371F3BEB4900DBC317 /* NSURLDownloadSPI.h */,
 				0C2DA1381F3BEB4900DBC317 /* NSURLFileTypeMappingsSPI.h */,
 				570AB8F820AF6E3D00B8BE87 /* NSXPCConnectionSPI.h */,
+				EB707FA4239737F80059053A /* OSVariantSPI.h */,
 				0C2DA1391F3BEB4900DBC317 /* PassKitSPI.h */,
 				0C2DA13A1F3BEB4900DBC317 /* pthreadSPI.h */,
 				0C2DA13B1F3BEB4900DBC317 /* QuartzCoreSPI.h */,
@@ -797,6 +800,7 @@
 				0C77859D1F45130F00F4EBB6 /* NSWindowSPI.h in Headers */,
 				570AB8F920AF6E3D00B8BE87 /* NSXPCConnectionSPI.h in Headers */,
 				0C5AF91F1F43A4C7002EAC02 /* OpenGLESSPI.h in Headers */,
+				EB707FA5239737F80059053A /* OSVariantSPI.h in Headers */,
 				A1F63C9F21A4DBF7006FB43B /* PassKitSoftLink.h in Headers */,
 				0C2DA1551F3BEB4900DBC317 /* PassKitSPI.h in Headers */,
 				0C77859E1F45130F00F4EBB6 /* PIPSPI.h in Headers */,

Modified: trunk/Source/WebCore/PAL/pal/PlatformMac.cmake (253701 => 253702)


--- trunk/Source/WebCore/PAL/pal/PlatformMac.cmake	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WebCore/PAL/pal/PlatformMac.cmake	2019-12-18 19:28:53 UTC (rev 253702)
@@ -52,6 +52,7 @@
     spi/cocoa/NSURLDownloadSPI.h
     spi/cocoa/NSURLFileTypeMappingsSPI.h
     spi/cocoa/NSXPCConnectionSPI.h
+    spi/cocoa/OSVariantSPI.h
     spi/cocoa/PassKitSPI.h
     spi/cocoa/QuartzCoreSPI.h
     spi/cocoa/SecKeyProxySPI.h

Added: trunk/Source/WebCore/PAL/pal/spi/cocoa/OSVariantSPI.h (0 => 253702)


--- trunk/Source/WebCore/PAL/pal/spi/cocoa/OSVariantSPI.h	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/OSVariantSPI.h	2019-12-18 19:28:53 UTC (rev 253702)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2019 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
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <os/variant_private.h>
+
+#else
+
+WTF_EXTERN_C_BEGIN
+bool os_variant_allows_internal_security_policies(const char *);
+WTF_EXTERN_C_END
+
+#endif

Modified: trunk/Source/WebKit/ChangeLog (253701 => 253702)


--- trunk/Source/WebKit/ChangeLog	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WebKit/ChangeLog	2019-12-18 19:28:53 UTC (rev 253702)
@@ -1,3 +1,29 @@
+2019-12-18  Ben Nham  <[email protected]>
+
+        Add network loading signposts
+        https://bugs.webkit.org/show_bug.cgi?id=204822
+        <rdar://problem/57608824>
+
+        Reviewed by Alex Christensen.
+
+        This adds os_signposts related to network loads to aid in debugging networking performance
+        issues. Since URLs are logged in the signposts, this capability is only enabled on Apple
+        internal builds when an environment variable is set.
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::signpostLogHandle):
+        (WebKit::signpostsEnabled):
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        (WebKit::NetworkDataTaskCocoa::didSendData):
+        (WebKit::NetworkDataTaskCocoa::didReceiveChallenge):
+        (WebKit::NetworkDataTaskCocoa::didCompleteWithError):
+        (WebKit::NetworkDataTaskCocoa::didReceiveData):
+        (WebKit::NetworkDataTaskCocoa::didReceiveResponse):
+        (WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):
+        (WebKit::NetworkDataTaskCocoa::cancel):
+        (WebKit::NetworkDataTaskCocoa::resume):
+
 2019-12-18  youenn fablet  <[email protected]>
 
         Refine RTCMonitor logging

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h (253701 => 253702)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h	2019-12-18 19:28:53 UTC (rev 253702)
@@ -54,6 +54,7 @@
     void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend);
     void didReceiveChallenge(WebCore::AuthenticationChallenge&&, ChallengeCompletionHandler&&);
     void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&);
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&);
     void didReceiveData(Ref<WebCore::SharedBuffer>&&);
 
     void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&);

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (253701 => 253702)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2019-12-18 19:27:52 UTC (rev 253701)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2019-12-18 19:28:53 UTC (rev 253702)
@@ -41,6 +41,7 @@
 #import <WebCore/RegistrableDomain.h>
 #import <WebCore/ResourceRequest.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
+#import <pal/spi/cocoa/OSVariantSPI.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/FileSystem.h>
 #import <wtf/MainThread.h>
@@ -58,6 +59,61 @@
 #define NETWORK_DATA_TASK_COCOA_ADDITIONS_2
 #endif
 
+#if HAVE(OS_SIGNPOST)
+
+#import <os/signpost.h>
+
+static os_log_t signpostLogHandle()
+{
+    static dispatch_once_t once;
+    static os_log_t handle;
+
+    dispatch_once(&once, ^{
+        handle = os_log_create(LOG_CHANNEL_WEBKIT_SUBSYSTEM, "DataTask");
+    });
+
+    return handle;
+}
+
+static bool signpostsEnabled()
+{
+    static dispatch_once_t once;
+    static bool enabled;
+
+    dispatch_once(&once, ^{
+        if (os_variant_allows_internal_security_policies("com.apple.WebKit"))
+            enabled = !strcmp(getenv("WEBKIT_DATA_TASK_SIGNPOSTS") ?: "0", "1");
+    });
+
+    return enabled;
+}
+
+#define EMIT_SIGNPOST_WITH_FUNCTION(emitFunc, task, ...) \
+    do { \
+        if (signpostsEnabled()) { \
+            os_log_t handle = signpostLogHandle(); \
+            os_signpost_id_t signpostID = os_signpost_id_make_with_pointer(signpostLogHandle(), (task).get()); \
+            emitFunc(handle, signpostID, "DataTask", ##__VA_ARGS__); \
+        } \
+    } while (0)
+
+#define BEGIN_SIGNPOST(task, ...) \
+    EMIT_SIGNPOST_WITH_FUNCTION(os_signpost_interval_begin, (task), ##__VA_ARGS__)
+
+#define END_SIGNPOST(task, ...) \
+    EMIT_SIGNPOST_WITH_FUNCTION(os_signpost_interval_end, (task), ##__VA_ARGS__)
+
+#define EMIT_SIGNPOST(task, ...) \
+    EMIT_SIGNPOST_WITH_FUNCTION(os_signpost_event_emit, (task), ##__VA_ARGS__)
+
+#else
+
+#define BEGIN_SIGNPOST(task, ...) do { } while (0)
+#define END_SIGNPOST(task, ...) do { } while (0)
+#define EMIT_SIGNPOST(task, ...) do { } while (0)
+
+#endif
+
 namespace WebKit {
 
 #if USE(CREDENTIAL_STORAGE_WITH_NETWORK_SESSION)
@@ -232,6 +288,8 @@
     
     NETWORK_DATA_TASK_COCOA_ADDITIONS_1;
 
+    BEGIN_SIGNPOST(m_task, "%{public}s pri: %f preconnect: %d", url.string().ascii().data(), toNSURLSessionTaskPriority(request.priority()), shouldPreconnectOnly == PreconnectOnly::Yes);
+
     RELEASE_ASSERT(!m_sessionWrapper.dataTaskMap.contains([m_task taskIdentifier]));
     m_sessionWrapper.dataTaskMap.add([m_task taskIdentifier], this);
     LOG(NetworkSession, "%llu Creating NetworkDataTask with URL %s", [m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
@@ -284,6 +342,8 @@
 
 void NetworkDataTaskCocoa::didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend)
 {
+    EMIT_SIGNPOST(m_task, "sent %llu bytes (expected %llu bytes)", totalBytesSent, totalBytesExpectedToSend);
+
     if (m_client)
         m_client->didSendData(totalBytesSent, totalBytesExpectedToSend);
 }
@@ -290,6 +350,8 @@
 
 void NetworkDataTaskCocoa::didReceiveChallenge(WebCore::AuthenticationChallenge&& challenge, ChallengeCompletionHandler&& completionHandler)
 {
+    EMIT_SIGNPOST(m_task, "received challenge");
+
     if (tryPasswordBasedAuthentication(challenge, completionHandler))
         return;
 
@@ -303,6 +365,11 @@
 
 void NetworkDataTaskCocoa::didCompleteWithError(const WebCore::ResourceError& error, const WebCore::NetworkLoadMetrics& networkLoadMetrics)
 {
+    if (error.isNull())
+        END_SIGNPOST(m_task, "completed");
+    else
+        END_SIGNPOST(m_task, "failed");
+
     if (m_client)
         m_client->didCompleteWithError(error, networkLoadMetrics);
 }
@@ -309,12 +376,22 @@
 
 void NetworkDataTaskCocoa::didReceiveData(Ref<WebCore::SharedBuffer>&& data)
 {
+    EMIT_SIGNPOST(m_task, "received %zd bytes", data->size());
+
     if (m_client)
         m_client->didReceiveData(WTFMove(data));
 }
 
+void NetworkDataTaskCocoa::didReceiveResponse(WebCore::ResourceResponse&& response, WebKit::ResponseCompletionHandler&& completionHandler)
+{
+    EMIT_SIGNPOST(m_task, "received response headers");
+    NetworkDataTask::didReceiveResponse(WTFMove(response), WTFMove(completionHandler));
+}
+
 void NetworkDataTaskCocoa::willPerformHTTPRedirection(WebCore::ResourceResponse&& redirectResponse, WebCore::ResourceRequest&& request, RedirectCompletionHandler&& completionHandler)
 {
+    EMIT_SIGNPOST(m_task, "redirect");
+
     if (redirectResponse.httpStatusCode() == 307 || redirectResponse.httpStatusCode() == 308) {
         ASSERT(m_lastHTTPMethod == request.httpMethod());
         WebCore::FormData* body = m_firstRequest.httpBody();
@@ -470,11 +547,14 @@
 
 void NetworkDataTaskCocoa::cancel()
 {
+    EMIT_SIGNPOST(m_task, "cancel");
     [m_task cancel];
 }
 
 void NetworkDataTaskCocoa::resume()
 {
+    EMIT_SIGNPOST(m_task, "resume");
+
     if (m_scheduledFailureType != NoFailure)
         m_failureTimer.startOneShot(0_s);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to