Title: [258384] trunk/Source/WebKit
Revision
258384
Author
[email protected]
Date
2020-03-12 22:55:58 -0700 (Thu, 12 Mar 2020)

Log Message

Add a very verbose logging mode for incremental PDF loading
https://bugs.webkit.org/show_bug.cgi?id=208975

Reviewed by Simon Fraser.

Adds a verbose logging channel that includes a full dump of the PDFPlugin's loading status
for each logging message.

* Platform/Logging.h:

* WebProcess/Plugins/PDF/PDFPlugin.h:
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::pdfLog):
(WebKit::PDFPlugin::logStreamLoader):
(WebKit::PDFPlugin::verboseLog):
(WebKit::dataProviderGetBytesAtPositionCallback):
(WebKit::dataProviderGetByteRangesCallback):
(WebKit::PDFPlugin::getResourceBytesAtPosition):
(WebKit::PDFPlugin::adoptBackgroundThreadDocument):
(WebKit::PDFPlugin::ByteRangeRequest::completeWithBytes):
(WebKit::PDFPlugin::ByteRangeRequest::completeWithAccumulatedData):
(WebKit::PDFPlugin::forgetLoader):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (258383 => 258384)


--- trunk/Source/WebKit/ChangeLog	2020-03-13 05:45:24 UTC (rev 258383)
+++ trunk/Source/WebKit/ChangeLog	2020-03-13 05:55:58 UTC (rev 258384)
@@ -1,3 +1,28 @@
+2020-03-12  Brady Eidson  <[email protected]>
+
+        Add a very verbose logging mode for incremental PDF loading
+        https://bugs.webkit.org/show_bug.cgi?id=208975
+
+        Reviewed by Simon Fraser.
+
+        Adds a verbose logging channel that includes a full dump of the PDFPlugin's loading status
+        for each logging message.
+        
+        * Platform/Logging.h:
+
+        * WebProcess/Plugins/PDF/PDFPlugin.h:
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::pdfLog):
+        (WebKit::PDFPlugin::logStreamLoader):
+        (WebKit::PDFPlugin::verboseLog):
+        (WebKit::dataProviderGetBytesAtPositionCallback):
+        (WebKit::dataProviderGetByteRangesCallback):
+        (WebKit::PDFPlugin::getResourceBytesAtPosition):
+        (WebKit::PDFPlugin::adoptBackgroundThreadDocument):
+        (WebKit::PDFPlugin::ByteRangeRequest::completeWithBytes):
+        (WebKit::PDFPlugin::ByteRangeRequest::completeWithAccumulatedData):
+        (WebKit::PDFPlugin::forgetLoader):
+
 2020-03-12  Brent Fulgham  <[email protected]>
 
         Correct preference handling and naming conventions in AppBound browsing preferences

Modified: trunk/Source/WebKit/Platform/Logging.h (258383 => 258384)


--- trunk/Source/WebKit/Platform/Logging.h	2020-03-13 05:45:24 UTC (rev 258383)
+++ trunk/Source/WebKit/Platform/Logging.h	2020-03-13 05:55:58 UTC (rev 258384)
@@ -54,10 +54,12 @@
     M(DragAndDrop) \
     M(Fullscreen) \
     M(Gamepad) \
+    M(IPC) \
+    M(ITPDebug) \
     M(IconDatabase) \
+    M(IncrementalPDF) \
+    M(IncrementalPDFVerbose) \
     M(IndexedDB) \
-    M(IPC) \
-    M(ITPDebug) \
     M(KeyHandling) \
     M(Layers) \
     M(Layout) \
@@ -71,7 +73,6 @@
     M(NetworkCacheStorage) \
     M(NetworkScheduling) \
     M(NetworkSession) \
-    M(PDF) \
     M(PerformanceLogging) \
     M(Plugins) \
     M(Printing) \

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h (258383 => 258384)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-03-13 05:45:24 UTC (rev 258383)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h	2020-03-13 05:55:58 UTC (rev 258384)
@@ -67,6 +67,10 @@
 struct PluginInfo;
 }
 
+namespace WTF {
+class TextStream;
+}
+
 namespace WebKit {
 
 class PDFPluginAnnotation;
@@ -128,7 +132,12 @@
 
 #if HAVE(INCREMENTAL_PDF_APIS)
     void getResourceBytesAtPosition(size_t count, off_t position, CompletionHandler<void(const uint8_t*, size_t count)>&&);
+#ifndef NDEBUG
+    void pdfLog(const String& event);
+    size_t incrementThreadsWaitingOnCallback() { return ++m_threadsWaitingOnCallback; }
+    size_t decrementThreadsWaitingOnCallback() { return --m_threadsWaitingOnCallback; }
 #endif
+#endif
 
 private:
     explicit PDFPlugin(WebFrame&);
@@ -353,6 +362,9 @@
         bool maybeComplete(PDFPlugin&);
         void completeUnconditionally(PDFPlugin&);
 
+        uint64_t position() const { return m_position; }
+        size_t count() const { return m_count; }
+
     private:
         uint64_t m_position { 0 };
         size_t m_count { 0 };
@@ -372,7 +384,16 @@
     HashMap<RefPtr<WebCore::NetscapePlugInStreamLoader>, uint64_t> m_streamLoaderMap;
     RangeSet<WTF::Range<uint64_t>> m_completedRanges;
     bool m_incrementalPDFLoadingEnabled;
+
+#if !LOG_DISABLED
+    void verboseLog();
+    void logStreamLoader(WTF::TextStream&, WebCore::NetscapePlugInStreamLoader&);
+    std::atomic<size_t> m_threadsWaitingOnCallback { 0 };
+    std::atomic<size_t> m_completedRangeRequests { 0 };
+    std::atomic<size_t> m_completedNetworkRangeRequests { 0 };
 #endif
+
+#endif // HAVE(INCREMENTAL_PDF_APIS)
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (258383 => 258384)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-03-13 05:45:24 UTC (rev 258383)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2020-03-13 05:55:58 UTC (rev 258384)
@@ -92,6 +92,7 @@
 #import <wtf/UUID.h>
 #import <wtf/WTFSemaphore.h>
 #import <wtf/WorkQueue.h>
+#import <wtf/text/TextStream.h>
 
 #if HAVE(INCREMENTAL_PDF_APIS)
 @interface PDFDocument ()
@@ -632,11 +633,74 @@
 }
 
 #if HAVE(INCREMENTAL_PDF_APIS)
+#if !LOG_DISABLED
+void PDFPlugin::pdfLog(const String& message)
+{
+    if (!isMainThread()) {
+        callOnMainThread([this, protectedThis = makeRef(*this), message = message.isolatedCopy()] {
+            pdfLog(message);
+        });
+        return;
+    }
+
+    LOG_WITH_STREAM(IncrementalPDF, stream << message);
+    verboseLog();
+    LOG_WITH_STREAM(IncrementalPDFVerbose, stream << message);
+}
+
+void PDFPlugin::logStreamLoader(WTF::TextStream& stream, WebCore::NetscapePlugInStreamLoader& loader)
+{
+    ASSERT(isMainThread());
+
+    auto* request = byteRangeRequestForLoader(loader);
+    stream << "(";
+    if (!request) {
+        stream << "no range request found) ";
+        return;
+    }
+
+    stream << request->position() << "-" << request->position() + request->count() - 1 << ") ";
+}
+
+void PDFPlugin::verboseLog()
+{
+    ASSERT(isMainThread());
+
+    TextStream stream;
+    stream << "\n";
+    if (m_pdfThread)
+        stream << "Initial PDF thread is still in progress\n";
+    else
+        stream << "Initial PDF thread has completed\n";
+
+    stream << "Have completed " << m_completedRangeRequests << " range requests (" << m_completedNetworkRangeRequests << " from the network)\n";
+    stream << "There are " << m_threadsWaitingOnCallback << " data provider threads waiting on a reply\n";
+    stream << "There are " << m_outstandingByteRangeRequests.size() << " byte range requests outstanding\n";
+
+    stream << "There are " << m_streamLoaderMap.size() << " active network stream loaders: ";
+    for (auto& loader : m_streamLoaderMap.keys())
+        logStreamLoader(stream, *loader);
+    stream << "\n";
+
+    stream << "The main document loader has finished loading " << m_streamedBytes << " bytes, and is";
+    if (!m_documentFinishedLoading)
+        stream << " not";
+    stream << " complete";
+
+    LOG(IncrementalPDFVerbose, "%s", stream.release().utf8().data());
+}
+#endif // !LOG_DISABLED
+
 static size_t dataProviderGetBytesAtPositionCallback(void* info, void* buffer, off_t position, size_t count)
 {
     ASSERT(!isMainThread());
-    LOG(PDF, "PDF data provider requesting %lu bytes at position %llu", count, position);
 
+#if !LOG_DISABLED
+    Ref<PDFPlugin> debugPluginRef = *((PDFPlugin*)info);
+    debugPluginRef->incrementThreadsWaitingOnCallback();
+    debugPluginRef->pdfLog(makeString("PDF data provider requesting ", count, " bytes at position ", position));
+#endif
+
     Ref<PDFPlugin> plugin = *((PDFPlugin*)info);
     WTF::Semaphore dataSemaphore { 0 };
     size_t bytesProvided = 0;
@@ -651,6 +715,12 @@
     });
 
     dataSemaphore.wait();
+
+#if !LOG_DISABLED
+    debugPluginRef->decrementThreadsWaitingOnCallback();
+    debugPluginRef->pdfLog(makeString("PDF data provider received ", bytesProvided, " bytes of requested ", count));
+#endif
+
     return bytesProvided;
 }
 
@@ -658,7 +728,9 @@
 {
     ASSERT(!isMainThread());
 
-#ifndef NDEBUG
+#if !LOG_DISABLED
+    Ref<PDFPlugin> debugPluginRef = *((PDFPlugin*)info);
+    debugPluginRef->incrementThreadsWaitingOnCallback();
     TextStream stream;
     stream << "PDF data provider requesting " << count << " byte ranges (";
     for (size_t i = 0; i < count; ++i) {
@@ -667,7 +739,7 @@
             stream << ", ";
     }
     stream << ")";
-    LOG(PDF, "%s", stream.release().utf8().data());
+    debugPluginRef->pdfLog(stream.release());
 #endif
 
     Ref<PDFPlugin> plugin = *((PDFPlugin*)info);
@@ -687,6 +759,11 @@
     for (size_t i = 0; i < count; ++i)
         dataSemaphore.wait();
 
+#if !LOG_DISABLED
+    debugPluginRef->decrementThreadsWaitingOnCallback();
+    debugPluginRef->pdfLog(makeString("PDF data provider finished receiving the requested ", count, " byte ranges"));
+#endif
+
     for (auto& result : dataResults) {
         if (!result)
             result = adoptCF(CFDataCreate(kCFAllocatorDefault, 0, 0));
@@ -728,6 +805,8 @@
 
     firstPageSemaphore.wait();
 
+    pdfLog("Fininished preloading first page");
+
     // The main thread dispatch below removes the last reference to the PDF thread.
     // It must be the last code executed in this function.
     callOnMainThread([protectedPlugin = WTFMove(protectedPlugin)] { });
@@ -769,7 +848,9 @@
     resourceRequest.setHTTPHeaderField(HTTPHeaderName::Range, makeString("bytes="_s, position, "-"_s, position + count - 1));
     resourceRequest.setCachePolicy(ResourceRequestCachePolicy::DoNotUseAnyCache);
 
-    LOG(PDF, "Scheduling a stream loader for request %llu (%lu bytes at %llu)\n", identifier, count, position);
+#if !LOG_DISABLED
+    pdfLog(makeString("Scheduling a stream loader for request ", identifier, " (", count, " bytes at ", position, ")"));
+#endif
 
     WebProcess::singleton().webLoaderStrategy().schedulePluginStreamLoad(*coreFrame, *this, WTFMove(resourceRequest), [this, protectedThis = makeRef(*this), identifier] (RefPtr<WebCore::NetscapePlugInStreamLoader>&& loader) {
         auto iterator = m_outstandingByteRangeRequests.find(identifier);
@@ -780,7 +861,10 @@
 
         iterator->value.setStreamLoader(loader.get());
         m_streamLoaderMap.set(WTFMove(loader), identifier);
-        LOG(PDF, "There are now %u stream loaders in flight", m_streamLoaderMap.size());
+
+#if !LOG_DISABLED
+        pdfLog(makeString("There are now ", m_streamLoaderMap.size(), " stream loaders in flight"));
+#endif
     });
 }
 
@@ -790,6 +874,10 @@
     ASSERT(m_backgroundThreadDocument);
     ASSERT(isMainThread());
 
+#if !LOG_DISABLED
+    pdfLog("Adopting PDFDocument from background thread");
+#endif
+
     m_pdfDocument = WTFMove(m_backgroundThreadDocument);
 
     // If the plugin was manually destroyed, the m_pdfThread might already be gone.
@@ -814,7 +902,10 @@
 
 void PDFPlugin::ByteRangeRequest::completeWithBytes(const uint8_t* data, size_t count, PDFPlugin& plugin)
 {
-    LOG(PDF, "Completing range request %llu (%lu bytes at %llu) with %lu bytes from the main PDF buffer", identifier(), m_count, m_position, count);
+#if !LOG_DISABLED
+    ++plugin.m_completedRangeRequests;
+    plugin.pdfLog(makeString("Completing range request ", identifier()," (", m_count," bytes at ", m_position,") with ", count," bytes from the main PDF buffer"));
+#endif
     m_completionHandler(data, count);
 
     if (m_streamLoader)
@@ -823,7 +914,12 @@
 
 void PDFPlugin::ByteRangeRequest::completeWithAccumulatedData(PDFPlugin& plugin)
 {
-    LOG(PDF, "Completing range request %llu (%lu bytes at %llu) with %lu bytes from the network", identifier(), m_count, m_position, m_accumulatedData.size());
+#if !LOG_DISABLED
+    ++plugin.m_completedRangeRequests;
+    ++plugin.m_completedNetworkRangeRequests;
+    plugin.pdfLog(makeString("Completing range request ", identifier()," (", m_count," bytes at ", m_position,") with ", m_accumulatedData.size()," bytes from the network"));
+#endif
+
     m_completionHandler(m_accumulatedData.data(), m_accumulatedData.size());
     
     if (m_streamLoader)
@@ -852,7 +948,7 @@
     }
 
     if (plugin.m_completedRanges.contains({ m_position, m_position + m_count - 1 })) {
-        LOG(PDF, "Completing request %llu with a previously completed range", identifier());
+        plugin.pdfLog(makeString("Completing request %llu with a previously completed range", identifier()));
         completeWithBytes(CFDataGetBytePtr(plugin.m_data.get()) + m_position, m_count, plugin);
         return true;
     }
@@ -965,7 +1061,9 @@
 
     m_streamLoaderMap.remove(&loader);
 
-    LOG(PDF, "Forgot stream loader for range request %llu.\nThere are now %u stream loaders remaining.", identifier, m_streamLoaderMap.size());
+#if !LOG_DISABLED
+    pdfLog(makeString("Forgot stream loader for range request ", identifier,". There are now ", m_streamLoaderMap.size()," stream loaders remaining"));
+#endif
 }
 
 void PDFPlugin::cancelAndForgetLoader(NetscapePlugInStreamLoader& loader)
@@ -1307,13 +1405,14 @@
 
 void PDFPlugin::pdfDocumentDidLoad()
 {
-    LOG(PDF, "PDF document finished loading with a total of %llu bytes", m_streamedBytes);
-
     addArchiveResource();
 
     m_documentFinishedLoading = true;
 
 #if HAVE(INCREMENTAL_PDF_APIS)
+#if !LOG_DISABLED
+    pdfLog(makeString("PDF document finished loading with a total of %llu bytes", m_streamedBytes));
+#endif
     if (m_incrementalPDFLoadingEnabled) {
         // At this point we know all data for the document, and therefore we know how to answer any outstanding range requests.
         unconditionalCompleteOutstandingRangeRequests();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to