Title: [142651] trunk/Source/WebKit2
Revision
142651
Author
[email protected]
Date
2013-02-12 12:12:53 -0800 (Tue, 12 Feb 2013)

Log Message

Add WKContext API to retrieve basic network process statistics
https://bugs.webkit.org/show_bug.cgi?id=109329

Reviewed by Sam Weinig.

This patch adds a WKContextGetStatisticsWithOptions which allows the client to ask for
certain types of statistics.

It also expands the "get statistics" callback mechanism to allow for a statistics request
to be answered by multiple child processes.

That mechanism still has some rough edges but will eventually allow for getting statistics
from multiple web processes, as well.

* NetworkProcess/HostRecord.cpp:
(WebKit::HostRecord::pendingRequestCount):
(WebKit::HostRecord::activeLoadCount):
* NetworkProcess/HostRecord.h:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::getNetworkProcessStatistics):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:

* NetworkProcess/NetworkResourceLoadScheduler.cpp:
(WebKit::NetworkResourceLoadScheduler::hostsPendingCount):
(WebKit::NetworkResourceLoadScheduler::loadsPendingCount):
(WebKit::NetworkResourceLoadScheduler::hostsActiveCount):
(WebKit::NetworkResourceLoadScheduler::loadsActiveCount):
* NetworkProcess/NetworkResourceLoadScheduler.h:

* Shared/Authentication/AuthenticationManager.h:
(WebKit::AuthenticationManager::outstandingAuthenticationChallengeCount):
* Shared/Downloads/DownloadManager.h:

* UIProcess/API/C/WKContext.cpp:
(WKContextGetStatistics):
(WKContextGetStatisticsWithOptions):
* UIProcess/API/C/WKContext.h:

* UIProcess/StatisticsRequest.cpp: Added.
(WebKit::StatisticsRequest::StatisticsRequest):
(WebKit::StatisticsRequest::~StatisticsRequest):
(WebKit::StatisticsRequest::addOutstandingRequest):
(WebKit::addToDictionaryFromHashMap):
(WebKit::createDictionaryFromHashMap):
(WebKit::StatisticsRequest::completedRequest):
* UIProcess/StatisticsRequest.h: Added.
(WebKit::StatisticsRequest::create):

* UIProcess/WebContext.cpp:
(WebKit::WebContext::networkingProcessConnection):
(WebKit::WebContext::getStatistics):
(WebKit::WebContext::requestWebContentStatistics):
(WebKit::WebContext::requestNetworkingStatistics):
(WebKit::WebContext::didGetStatistics):
* UIProcess/WebContext.h:
* UIProcess/WebContext.messages.in:

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::getWebCoreStatistics):

* WebKit2.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (142650 => 142651)


--- trunk/Source/WebKit2/ChangeLog	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/ChangeLog	2013-02-12 20:12:53 UTC (rev 142651)
@@ -1,3 +1,69 @@
+2013-02-12  Brady Eidson  <[email protected]>
+
+        Add WKContext API to retrieve basic network process statistics
+        https://bugs.webkit.org/show_bug.cgi?id=109329
+
+        Reviewed by Sam Weinig.
+
+        This patch adds a WKContextGetStatisticsWithOptions which allows the client to ask for
+        certain types of statistics.
+
+        It also expands the "get statistics" callback mechanism to allow for a statistics request 
+        to be answered by multiple child processes.
+
+        That mechanism still has some rough edges but will eventually allow for getting statistics
+        from multiple web processes, as well.
+
+        * NetworkProcess/HostRecord.cpp:
+        (WebKit::HostRecord::pendingRequestCount):
+        (WebKit::HostRecord::activeLoadCount):
+        * NetworkProcess/HostRecord.h:
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::getNetworkProcessStatistics):
+        * NetworkProcess/NetworkProcess.h:
+        * NetworkProcess/NetworkProcess.messages.in:
+
+        * NetworkProcess/NetworkResourceLoadScheduler.cpp:
+        (WebKit::NetworkResourceLoadScheduler::hostsPendingCount):
+        (WebKit::NetworkResourceLoadScheduler::loadsPendingCount):
+        (WebKit::NetworkResourceLoadScheduler::hostsActiveCount):
+        (WebKit::NetworkResourceLoadScheduler::loadsActiveCount):
+        * NetworkProcess/NetworkResourceLoadScheduler.h:
+
+        * Shared/Authentication/AuthenticationManager.h:
+        (WebKit::AuthenticationManager::outstandingAuthenticationChallengeCount):
+        * Shared/Downloads/DownloadManager.h:
+
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextGetStatistics):
+        (WKContextGetStatisticsWithOptions):
+        * UIProcess/API/C/WKContext.h:
+
+        * UIProcess/StatisticsRequest.cpp: Added.
+        (WebKit::StatisticsRequest::StatisticsRequest):
+        (WebKit::StatisticsRequest::~StatisticsRequest):
+        (WebKit::StatisticsRequest::addOutstandingRequest):
+        (WebKit::addToDictionaryFromHashMap):
+        (WebKit::createDictionaryFromHashMap):
+        (WebKit::StatisticsRequest::completedRequest):
+        * UIProcess/StatisticsRequest.h: Added.
+        (WebKit::StatisticsRequest::create):
+
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::networkingProcessConnection):
+        (WebKit::WebContext::getStatistics):
+        (WebKit::WebContext::requestWebContentStatistics):
+        (WebKit::WebContext::requestNetworkingStatistics):
+        (WebKit::WebContext::didGetStatistics):
+        * UIProcess/WebContext.h:
+        * UIProcess/WebContext.messages.in:
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::getWebCoreStatistics):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2013-02-12  Anders Carlsson  <[email protected]>
 
         Build fix.

Modified: trunk/Source/WebKit2/NetworkProcess/HostRecord.cpp (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/HostRecord.cpp	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/HostRecord.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -115,6 +115,21 @@
     return false;
 }
 
+uint64_t HostRecord::pendingRequestCount() const
+{
+    uint64_t count = 0;
+
+    for (unsigned p = 0; p <= ResourceLoadPriorityHighest; p++)
+        count += m_loadersPending[p].size();
+
+    return count;
+}
+
+uint64_t HostRecord::activeLoadCount() const
+{
+    return m_loadersInProgress.size();
+}
+
 void HostRecord::servePendingRequestsForQueue(LoaderQueue& queue, ResourceLoadPriority priority)
 {
     while (!queue.isEmpty()) {

Modified: trunk/Source/WebKit2/NetworkProcess/HostRecord.h (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/HostRecord.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/HostRecord.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -58,6 +58,9 @@
     bool hasRequests() const;
     void servePendingRequests(WebCore::ResourceLoadPriority);
 
+    uint64_t pendingRequestCount() const;
+    uint64_t activeLoadCount() const;
+
 private:
     HostRecord(const String& name, int maxRequestsInFlight);
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -37,6 +37,8 @@
 #include "NetworkProcessCreationParameters.h"
 #include "NetworkProcessProxyMessages.h"
 #include "RemoteNetworkingContext.h"
+#include "StatisticsData.h"
+#include "WebContextMessages.h"
 #include "WebCookieManager.h"
 #include <WebCore/InitializeLogging.h>
 #include <WebCore/ResourceRequest.h>
@@ -216,6 +218,22 @@
     }
 }
 
+void NetworkProcess::getNetworkProcessStatistics(uint64_t callbackID)
+{
+    NetworkResourceLoadScheduler& scheduler = NetworkProcess::shared().networkResourceLoadScheduler();
+
+    StatisticsData data;
+
+    data.statisticsNumbers.set("HostsPendingCount", scheduler.hostsPendingCount());
+    data.statisticsNumbers.set("HostsActiveCount", scheduler.hostsActiveCount());
+    data.statisticsNumbers.set("LoadsPendingCount", scheduler.loadsPendingCount());
+    data.statisticsNumbers.set("LoadsActiveCount", scheduler.loadsActiveCount());
+    data.statisticsNumbers.set("DownloadsActiveCount", shared().downloadManager().activeDownloadCount());
+    data.statisticsNumbers.set("OutstandingAuthenticationChallengesCount", shared().authenticationManager().outstandingAuthenticationChallengeCount());
+
+    parentProcessConnection()->send(Messages::WebContext::DidGetStatistics(data, callbackID), 0);
+}
+
 #if !PLATFORM(MAC)
 void NetworkProcess::initializeProcessName(const ChildProcessInitializationParameters&)
 {

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -107,6 +107,8 @@
 
     void allowSpecificHTTPSCertificateForHost(const PlatformCertificateInfo&, const String& host);
 
+    void getNetworkProcessStatistics(uint64_t callbackID);
+
     // Platform Helpers
     void platformSetCacheModel(CacheModel);
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in	2013-02-12 20:12:53 UTC (rev 142651)
@@ -40,6 +40,8 @@
 #endif
 
     AllowSpecificHTTPSCertificateForHost(WebKit::PlatformCertificateInfo certificate, WTF::String host)
+    
+    GetNetworkProcessStatistics(uint64_t callbackID)
 }
 
 #endif // ENABLE(NETWORK_PROCESS)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -4,7 +4,8 @@
 #include "HostRecord.h"
 #include "Logging.h"
 #include "NetworkConnectionToWebProcess.h"
-#include "NetworkProcessconnectionMessages.h"
+#include "NetworkProcess.h"
+#include "NetworkProcessConnectionMessages.h"
 #include "NetworkResourceLoadParameters.h"
 #include "NetworkResourceLoader.h"
 #include "SyncNetworkResourceLoader.h"
@@ -174,6 +175,57 @@
     }
 }
 
+uint64_t NetworkResourceLoadScheduler::hostsPendingCount() const
+{
+    uint64_t count = m_nonHTTPProtocolHost->pendingRequestCount() ? 1 : 0;
+
+    HostMap::const_iterator end = m_hosts.end();
+    for (HostMap::const_iterator i = m_hosts.begin(); i != end; ++i) {
+        if (i->value->pendingRequestCount())
+            ++count;
+    }
+
+    return count;
+}
+
+uint64_t NetworkResourceLoadScheduler::loadsPendingCount() const
+{
+    uint64_t count = m_nonHTTPProtocolHost->pendingRequestCount();
+
+    HostMap::const_iterator end = m_hosts.end();
+    for (HostMap::const_iterator i = m_hosts.begin(); i != end; ++i)
+        count += i->value->pendingRequestCount();
+
+    return count;
+}
+
+uint64_t NetworkResourceLoadScheduler::hostsActiveCount() const
+{
+    uint64_t count = 0;
+
+    if (m_nonHTTPProtocolHost->activeLoadCount())
+        count = 1;
+
+    HostMap::const_iterator end = m_hosts.end();
+    for (HostMap::const_iterator i = m_hosts.begin(); i != end; ++i) {
+        if (i->value->activeLoadCount())
+            ++count;
+    }
+
+    return count;
+}
+
+uint64_t NetworkResourceLoadScheduler::loadsActiveCount() const
+{
+    uint64_t count = m_nonHTTPProtocolHost->activeLoadCount();
+
+    HostMap::const_iterator end = m_hosts.end();
+    for (HostMap::const_iterator i = m_hosts.begin(); i != end; ++i)
+        count += i->value->activeLoadCount();
+
+    return count;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.h (142650 => 142651)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -57,7 +57,13 @@
 
     void receivedRedirect(SchedulableLoader*, const WebCore::KURL& redirectURL);
     void servePendingRequests(WebCore::ResourceLoadPriority = WebCore::ResourceLoadPriorityVeryLow);
-    
+
+    // For NetworkProcess statistics reporting.
+    uint64_t hostsPendingCount() const;
+    uint64_t loadsPendingCount() const;
+    uint64_t hostsActiveCount() const;
+    uint64_t loadsActiveCount() const;
+
 private:
     enum CreateHostPolicy {
         CreateIfNotFound,

Modified: trunk/Source/WebKit2/Shared/Authentication/AuthenticationManager.h (142650 => 142651)


--- trunk/Source/WebKit2/Shared/Authentication/AuthenticationManager.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/Shared/Authentication/AuthenticationManager.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -62,6 +62,8 @@
     void useCredentialForChallenge(uint64_t challengeID, const WebCore::Credential&, const PlatformCertificateInfo&);
     void continueWithoutCredentialForChallenge(uint64_t challengeID);
     void cancelChallenge(uint64_t challengeID);
+    
+    uint64_t outstandingAuthenticationChallengeCount() const { return m_challenges.size(); }
 
 private:
     // CoreIPC::MessageReceiver

Modified: trunk/Source/WebKit2/Shared/Downloads/DownloadManager.h (142650 => 142651)


--- trunk/Source/WebKit2/Shared/Downloads/DownloadManager.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/Shared/Downloads/DownloadManager.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -69,6 +69,7 @@
 
     void downloadFinished(Download*);
     bool isDownloading() const { return !m_downloads.isEmpty(); }
+    uint64_t activeDownloadCount() const { return m_downloads.size(); }
 
     void didCreateDownload();
     void didDestroyDownload();

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp (142650 => 142651)


--- trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -331,9 +331,14 @@
 
 void WKContextGetStatistics(WKContextRef contextRef, void* context, WKContextGetStatisticsFunction callback)
 {
-    toImpl(contextRef)->getWebCoreStatistics(DictionaryCallback::create(context, callback));    
+    toImpl(contextRef)->getStatistics(0xFFFFFFFF, DictionaryCallback::create(context, callback));
 }
 
+void WKContextGetStatisticsWithOptions(WKContextRef contextRef, WKStatisticsOptions optionsMask, void* context, WKContextGetStatisticsFunction callback)
+{
+    toImpl(contextRef)->getStatistics(optionsMask, DictionaryCallback::create(context, callback));
+}
+
 void WKContextGarbageCollectJavaScriptObjects(WKContextRef contextRef)
 {
     toImpl(contextRef)->garbageCollectJavaScriptObjects();

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKContext.h (142650 => 142651)


--- trunk/Source/WebKit2/UIProcess/API/C/WKContext.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKContext.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -143,6 +143,12 @@
 };
 typedef uint32_t WKProcessModel;
 
+enum {
+    kWKStatisticsOptionsWebContent = 1 << 0,
+    kWKStatisticsOptionsNetworking = 1 << 1
+};
+typedef uint32_t WKStatisticsOptions;
+
 WK_EXPORT WKTypeID WKContextGetTypeID();
 
 WK_EXPORT WKContextRef WKContextCreate();
@@ -188,7 +194,8 @@
     
 typedef void (*WKContextGetStatisticsFunction)(WKDictionaryRef statistics, WKErrorRef error, void* functionContext);
 WK_EXPORT void WKContextGetStatistics(WKContextRef context, void* functionContext, WKContextGetStatisticsFunction function);
-    
+WK_EXPORT void WKContextGetStatisticsWithOptions(WKContextRef context, WKStatisticsOptions statisticsMask, void* functionContext, WKContextGetStatisticsFunction function);
+
 WK_EXPORT void WKContextGarbageCollectJavaScriptObjects(WKContextRef context);
 WK_EXPORT void WKContextSetJavaScriptGarbageCollectorTimerEnabled(WKContextRef context, bool enable);
 

Added: trunk/Source/WebKit2/UIProcess/StatisticsRequest.cpp (0 => 142651)


--- trunk/Source/WebKit2/UIProcess/StatisticsRequest.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/StatisticsRequest.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2013 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 "StatisticsRequest.h"
+
+#include "ImmutableArray.h"
+#include "MutableDictionary.h"
+#include <wtf/Atomics.h>
+
+namespace WebKit {
+
+StatisticsRequest::StatisticsRequest(PassRefPtr<DictionaryCallback> callback)
+    : m_callback(callback)
+{
+}
+
+StatisticsRequest::~StatisticsRequest()
+{
+    if (m_callback)
+        m_callback->invalidate();
+}
+
+uint64_t StatisticsRequest::addOutstandingRequest()
+{
+    static int64_t uniqueRequestID;
+
+    uint64_t requestID = atomicIncrement(&uniqueRequestID);
+    m_outstandingRequests.add(requestID);
+    return requestID;
+}
+
+static void addToDictionaryFromHashMap(MutableDictionary* dictionary, const HashMap<String, uint64_t>& map)
+{
+    HashMap<String, uint64_t>::const_iterator end = map.end();
+    for (HashMap<String, uint64_t>::const_iterator it = map.begin(); it != end; ++it)
+        dictionary->set(it->key, RefPtr<WebUInt64>(WebUInt64::create(it->value)).get());
+}
+
+static PassRefPtr<MutableDictionary> createDictionaryFromHashMap(const HashMap<String, uint64_t>& map)
+{
+    RefPtr<MutableDictionary> result = MutableDictionary::create();
+    addToDictionaryFromHashMap(result.get(), map);
+    return result;
+}
+
+void StatisticsRequest::completedRequest(uint64_t requestID, const StatisticsData& data)
+{
+    ASSERT(m_outstandingRequests.contains(requestID));
+    m_outstandingRequests.remove(requestID);
+
+    if (!m_responseDictionary)
+        m_responseDictionary = MutableDictionary::create();
+    
+    // FIXME (Multi-WebProcess) <rdar://problem/13200059>: This code overwrites any previous response data received.
+    // When getting responses from multiple WebProcesses we need to combine items instead of clobbering them.
+
+    addToDictionaryFromHashMap(m_responseDictionary.get(), data.statisticsNumbers);
+
+    if (!data._javascript_ProtectedObjectTypeCounts.isEmpty())
+        m_responseDictionary->set("_javascript_ProtectedObjectTypeCounts", createDictionaryFromHashMap(data._javascript_ProtectedObjectTypeCounts).get());
+    if (!data._javascript_ObjectTypeCounts.isEmpty())
+        m_responseDictionary->set("_javascript_ObjectTypeCounts", createDictionaryFromHashMap(data._javascript_ObjectTypeCounts).get());
+    
+    size_t cacheStatisticsCount = data.webCoreCacheStatistics.size();
+    if (cacheStatisticsCount) {
+        Vector<RefPtr<APIObject> > cacheStatisticsVector(cacheStatisticsCount);
+        for (size_t i = 0; i < cacheStatisticsCount; ++i)
+            cacheStatisticsVector[i] = createDictionaryFromHashMap(data.webCoreCacheStatistics[i]);
+        m_responseDictionary->set("WebCoreCacheStatistics", ImmutableArray::adopt(cacheStatisticsVector).get());
+    }
+
+    if (m_outstandingRequests.isEmpty()) {
+        m_callback->performCallbackWithReturnValue(m_responseDictionary.get());
+        m_callback = 0;
+    }
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit2/UIProcess/StatisticsRequest.h (0 => 142651)


--- trunk/Source/WebKit2/UIProcess/StatisticsRequest.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/StatisticsRequest.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#ifndef StatisticsRequest_h
+#define StatisticsRequest_h
+
+#include "GenericCallback.h"
+#include "StatisticsData.h"
+
+#include <wtf/HashSet.h>
+
+namespace WebKit {
+
+struct StatisticsData;
+
+typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
+
+enum StatisticsRequestType {
+    StatisticsRequestTypeWebContent = 0x00000001,
+    StatisticsRequestTypeNetworking = 0x00000002
+};
+
+class StatisticsRequest : public RefCounted<StatisticsRequest> {
+public:
+    static PassRefPtr<StatisticsRequest> create(PassRefPtr<DictionaryCallback> callback)
+    {
+        return adoptRef(new StatisticsRequest(callback));
+    }
+
+    ~StatisticsRequest();
+
+    uint64_t addOutstandingRequest();
+
+    void completedRequest(uint64_t requestID, const StatisticsData&);
+
+private:
+    StatisticsRequest(PassRefPtr<DictionaryCallback>);
+
+    HashSet<uint64_t> m_outstandingRequests;
+    RefPtr<DictionaryCallback> m_callback;
+
+    RefPtr<MutableDictionary> m_responseDictionary;
+};
+
+} // namespace WebKit
+
+#endif // StatisticsRequest_h

Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (142650 => 142651)


--- trunk/Source/WebKit2/UIProcess/WebContext.cpp	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -303,9 +303,14 @@
 {
     switch (m_processModel) {
     case ProcessModelSharedSecondaryProcess:
+#if ENABLE(NETWORK_PROCESS)
+        if (m_usesNetworkProcess)
+            return m_networkProcess->connection();
+#endif
         return m_processes[0]->connection();
     case ProcessModelMultipleSecondaryProcesses:
 #if ENABLE(NETWORK_PROCESS)
+        ASSERT(m_usesNetworkProcess);
         return m_networkProcess->connection();
 #else
         break;
@@ -1071,32 +1076,56 @@
 #endif
 }
 
-void WebContext::getWebCoreStatistics(PassRefPtr<DictionaryCallback> callback)
+void WebContext::getStatistics(uint32_t statisticsMask, PassRefPtr<DictionaryCallback> callback)
 {
+    if (!statisticsMask) {
+        callback->invalidate();
+        return;
+    }
+
+    RefPtr<StatisticsRequest> request = StatisticsRequest::create(callback);
+
+    if (statisticsMask & StatisticsRequestTypeWebContent)
+        requestWebContentStatistics(request.get());
+    
+    if (statisticsMask & StatisticsRequestTypeNetworking)
+        requestNetworkingStatistics(request.get());
+}
+
+void WebContext::requestWebContentStatistics(StatisticsRequest* request)
+{
     if (m_processModel == ProcessModelSharedSecondaryProcess) {
-        if (m_processes.isEmpty()) {
-            callback->invalidate();
+        if (m_processes.isEmpty())
             return;
-        }
         
-        uint64_t callbackID = callback->callbackID();
-        m_dictionaryCallbacks.set(callbackID, callback.get());
-        m_processes[0]->send(Messages::WebProcess::GetWebCoreStatistics(callbackID), 0);
+        uint64_t requestID = request->addOutstandingRequest();
+        m_statisticsRequests.set(requestID, request);
+        m_processes[0]->send(Messages::WebProcess::GetWebCoreStatistics(requestID), 0);
 
     } else {
-        // FIXME (Multi-WebProcess): <rdar://problem/12239483> Make downloading work.
-        callback->invalidate();
+        // FIXME (Multi-WebProcess) <rdar://problem/13200059>: Make getting statistics from multiple WebProcesses work.
     }
 }
 
-static PassRefPtr<MutableDictionary> createDictionaryFromHashMap(const HashMap<String, uint64_t>& map)
+void WebContext::requestNetworkingStatistics(StatisticsRequest* request)
 {
-    RefPtr<MutableDictionary> result = MutableDictionary::create();
-    HashMap<String, uint64_t>::const_iterator end = map.end();
-    for (HashMap<String, uint64_t>::const_iterator it = map.begin(); it != end; ++it)
-        result->set(it->key, RefPtr<WebUInt64>(WebUInt64::create(it->value)).get());
-    
-    return result;
+    bool networkProcessUnavailable;
+#if ENABLE(NETWORK_PROCESS)
+    networkProcessUnavailable = !m_usesNetworkProcess || !m_networkProcess;
+#else
+    networkProcessUnavailable = true;
+#endif
+
+    if (networkProcessUnavailable) {
+        LOG_ERROR("Attempt to get NetworkProcess statistics but the NetworkProcess is unavailable");
+        return;
+    }
+
+#if ENABLE(NETWORK_PROCESS)
+    uint64_t requestID = request->addOutstandingRequest();
+    m_statisticsRequests.set(requestID, request);
+    m_networkProcess->send(Messages::NetworkProcess::GetNetworkProcessStatistics(requestID), 0);
+#endif
 }
 
 #if !PLATFORM(MAC)
@@ -1105,25 +1134,15 @@
 }
 #endif
 
-void WebContext::didGetWebCoreStatistics(const StatisticsData& statisticsData, uint64_t callbackID)
+void WebContext::didGetStatistics(const StatisticsData& statisticsData, uint64_t requestID)
 {
-    RefPtr<DictionaryCallback> callback = m_dictionaryCallbacks.take(callbackID);
-    if (!callback) {
-        // FIXME: Log error or assert.
+    RefPtr<StatisticsRequest> request = m_statisticsRequests.take(requestID);
+    if (!request) {
+        LOG_ERROR("Cannot report networking statistics.");
         return;
     }
 
-    RefPtr<MutableDictionary> statistics = createDictionaryFromHashMap(statisticsData.statisticsNumbers);
-    statistics->set("_javascript_ProtectedObjectTypeCounts", createDictionaryFromHashMap(statisticsData._javascript_ProtectedObjectTypeCounts).get());
-    statistics->set("_javascript_ObjectTypeCounts", createDictionaryFromHashMap(statisticsData._javascript_ObjectTypeCounts).get());
-    
-    size_t cacheStatisticsCount = statisticsData.webCoreCacheStatistics.size();
-    Vector<RefPtr<APIObject> > cacheStatisticsVector(cacheStatisticsCount);
-    for (size_t i = 0; i < cacheStatisticsCount; ++i)
-        cacheStatisticsVector[i] = createDictionaryFromHashMap(statisticsData.webCoreCacheStatistics[i]);
-    statistics->set("WebCoreCacheStatistics", ImmutableArray::adopt(cacheStatisticsVector).get());
-    
-    callback->performCallbackWithReturnValue(statistics.get());
+    request->completedRequest(requestID, statisticsData);
 }
     
 void WebContext::garbageCollectJavaScriptObjects()

Modified: trunk/Source/WebKit2/UIProcess/WebContext.h (142650 => 142651)


--- trunk/Source/WebKit2/UIProcess/WebContext.h	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/UIProcess/WebContext.h	2013-02-12 20:12:53 UTC (rev 142651)
@@ -35,6 +35,7 @@
 #include "PlugInAutoStartProvider.h"
 #include "PluginInfoStore.h"
 #include "ProcessModel.h"
+#include "StatisticsRequest.h"
 #include "StorageManager.h"
 #include "VisitedLinkProvider.h"
 #include "WebContextClient.h"
@@ -242,8 +243,9 @@
     // Defaults to false.
     void setHTTPPipeliningEnabled(bool);
     bool httpPipeliningEnabled() const;
+
+    void getStatistics(uint32_t statisticsMask, PassRefPtr<DictionaryCallback>);
     
-    void getWebCoreStatistics(PassRefPtr<DictionaryCallback>);
     void garbageCollectJavaScriptObjects();
     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
 
@@ -300,6 +302,9 @@
 
     WebProcessProxy* createNewWebProcess();
 
+    void requestWebContentStatistics(StatisticsRequest*);
+    void requestNetworkingStatistics(StatisticsRequest*);
+
 #if ENABLE(NETWORK_PROCESS)
     void platformInitializeNetworkProcess(NetworkProcessCreationParameters&);
 #endif
@@ -327,7 +332,7 @@
     void dummy(bool&);
 #endif
 
-    void didGetWebCoreStatistics(const StatisticsData&, uint64_t callbackID);
+    void didGetStatistics(const StatisticsData&, uint64_t callbackID);
         
     // Implemented in generated WebContextMessageReceiver.cpp
     void didReceiveWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
@@ -453,6 +458,7 @@
 #endif
     
     HashMap<uint64_t, RefPtr<DictionaryCallback> > m_dictionaryCallbacks;
+    HashMap<uint64_t, RefPtr<StatisticsRequest> > m_statisticsRequests;
 
 #if PLATFORM(MAC)
     bool m_processSuppressionEnabled;

Modified: trunk/Source/WebKit2/UIProcess/WebContext.messages.in (142650 => 142651)


--- trunk/Source/WebKit2/UIProcess/WebContext.messages.in	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/UIProcess/WebContext.messages.in	2013-02-12 20:12:53 UTC (rev 142651)
@@ -25,7 +25,7 @@
     # Visited link provider messages.
     AddVisitedLinkHash(uint64_t linkHash)
 
-    DidGetWebCoreStatistics(WebKit::StatisticsData statisticsData, uint64_t callbackID)
+    DidGetStatistics(WebKit::StatisticsData statisticsData, uint64_t callbackID)
 
 #if PLATFORM(MAC)
     # Pasteboard messages.

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (142650 => 142651)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-02-12 20:12:53 UTC (rev 142651)
@@ -451,6 +451,7 @@
 		513A163D163088F6005D7D22 /* NetworkProcessProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 513A163B163088F6005D7D22 /* NetworkProcessProxyMessages.h */; };
 		513A164C1630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */; };
 		513A164D1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */; };
+		514BDED316C98EDD00E4E25E /* StatisticsRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 514BDED216C98EDD00E4E25E /* StatisticsRequest.h */; };
 		5153569C1291B1D2000749DC /* WebPageContextMenuClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5153569A1291B1D2000749DC /* WebPageContextMenuClient.cpp */; };
 		5153569D1291B1D2000749DC /* WebPageContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 5153569B1291B1D2000749DC /* WebPageContextMenuClient.h */; };
 		51578B831209ECEF00A37C4A /* WebData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51578B821209ECEF00A37C4A /* WebData.h */; };
@@ -496,6 +497,7 @@
 		518E8F0D16B2093700E91429 /* DownloadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 518E8F0516B2093700E91429 /* DownloadMac.mm */; };
 		519B4FF416A9EA970066874D /* SchedulableLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 519B4FF216A9EA970066874D /* SchedulableLoader.cpp */; };
 		519B4FF516A9EA970066874D /* SchedulableLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 519B4FF316A9EA970066874D /* SchedulableLoader.h */; };
+		51A4D5A916CAC4FF000E615E /* StatisticsRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */; };
 		51A555F5128C6C47009ABCEC /* WKContextMenuItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51A555F3128C6C47009ABCEC /* WKContextMenuItem.cpp */; };
 		51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 51A55600128C6D92009ABCEC /* WKContextMenuItemTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1779,6 +1781,7 @@
 		513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkConnectionToWebProcess.cpp; path = NetworkProcess/NetworkConnectionToWebProcess.cpp; sourceTree = "<group>"; };
 		513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkConnectionToWebProcess.h; path = NetworkProcess/NetworkConnectionToWebProcess.h; sourceTree = "<group>"; };
 		513A164B1630A9BF005D7D22 /* NetworkConnectionToWebProcess.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = NetworkConnectionToWebProcess.messages.in; path = NetworkProcess/NetworkConnectionToWebProcess.messages.in; sourceTree = "<group>"; };
+		514BDED216C98EDD00E4E25E /* StatisticsRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StatisticsRequest.h; sourceTree = "<group>"; };
 		5153569A1291B1D2000749DC /* WebPageContextMenuClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageContextMenuClient.cpp; sourceTree = "<group>"; };
 		5153569B1291B1D2000749DC /* WebPageContextMenuClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageContextMenuClient.h; sourceTree = "<group>"; };
 		51578B821209ECEF00A37C4A /* WebData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebData.h; sourceTree = "<group>"; };
@@ -1818,6 +1821,7 @@
 		518E8F0516B2093700E91429 /* DownloadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadMac.mm; sourceTree = "<group>"; };
 		519B4FF216A9EA970066874D /* SchedulableLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SchedulableLoader.cpp; path = NetworkProcess/SchedulableLoader.cpp; sourceTree = "<group>"; };
 		519B4FF316A9EA970066874D /* SchedulableLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SchedulableLoader.h; path = NetworkProcess/SchedulableLoader.h; sourceTree = "<group>"; };
+		51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StatisticsRequest.cpp; sourceTree = "<group>"; };
 		51A555F3128C6C47009ABCEC /* WKContextMenuItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKContextMenuItem.cpp; sourceTree = "<group>"; };
 		51A555F4128C6C47009ABCEC /* WKContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextMenuItem.h; sourceTree = "<group>"; };
 		51A55600128C6D92009ABCEC /* WKContextMenuItemTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextMenuItemTypes.h; sourceTree = "<group>"; };
@@ -3690,6 +3694,8 @@
 				BC597074116591D000551FCA /* ProcessModel.h */,
 				BC111B08112F5E3C00337BAB /* ResponsivenessTimer.cpp */,
 				1A30066C1110F4F70031937C /* ResponsivenessTimer.h */,
+				51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */,
+				514BDED216C98EDD00E4E25E /* StatisticsRequest.h */,
 				1AA417C912C00CCA002BE67B /* TextChecker.h */,
 				1A0F29E1120B44420053D1B9 /* VisitedLinkProvider.cpp */,
 				1A0F29E2120B44420053D1B9 /* VisitedLinkProvider.h */,
@@ -5375,6 +5381,7 @@
 				BC989D85161A9890000D46D3 /* WKWebProcessPlugInInternal.h in Headers */,
 				BC2E6E8E1141971500A63B1E /* WorkQueue.h in Headers */,
 				BCBECDE816B6416800047A1A /* XPCServiceEntryPoint.h in Headers */,
+				514BDED316C98EDD00E4E25E /* StatisticsRequest.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -6498,6 +6505,7 @@
 				BC2E6E8D1141971500A63B1E /* WorkQueue.cpp in Sources */,
 				BC0092F8115837A300E0AE2A /* WorkQueueMac.cpp in Sources */,
 				BCBECDE716B6416800047A1A /* XPCServiceEntryPoint.mm in Sources */,
+				51A4D5A916CAC4FF000E615E /* StatisticsRequest.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (142650 => 142651)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2013-02-12 19:56:08 UTC (rev 142650)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2013-02-12 20:12:53 UTC (rev 142651)
@@ -901,7 +901,7 @@
     // Get WebCore memory cache statistics
     getWebCoreMemoryCacheStatistics(data.webCoreCacheStatistics);
     
-    parentProcessConnection()->send(Messages::WebContext::DidGetWebCoreStatistics(data, callbackID), 0);
+    parentProcessConnection()->send(Messages::WebContext::DidGetStatistics(data, callbackID), 0);
 }
 
 void WebProcess::garbageCollectJavaScriptObjects()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to