<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[210733] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/210733">210733</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2017-01-13 09:54:53 -0800 (Fri, 13 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Report post-page load CPU usage using diagnostic logging
https://bugs.webkit.org/show_bug.cgi?id=166950
&lt;rdar://problem/30014496&gt;

Reviewed by Alex Christensen.

Shortly after page load (5 seconds), we measure the WebContent process'
CPU usage over 10 seconds and report the percentage back via release
logging. We also log the percentage using diagnostic logging using the
following buckets:
- Below 10%
- 10 to 20%
- 20 to 40%
- 60 to 80%
- Over 80%

The logging works on both Mac and iOS. I verified that I get results
consistent with Activity Monitor or top.

No new tests, no Web-facing behavior change, only extra logging.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::checkLoadCompleteForThisFrame):
* page/DiagnosticLoggingKeys.cpp:
(WebCore::DiagnosticLoggingKeys::postPageLoadKey):
(WebCore::DiagnosticLoggingKeys::cpuUsageKey):
* page/DiagnosticLoggingKeys.h:
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::didFinishLoad):
(WebCore::cpuUsageToDiagnosticLogginKey):
(WebCore::Page::measurePostLoadCPUUsage):
* page/Page.h:
* page/Settings.cpp:
(WebCore::Settings::isPostLoadCPUUsageMeasurementEnabled):
* page/Settings.h:
* platform/CPUTime.cpp: Added.
(WebCore::getCPUTime):
(WebCore::CPUTime::percentageCPUUsageSince):
* platform/CPUTime.h: Added.
* platform/cocoa/CPUTimeCocoa.mm: Added.
(WebCore::timeValueToMicroseconds):
(WebCore::getCPUTime):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCorepageDiagnosticLoggingKeyscpp">trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp</a></li>
<li><a href="#trunkSourceWebCorepageDiagnosticLoggingKeysh">trunk/Source/WebCore/page/DiagnosticLoggingKeys.h</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
<li><a href="#trunkSourceWebCorepageSettingscpp">trunk/Source/WebCore/page/Settings.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsh">trunk/Source/WebCore/page/Settings.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformCPUTimecpp">trunk/Source/WebCore/platform/CPUTime.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformCPUTimeh">trunk/Source/WebCore/platform/CPUTime.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaCPUTimeCocoamm">trunk/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/CMakeLists.txt        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -2054,6 +2054,7 @@
</span><span class="cx">     page/scrolling/ScrollingTreeScrollingNode.cpp
</span><span class="cx">     page/scrolling/ThreadedScrollingTree.cpp
</span><span class="cx"> 
</span><ins>+    platform/CPUTime.cpp
</ins><span class="cx">     platform/CalculationValue.cpp
</span><span class="cx">     platform/Clock.cpp
</span><span class="cx">     platform/ClockGeneric.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/ChangeLog        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2017-01-13  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Report post-page load CPU usage using diagnostic logging
+        https://bugs.webkit.org/show_bug.cgi?id=166950
+        &lt;rdar://problem/30014496&gt;
+
+        Reviewed by Alex Christensen.
+
+        Shortly after page load (5 seconds), we measure the WebContent process'
+        CPU usage over 10 seconds and report the percentage back via release
+        logging. We also log the percentage using diagnostic logging using the
+        following buckets:
+        - Below 10%
+        - 10 to 20%
+        - 20 to 40%
+        - 60 to 80%
+        - Over 80%
+
+        The logging works on both Mac and iOS. I verified that I get results
+        consistent with Activity Monitor or top.
+
+        No new tests, no Web-facing behavior change, only extra logging.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::checkLoadCompleteForThisFrame):
+        * page/DiagnosticLoggingKeys.cpp:
+        (WebCore::DiagnosticLoggingKeys::postPageLoadKey):
+        (WebCore::DiagnosticLoggingKeys::cpuUsageKey):
+        * page/DiagnosticLoggingKeys.h:
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        (WebCore::Page::didFinishLoad):
+        (WebCore::cpuUsageToDiagnosticLogginKey):
+        (WebCore::Page::measurePostLoadCPUUsage):
+        * page/Page.h:
+        * page/Settings.cpp:
+        (WebCore::Settings::isPostLoadCPUUsageMeasurementEnabled):
+        * page/Settings.h:
+        * platform/CPUTime.cpp: Added.
+        (WebCore::getCPUTime):
+        (WebCore::CPUTime::percentageCPUUsageSince):
+        * platform/CPUTime.h: Added.
+        * platform/cocoa/CPUTimeCocoa.mm: Added.
+        (WebCore::timeValueToMicroseconds):
+        (WebCore::getCPUTime):
+
</ins><span class="cx"> 2017-01-13  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r210677.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -1731,6 +1731,9 @@
</span><span class="cx">                 460CBF351D4BCD0E0092E88E /* JSDOMWindowProperties.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460CBF331D4BCCFE0092E88E /* JSDOMWindowProperties.cpp */; };
</span><span class="cx">                 460CBF361D4BCD0E0092E88E /* JSDOMWindowProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */; };
</span><span class="cx">                 4634592C1AC2271000ECB71C /* PowerObserverMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */; };
</span><ins>+                463763081E26FDD7008CD46D /* CPUTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 463763061E26FDBA008CD46D /* CPUTime.cpp */; };
+                463763091E26FDD7008CD46D /* CPUTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 463763071E26FDBA008CD46D /* CPUTime.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                4637630B1E26FDF6008CD46D /* CPUTimeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4637630A1E26FDEB008CD46D /* CPUTimeCocoa.mm */; };
</ins><span class="cx">                 463EB6221B8789E00096ED51 /* TagCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 463EB6201B8789CB0096ED51 /* TagCollection.cpp */; };
</span><span class="cx">                 463EB6231B8789E00096ED51 /* TagCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 463EB6211B8789CB0096ED51 /* TagCollection.h */; };
</span><span class="cx">                 465307D01DB6EE4800E4137C /* JSUIEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E045EF1DAA104F00B0D8B9 /* JSUIEventInit.h */; };
</span><span class="lines">@@ -8922,6 +8925,9 @@
</span><span class="cx">                 460CBF331D4BCCFE0092E88E /* JSDOMWindowProperties.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWindowProperties.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMWindowProperties.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PowerObserverMac.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                463763061E26FDBA008CD46D /* CPUTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUTime.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                463763071E26FDBA008CD46D /* CPUTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPUTime.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                4637630A1E26FDEB008CD46D /* CPUTimeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CPUTimeCocoa.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 463EB6201B8789CB0096ED51 /* TagCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagCollection.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 463EB6211B8789CB0096ED51 /* TagCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagCollection.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 465A8E781C8A24CE00E7D3E4 /* RuntimeApplicationChecks.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RuntimeApplicationChecks.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -19758,6 +19764,7 @@
</span><span class="cx">                 A5C974CE11485FDA0066F2AB /* cocoa */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                4637630A1E26FDEB008CD46D /* CPUTimeCocoa.mm */,
</ins><span class="cx">                                 A14090FA1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm */,
</span><span class="cx">                                 CD7D33451C7A16BF00041293 /* CoreVideoSoftLink.cpp */,
</span><span class="cx">                                 CD7D33461C7A16BF00041293 /* CoreVideoSoftLink.h */,
</span><span class="lines">@@ -22484,6 +22491,8 @@
</span><span class="cx">                                 653EF83619A043AE0052202C /* spi */,
</span><span class="cx">                                 1A2E6E560CC551E0004A2062 /* sql */,
</span><span class="cx">                                 B2C3D9EC0D006C1D00EF6F26 /* text */,
</span><ins>+                                463763061E26FDBA008CD46D /* CPUTime.cpp */,
+                                463763071E26FDBA008CD46D /* CPUTime.h */,
</ins><span class="cx">                                 49AE2D94134EE5F90072920A /* CalculationValue.cpp */,
</span><span class="cx">                                 49AE2D95134EE5F90072920A /* CalculationValue.h */,
</span><span class="cx">                                 CDEA76331460B462008B31F1 /* Clock.cpp */,
</span><span class="lines">@@ -28245,6 +28254,7 @@
</span><span class="cx">                                 5B30695E18B3D3450099D5E8 /* WebGLDrawBuffers.h in Headers */,
</span><span class="cx">                                 6EBF0E5512A8929800DB1709 /* WebGLExtension.h in Headers */,
</span><span class="cx">                                 49C7B9CF1042D32F0009D447 /* WebGLFramebuffer.h in Headers */,
</span><ins>+                                463763091E26FDD7008CD46D /* CPUTime.h in Headers */,
</ins><span class="cx">                                 6E47E66110B7944B00B186C8 /* WebGLAny.h in Headers */,
</span><span class="cx">                                 49FFBF3F11C93EE3006A7118 /* WebGLLayer.h in Headers */,
</span><span class="cx">                                 93F1D5BB12D532C400832BEC /* WebGLLoseContext.h in Headers */,
</span><span class="lines">@@ -29892,6 +29902,7 @@
</span><span class="cx">                                 2E0888D41148848A00AF4265 /* JSDOMFormData.cpp in Sources */,
</span><span class="cx">                                 E1C36CBD0EB08062007410BC /* JSDOMGlobalObject.cpp in Sources */,
</span><span class="cx">                                 7C2BDD3D17C7F98C0038FF15 /* JSDOMGlobalObjectTask.cpp in Sources */,
</span><ins>+                                463763081E26FDD7008CD46D /* CPUTime.cpp in Sources */,
</ins><span class="cx">                                 65DF31F709D1CC60000BE325 /* JSDOMImplementation.cpp in Sources */,
</span><span class="cx">                                 9479493C1E045CF300018D85 /* DeprecatedCSSOMPrimitiveValue.cpp in Sources */,
</span><span class="cx">                                 4138F8571D253F08001CB61E /* JSDOMIterator.cpp in Sources */,
</span><span class="lines">@@ -30054,6 +30065,7 @@
</span><span class="cx">                                 BC06ED9F0BFD660600856E9D /* JSHTMLTableRowElement.cpp in Sources */,
</span><span class="cx">                                 BC06ED060BFD5BAE00856E9D /* JSHTMLTableSectionElement.cpp in Sources */,
</span><span class="cx">                                 D6489D25166FFCF1007C031B /* JSHTMLTemplateElement.cpp in Sources */,
</span><ins>+                                4637630B1E26FDF6008CD46D /* CPUTimeCocoa.mm in Sources */,
</ins><span class="cx">                                 D6F7960D166FFECE0076DD18 /* JSHTMLTemplateElementCustom.cpp in Sources */,
</span><span class="cx">                                 A80E7E9E0A1A83E3007FB8C5 /* JSHTMLTextAreaElement.cpp in Sources */,
</span><span class="cx">                                 83E359A31BB1031D002CEB98 /* JSHTMLTimeElement.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -991,6 +991,11 @@
</span><span class="cx">         m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad);
</span><span class="cx">     m_frame.navigationScheduler().cancel(true);
</span><span class="cx">     m_client.provisionalLoadStarted();
</span><ins>+
+    if (m_frame.isMainFrame()) {
+        if (auto* page = m_frame.page())
+            page-&gt;didStartProvisionalLoad();
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FrameLoader::resetMultipleFormSubmissionProtection()
</span><span class="lines">@@ -2286,7 +2291,7 @@
</span><span class="cx">             Page* page = m_frame.page();
</span><span class="cx">             if (page) {
</span><span class="cx">                 if (m_frame.isMainFrame())
</span><del>-                    page-&gt;resetRelevantPaintedObjectCounter();
</del><ins>+                    page-&gt;didFinishLoad();
</ins><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             const ResourceError&amp; error = dl-&gt;mainDocumentError();
</span></span></pre></div>
<a id="trunkSourceWebCorepageDiagnosticLoggingKeyscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -53,6 +53,11 @@
</span><span class="cx">     return ASCIILiteral(&quot;pluginFailedLoading&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String DiagnosticLoggingKeys::postPageLoadKey()
+{
+    return ASCIILiteral(&quot;postPageLoad&quot;);
+}
+
</ins><span class="cx"> String DiagnosticLoggingKeys::provisionalLoadKey()
</span><span class="cx"> {
</span><span class="cx">     return ASCIILiteral(&quot;provisionalLoad&quot;);
</span><span class="lines">@@ -303,6 +308,11 @@
</span><span class="cx">     return ASCIILiteral(&quot;cannotSuspendActiveDOMObjects&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String DiagnosticLoggingKeys::cpuUsageKey()
+{
+    return ASCIILiteral(&quot;cpuUsage&quot;);
+}
+
</ins><span class="cx"> String DiagnosticLoggingKeys::createSharedBufferFailedKey()
</span><span class="cx"> {
</span><span class="cx">     return ASCIILiteral(&quot;createSharedBufferFailed&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCorepageDiagnosticLoggingKeysh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DiagnosticLoggingKeys.h (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DiagnosticLoggingKeys.h        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/page/DiagnosticLoggingKeys.h        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx">     static String cachedResourceRevalidationKey();
</span><span class="cx">     static String canCacheKey();
</span><span class="cx">     static String cannotSuspendActiveDOMObjectsKey();
</span><ins>+    static String cpuUsageKey();
</ins><span class="cx">     WEBCORE_EXPORT static String createSharedBufferFailedKey();
</span><span class="cx">     WEBCORE_EXPORT static String deltaKey();
</span><span class="cx">     static String deniedByClientKey();
</span><span class="lines">@@ -97,6 +98,7 @@
</span><span class="cx">     static String playedKey();
</span><span class="cx">     static String pluginLoadedKey();
</span><span class="cx">     static String pluginLoadingFailedKey();
</span><ins>+    static String postPageLoadKey();
</ins><span class="cx">     static String provisionalLoadKey();
</span><span class="cx">     static String prunedDueToMaxSizeReached();
</span><span class="cx">     static String prunedDueToMemoryPressureKey();
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/page/Page.cpp        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #include &quot;ContextMenuController.h&quot;
</span><span class="cx"> #include &quot;DatabaseProvider.h&quot;
</span><span class="cx"> #include &quot;DiagnosticLoggingClient.h&quot;
</span><ins>+#include &quot;DiagnosticLoggingKeys.h&quot;
</ins><span class="cx"> #include &quot;DocumentLoader.h&quot;
</span><span class="cx"> #include &quot;DocumentMarkerController.h&quot;
</span><span class="cx"> #include &quot;DragController.h&quot;
</span><span class="lines">@@ -98,6 +99,7 @@
</span><span class="cx"> #include &quot;VisitedLinkStore.h&quot;
</span><span class="cx"> #include &quot;VoidCallback.h&quot;
</span><span class="cx"> #include &quot;Widget.h&quot;
</span><ins>+#include &lt;wtf/CurrentTime.h&gt;
</ins><span class="cx"> #include &lt;wtf/RefCountedLeakCounter.h&gt;
</span><span class="cx"> #include &lt;wtf/StdLibExtras.h&gt;
</span><span class="cx"> #include &lt;wtf/text/Base64.h&gt;
</span><span class="lines">@@ -124,8 +126,13 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+#define RELEASE_LOG_IF_ALLOWED(channel, fmt, ...) RELEASE_LOG_IF(isAlwaysOnLoggingAllowed(), channel, &quot;%p - Page::&quot; fmt, this, ##__VA_ARGS__)
+
</ins><span class="cx"> static HashSet&lt;Page*&gt;* allPages;
</span><span class="cx"> 
</span><ins>+static const std::chrono::seconds cpuUsageMeasurementDelay { 5 };
+static const std::chrono::seconds cpuUsageMeasurementDuration { 10 };
+
</ins><span class="cx"> DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, pageCounter, (&quot;Page&quot;));
</span><span class="cx"> 
</span><span class="cx"> void Page::forEachPage(std::function&lt;void(Page&amp;)&gt; function)
</span><span class="lines">@@ -244,6 +251,7 @@
</span><span class="cx">     , m_visitedLinkStore(*WTFMove(pageConfiguration.visitedLinkStore))
</span><span class="cx">     , m_sessionID(SessionID::defaultSessionID())
</span><span class="cx">     , m_isClosing(false)
</span><ins>+    , m_cpuUsageMeasurementTimer(*this, &amp;Page::measurePostLoadCPUUsage)
</ins><span class="cx"> {
</span><span class="cx">     updateTimerThrottlingState();
</span><span class="cx"> 
</span><span class="lines">@@ -920,6 +928,55 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Page::didStartProvisionalLoad()
+{
+    m_postLoadCPUTime = std::nullopt;
+    m_cpuUsageMeasurementTimer.stop();
+}
+
+void Page::didFinishLoad()
+{
+    resetRelevantPaintedObjectCounter();
+
+    // Only do post-load CPU usage measurement if there is a single Page in the process in order to reduce noise.
+    if (Settings::isPostLoadCPUUsageMeasurementEnabled() &amp;&amp; allPages-&gt;size() == 1) {
+        m_postLoadCPUTime = std::nullopt;
+        m_cpuUsageMeasurementTimer.startOneShot(cpuUsageMeasurementDelay);
+    }
+}
+
+static String cpuUsageToDiagnosticLogginKey(double cpuUsage)
+{
+    if (cpuUsage &lt; 10)
+        return ASCIILiteral(&quot;Below10&quot;);
+    if (cpuUsage &lt; 20)
+        return ASCIILiteral(&quot;10to20&quot;);
+    if (cpuUsage &lt; 40)
+        return ASCIILiteral(&quot;20to40&quot;);
+    if (cpuUsage &lt; 60)
+        return ASCIILiteral(&quot;40to60&quot;);
+    if (cpuUsage &lt; 80)
+        return ASCIILiteral(&quot;60to80&quot;);
+    return ASCIILiteral(&quot;over80&quot;);
+}
+
+void Page::measurePostLoadCPUUsage()
+{
+    if (!m_postLoadCPUTime) {
+        m_postLoadCPUTime = getCPUTime();
+        if (m_postLoadCPUTime)
+            m_cpuUsageMeasurementTimer.startOneShot(cpuUsageMeasurementDuration);
+        return;
+    }
+    std::optional&lt;CPUTime&gt; cpuTime = getCPUTime();
+    if (!cpuTime)
+        return;
+
+    double cpuUsage = cpuTime.value().percentageCPUUsageSince(*m_postLoadCPUTime);
+    RELEASE_LOG_IF_ALLOWED(PerformanceLogging, &quot;measurePostLoadCPUUsage: Process was using %.1f%% percent CPU after the page load.&quot;, cpuUsage);
+    diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::cpuUsageKey(), cpuUsageToDiagnosticLogginKey(cpuUsage), ShouldSample::No);
+}
+
</ins><span class="cx"> void Page::setTopContentInset(float contentInset)
</span><span class="cx"> {
</span><span class="cx">     if (m_topContentInset == contentInset)
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/page/Page.h        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -21,6 +21,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><span class="cx"> #include &quot;ActivityState.h&quot;
</span><ins>+#include &quot;CPUTime.h&quot;
</ins><span class="cx"> #include &quot;FindOptions.h&quot;
</span><span class="cx"> #include &quot;FrameLoaderTypes.h&quot;
</span><span class="cx"> #include &quot;LayoutMilestones.h&quot;
</span><span class="lines">@@ -293,6 +294,9 @@
</span><span class="cx">     UserInterfaceLayoutDirection userInterfaceLayoutDirection() const { return m_userInterfaceLayoutDirection; }
</span><span class="cx">     WEBCORE_EXPORT void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
</span><span class="cx"> 
</span><ins>+    void didStartProvisionalLoad();
+    void didFinishLoad(); // Called when the load has been committed in the main frame.
+
</ins><span class="cx">     // The view scale factor is multiplied into the page scale factor by all
</span><span class="cx">     // callers of setPageScaleFactor.
</span><span class="cx">     WEBCORE_EXPORT void setViewScaleFactor(float);
</span><span class="lines">@@ -561,6 +565,8 @@
</span><span class="cx">     void checkSubframeCountConsistency() const;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    void measurePostLoadCPUUsage();
+
</ins><span class="cx">     enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
</span><span class="cx">     enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
</span><span class="cx"> 
</span><span class="lines">@@ -742,6 +748,9 @@
</span><span class="cx">     
</span><span class="cx">     // For testing.
</span><span class="cx">     std::optional&lt;EventThrottlingBehavior&gt; m_eventThrottlingBehaviorOverride;
</span><ins>+
+    Timer m_cpuUsageMeasurementTimer;
+    std::optional&lt;CPUTime&gt; m_postLoadCPUTime;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline PageGroup&amp; Page::group()
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.cpp (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.cpp        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/page/Settings.cpp        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -778,6 +778,15 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Settings::isPostLoadCPUUsageMeasurementEnabled()
+{
+#if PLATFORM(COCOA)
+    return true;
+#else
+    return false;
+#endif
+}
+
</ins><span class="cx"> void Settings::setAllowsAnySSLCertificate(bool allowAnySSLCertificate)
</span><span class="cx"> {
</span><span class="cx">     gAllowsAnySSLCertificate = allowAnySSLCertificate;
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.h (210732 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.h        2017-01-13 17:54:30 UTC (rev 210732)
+++ trunk/Source/WebCore/page/Settings.h        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -199,6 +199,8 @@
</span><span class="cx">     static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    static bool isPostLoadCPUUsageMeasurementEnabled();
+
</ins><span class="cx">     static bool globalConstRedeclarationShouldThrow();
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT void setBackgroundShouldExtendBeyondPage(bool);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformCPUTimecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/CPUTime.cpp (0 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/CPUTime.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/CPUTime.cpp        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * Copyright (C) 2017 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 &quot;config.h&quot;
+#include &quot;CPUTime.h&quot;
+
+namespace WebCore {
+
+#if !PLATFORM(COCOA)
+
+std::optional&lt;CPUTime&gt; getCPUTime()
+{
+    return std::nullopt;
+}
+
+#endif
+
+double CPUTime::percentageCPUUsageSince(const CPUTime&amp; reference)
+{
+    int64_t cpuUsageTimeDelta = (systemTime + userTime) - (reference.systemTime + reference.userTime);
+    int64_t cpuTimeDelta = cpuTime - reference.cpuTime;
+    ASSERT(cpuTimeDelta);
+    return static_cast&lt;double&gt;(cpuUsageTimeDelta * 100.0) / cpuTimeDelta;
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformCPUTimeh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/CPUTime.h (0 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/CPUTime.h                                (rev 0)
+++ trunk/Source/WebCore/platform/CPUTime.h        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+/*
+ * Copyright (C) 2017 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 &lt;wtf/Optional.h&gt;
+
+namespace WebCore {
+
+struct CPUTime {
+    int64_t cpuTime; // in microseconds.
+    int64_t userTime; // in microseconds.
+    int64_t systemTime; // in microseconds.
+
+    double percentageCPUUsageSince(const CPUTime&amp;);
+};
+
+std::optional&lt;CPUTime&gt; getCPUTime();
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaCPUTimeCocoamm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm (0 => 210733)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm                                (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm        2017-01-13 17:54:53 UTC (rev 210733)
</span><span class="lines">@@ -0,0 +1,71 @@
</span><ins>+/*
+ * Copyright (C) 2017 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.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;CPUTime.h&quot;
+
+#import &lt;mach/mach_init.h&gt;
+#import &lt;mach/task.h&gt;
+#import &lt;mach/task_info.h&gt;
+#import &lt;wtf/CurrentTime.h&gt;
+
+namespace WebCore {
+
+static const int64_t microsecondsPerSecond = 1000000;
+
+static int64_t timeValueToMicroseconds(const time_value_t&amp; value)
+{
+    int64_t result = value.seconds;
+    result *= microsecondsPerSecond;
+    result += value.microseconds;
+    return result;
+}
+
+std::optional&lt;CPUTime&gt; getCPUTime()
+{
+    // Account for current threads.
+    task_thread_times_info threadInfoData;
+    mach_msg_type_number_t threadInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
+    kern_return_t result = task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, reinterpret_cast&lt;task_info_t&gt;(&amp;threadInfoData), &amp;threadInfoCount);
+    if (result != KERN_SUCCESS)
+        return std::nullopt;
+
+    int64_t userTime = timeValueToMicroseconds(threadInfoData.user_time);
+    int64_t systemTime = timeValueToMicroseconds(threadInfoData.system_time);
+
+    // Account for termined threads.
+    task_basic_info taskInfoData;
+    mach_msg_type_number_t taskInfoCount = TASK_BASIC_INFO_COUNT;
+    result = task_info(mach_task_self(), TASK_BASIC_INFO, reinterpret_cast&lt;task_info_t&gt;(&amp;taskInfoData), &amp;taskInfoCount);
+    if (result != KERN_SUCCESS)
+        return std::nullopt;
+
+    userTime += timeValueToMicroseconds(taskInfoData.user_time);
+    systemTime += timeValueToMicroseconds(taskInfoData.system_time);
+
+    return CPUTime { static_cast&lt;int64_t&gt;(monotonicallyIncreasingTime() * microsecondsPerSecond), userTime, systemTime };
+}
+
+}
</ins></span></pre>
</div>
</div>

</body>
</html>