<!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>[210878] branches/safari-603-branch/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/210878">210878</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-01-18 12:43:40 -0800 (Wed, 18 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/210733">r210733</a>. rdar://problem/30014496</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchSourceWebCoreCMakeListstxt">branches/safari-603-branch/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#branchessafari603branchSourceWebCoreChangeLog">branches/safari-603-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceWebCoreWebCorexcodeprojprojectpbxproj">branches/safari-603-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#branchessafari603branchSourceWebCoreloaderFrameLoadercpp">branches/safari-603-branch/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorepageDiagnosticLoggingKeyscpp">branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorepageDiagnosticLoggingKeysh">branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h</a></li>
<li><a href="#branchessafari603branchSourceWebCorepagePagecpp">branches/safari-603-branch/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorepagePageh">branches/safari-603-branch/Source/WebCore/page/Page.h</a></li>
<li><a href="#branchessafari603branchSourceWebCorepageSettingscpp">branches/safari-603-branch/Source/WebCore/page/Settings.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorepageSettingsh">branches/safari-603-branch/Source/WebCore/page/Settings.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari603branchSourceWebCoreplatformCPUTimecpp">branches/safari-603-branch/Source/WebCore/platform/CPUTime.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformCPUTimeh">branches/safari-603-branch/Source/WebCore/platform/CPUTime.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformcocoaCPUTimeCocoamm">branches/safari-603-branch/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari603branchSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/CMakeLists.txt (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/CMakeLists.txt        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/CMakeLists.txt        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -2123,6 +2123,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="branchessafari603branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/ChangeLog        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -1,5 +1,57 @@
</span><span class="cx"> 2017-01-18 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r210733. rdar://problem/30014496
+
+ 2017-01-13 Chris Dumez <cdumez@apple.com>
+
+ Report post-page load CPU usage using diagnostic logging
+ https://bugs.webkit.org/show_bug.cgi?id=166950
+ <rdar://problem/30014496>
+
+ 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):
+
+2017-01-18 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r210762. rdar://problem/29883469
</span><span class="cx">
</span><span class="cx"> 2017-01-13 Alex Christensen <achristensen@webkit.org>
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -1741,6 +1741,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">@@ -8960,6 +8963,9 @@
</span><span class="cx">                 460CBF331D4BCCFE0092E88E /* JSDOMWindowProperties.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWindowProperties.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMWindowProperties.h; sourceTree = "<group>"; };
</span><span class="cx">                 4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PowerObserverMac.cpp; sourceTree = "<group>"; };
</span><ins>+                463763061E26FDBA008CD46D /* CPUTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUTime.cpp; sourceTree = "<group>"; };
+                463763071E26FDBA008CD46D /* CPUTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPUTime.h; sourceTree = "<group>"; };
+                4637630A1E26FDEB008CD46D /* CPUTimeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CPUTimeCocoa.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 463EB6201B8789CB0096ED51 /* TagCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagCollection.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 463EB6211B8789CB0096ED51 /* TagCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagCollection.h; sourceTree = "<group>"; };
</span><span class="cx">                 465A8E781C8A24CE00E7D3E4 /* RuntimeApplicationChecks.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RuntimeApplicationChecks.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -19723,6 +19729,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">@@ -22546,6 +22553,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">@@ -28298,6 +28307,7 @@
</span><span class="cx">                                 6EBF0E5512A8929800DB1709 /* WebGLExtension.h in Headers */,
</span><span class="cx">                                 49C7B9CF1042D32F0009D447 /* WebGLFramebuffer.h in Headers */,
</span><span class="cx">                                 6E47E66110B7944B00B186C8 /* WebGLGetInfo.h in Headers */,
</span><ins>+                                463763091E26FDD7008CD46D /* CPUTime.h in Headers */,
</ins><span class="cx">                                 49FFBF3F11C93EE3006A7118 /* WebGLLayer.h in Headers */,
</span><span class="cx">                                 93F1D5BB12D532C400832BEC /* WebGLLoseContext.h in Headers */,
</span><span class="cx">                                 49C7B9D51042D32F0009D447 /* WebGLObject.h in Headers */,
</span><span class="lines">@@ -29949,6 +29959,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">@@ -30118,6 +30129,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="branchessafari603branchSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/loader/FrameLoader.cpp (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/loader/FrameLoader.cpp        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/loader/FrameLoader.cpp        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -992,6 +992,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->didStartProvisionalLoad();
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void FrameLoader::resetMultipleFormSubmissionProtection()
</span><span class="lines">@@ -2294,7 +2299,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->resetRelevantPaintedObjectCounter();
</del><ins>+ page->didFinishLoad();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> const ResourceError& error = dl->mainDocumentError();
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorepageDiagnosticLoggingKeyscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -53,6 +53,11 @@
</span><span class="cx"> return ASCIILiteral("pluginFailedLoading");
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+String DiagnosticLoggingKeys::postPageLoadKey()
+{
+ return ASCIILiteral("postPageLoad");
+}
+
</ins><span class="cx"> String DiagnosticLoggingKeys::provisionalLoadKey()
</span><span class="cx"> {
</span><span class="cx"> return ASCIILiteral("provisionalLoad");
</span><span class="lines">@@ -308,6 +313,11 @@
</span><span class="cx"> return ASCIILiteral("cannotSuspendActiveDOMObjects");
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+String DiagnosticLoggingKeys::cpuUsageKey()
+{
+ return ASCIILiteral("cpuUsage");
+}
+
</ins><span class="cx"> String DiagnosticLoggingKeys::createSharedBufferFailedKey()
</span><span class="cx"> {
</span><span class="cx"> return ASCIILiteral("createSharedBufferFailed");
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorepageDiagnosticLoggingKeysh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -40,6 +40,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">@@ -100,6 +101,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="branchessafari603branchSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/Page.cpp (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/Page.cpp        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/page/Page.cpp        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #include "ContextMenuController.h"
</span><span class="cx"> #include "DatabaseProvider.h"
</span><span class="cx"> #include "DiagnosticLoggingClient.h"
</span><ins>+#include "DiagnosticLoggingKeys.h"
</ins><span class="cx"> #include "DocumentLoader.h"
</span><span class="cx"> #include "DocumentMarkerController.h"
</span><span class="cx"> #include "DragController.h"
</span><span class="lines">@@ -98,6 +99,7 @@
</span><span class="cx"> #include "VoidCallback.h"
</span><span class="cx"> #include "WebGLStateTracker.h"
</span><span class="cx"> #include "Widget.h"
</span><ins>+#include <wtf/CurrentTime.h>
</ins><span class="cx"> #include <wtf/RefCountedLeakCounter.h>
</span><span class="cx"> #include <wtf/StdLibExtras.h>
</span><span class="cx"> #include <wtf/text/Base64.h>
</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, "%p - Page::" fmt, this, ##__VA_ARGS__)
+
</ins><span class="cx"> static HashSet<Page*>* 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, ("Page"));
</span><span class="cx">
</span><span class="cx"> void Page::forEachPage(std::function<void(Page&)> 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, &Page::measurePostLoadCPUUsage)
</ins><span class="cx"> {
</span><span class="cx"> updateTimerThrottlingState();
</span><span class="cx">
</span><span class="lines">@@ -925,6 +933,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() && allPages->size() == 1) {
+ m_postLoadCPUTime = std::nullopt;
+ m_cpuUsageMeasurementTimer.startOneShot(cpuUsageMeasurementDelay);
+ }
+}
+
+static String cpuUsageToDiagnosticLogginKey(double cpuUsage)
+{
+ if (cpuUsage < 10)
+ return ASCIILiteral("Below10");
+ if (cpuUsage < 20)
+ return ASCIILiteral("10to20");
+ if (cpuUsage < 40)
+ return ASCIILiteral("20to40");
+ if (cpuUsage < 60)
+ return ASCIILiteral("40to60");
+ if (cpuUsage < 80)
+ return ASCIILiteral("60to80");
+ return ASCIILiteral("over80");
+}
+
+void Page::measurePostLoadCPUUsage()
+{
+ if (!m_postLoadCPUTime) {
+ m_postLoadCPUTime = getCPUTime();
+ if (m_postLoadCPUTime)
+ m_cpuUsageMeasurementTimer.startOneShot(cpuUsageMeasurementDuration);
+ return;
+ }
+ std::optional<CPUTime> cpuTime = getCPUTime();
+ if (!cpuTime)
+ return;
+
+ double cpuUsage = cpuTime.value().percentageCPUUsageSince(*m_postLoadCPUTime);
+ RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostLoadCPUUsage: Process was using %.1f%% percent CPU after the page load.", 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="branchessafari603branchSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/Page.h (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/Page.h        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/page/Page.h        2017-01-18 20:43:40 UTC (rev 210878)
</span><span class="lines">@@ -21,6 +21,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx">
</span><span class="cx"> #include "ActivityState.h"
</span><ins>+#include "CPUTime.h"
</ins><span class="cx"> #include "FindOptions.h"
</span><span class="cx"> #include "FrameLoaderTypes.h"
</span><span class="cx"> #include "LayoutMilestones.h"
</span><span class="lines">@@ -299,6 +300,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">@@ -568,6 +572,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">@@ -753,6 +759,9 @@
</span><span class="cx">
</span><span class="cx"> // For testing.
</span><span class="cx"> std::optional<EventThrottlingBehavior> m_eventThrottlingBehaviorOverride;
</span><ins>+
+ Timer m_cpuUsageMeasurementTimer;
+ std::optional<CPUTime> m_postLoadCPUTime;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> inline PageGroup& Page::group()
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorepageSettingscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/Settings.cpp (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/Settings.cpp        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/page/Settings.cpp        2017-01-18 20:43:40 UTC (rev 210878)
</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="branchessafari603branchSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/Settings.h (210877 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/Settings.h        2017-01-18 20:43:34 UTC (rev 210877)
+++ branches/safari-603-branch/Source/WebCore/page/Settings.h        2017-01-18 20:43:40 UTC (rev 210878)
</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="branchessafari603branchSourceWebCoreplatformCPUTimecpp"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/Source/WebCore/platform/CPUTime.cpp (0 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/CPUTime.cpp         (rev 0)
+++ branches/safari-603-branch/Source/WebCore/platform/CPUTime.cpp        2017-01-18 20:43:40 UTC (rev 210878)
</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 "config.h"
+#include "CPUTime.h"
+
+namespace WebCore {
+
+#if !PLATFORM(COCOA)
+
+std::optional<CPUTime> getCPUTime()
+{
+ return std::nullopt;
+}
+
+#endif
+
+double CPUTime::percentageCPUUsageSince(const CPUTime& reference)
+{
+ int64_t cpuUsageTimeDelta = (systemTime + userTime) - (reference.systemTime + reference.userTime);
+ int64_t cpuTimeDelta = cpuTime - reference.cpuTime;
+ ASSERT(cpuTimeDelta);
+ return static_cast<double>(cpuUsageTimeDelta * 100.0) / cpuTimeDelta;
+}
+
+}
</ins></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformCPUTimeh"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/Source/WebCore/platform/CPUTime.h (0 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/CPUTime.h         (rev 0)
+++ branches/safari-603-branch/Source/WebCore/platform/CPUTime.h        2017-01-18 20:43:40 UTC (rev 210878)
</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 <wtf/Optional.h>
+
+namespace WebCore {
+
+struct CPUTime {
+ int64_t cpuTime; // in microseconds.
+ int64_t userTime; // in microseconds.
+ int64_t systemTime; // in microseconds.
+
+ double percentageCPUUsageSince(const CPUTime&);
+};
+
+std::optional<CPUTime> getCPUTime();
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformcocoaCPUTimeCocoamm"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm (0 => 210878)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm         (rev 0)
+++ branches/safari-603-branch/Source/WebCore/platform/cocoa/CPUTimeCocoa.mm        2017-01-18 20:43:40 UTC (rev 210878)
</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 "config.h"
+#import "CPUTime.h"
+
+#import <mach/mach_init.h>
+#import <mach/task.h>
+#import <mach/task_info.h>
+#import <wtf/CurrentTime.h>
+
+namespace WebCore {
+
+static const int64_t microsecondsPerSecond = 1000000;
+
+static int64_t timeValueToMicroseconds(const time_value_t& value)
+{
+ int64_t result = value.seconds;
+ result *= microsecondsPerSecond;
+ result += value.microseconds;
+ return result;
+}
+
+std::optional<CPUTime> 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<task_info_t>(&threadInfoData), &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<task_info_t>(&taskInfoData), &taskInfoCount);
+ if (result != KERN_SUCCESS)
+ return std::nullopt;
+
+ userTime += timeValueToMicroseconds(taskInfoData.user_time);
+ systemTime += timeValueToMicroseconds(taskInfoData.system_time);
+
+ return CPUTime { static_cast<int64_t>(monotonicallyIncreasingTime() * microsecondsPerSecond), userTime, systemTime };
+}
+
+}
</ins></span></pre>
</div>
</div>
</body>
</html>