Title: [197827] trunk/Source
Revision
197827
Author
joep...@webkit.org
Date
2016-03-08 18:06:55 -0800 (Tue, 08 Mar 2016)

Log Message

Web Inspector: Memory Timeline should show MemoryPressure events
https://bugs.webkit.org/show_bug.cgi?id=155158
<rdar://problem/25026610>

Reviewed by Brian Burg.

Source/_javascript_Core:

* inspector/protocol/Memory.json:

Source/WebCore:

* platform/MemoryPressureHandler.cpp:
(WebCore::MemoryPressureHandler::releaseMemory):
When responding to memory pressure, notify page inspectors.

* platform/cocoa/MemoryPressureHandlerCocoa.mm:
Remove unused includes.

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didHandleMemoryPressureImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::playbackStarted):
(WebCore::InspectorInstrumentation::playbackPaused):
(WebCore::InspectorInstrumentation::playbackFinished):
(WebCore::InspectorInstrumentation::playbackHitPosition):
(WebCore::InspectorInstrumentation::didHandleMemoryPressure):
* inspector/InspectorMemoryAgent.cpp:
(WebCore::InspectorMemoryAgent::didCreateFrontendAndBackend):
(WebCore::InspectorMemoryAgent::willDestroyFrontendAndBackend):
(WebCore::InspectorMemoryAgent::enable):
(WebCore::InspectorMemoryAgent::disable):
(WebCore::InspectorMemoryAgent::didHandleMemoryPressure):
* inspector/InspectorMemoryAgent.h:
* inspector/InstrumentingAgents.cpp:
(WebCore::InstrumentingAgents::reset):
* inspector/InstrumentingAgents.h:
(WebCore::InstrumentingAgents::inspectorMemoryAgent):
(WebCore::InstrumentingAgents::setInspectorMemoryAgent):
Plumbing to notify the right active inspector.

Source/WebInspectorUI:

* UserInterface/Main.html:
New resources.

* UserInterface/Base/Main.js:
(WebInspector.loaded):
* UserInterface/Controllers/MemoryManager.js:
(WebInspector.MemoryManager):
(WebInspector.MemoryManager.prototype.memoryPressure):
* UserInterface/Protocol/MemoryObserver.js:
(WebInspector.MemoryObserver.prototype.memoryPressure):
New manager for Memory domain events.

* UserInterface/Controllers/TimelineManager.js:
(WebInspector.TimelineManager):
(WebInspector.TimelineManager.defaultInstruments):
(WebInspector.TimelineManager.prototype._memoryPressure):
* UserInterface/Models/TimelineRecording.js:
(WebInspector.TimelineRecording.prototype.addMemoryPressureEvent):
Add events to the Memory Timeline of the active recording.

* UserInterface/Models/MemoryTimeline.js:
(WebInspector.MemoryTimeline.prototype.get memoryPressureEvents):
(WebInspector.MemoryTimeline.prototype.addMemoryPressureEvent):
(WebInspector.MemoryTimeline.prototype.reset):
(WebInspector.MemoryTimeline):
* UserInterface/Models/Timeline.js:
(WebInspector.Timeline.create):
Create a specific MemoryTimeline to hold records and memory pressure events.

* UserInterface/Models/MemoryPressureEvent.js:
(WebInspector.MemoryPressureEvent):
(WebInspector.MemoryPressureEvent.fromPayload):
(WebInspector.MemoryPressureEvent.prototype.get timestamp):
(WebInspector.MemoryPressureEvent.prototype.get severity):
Model object for a memory pressure event.

* UserInterface/Views/MemoryTimelineOverviewGraph.css:
(.timeline-overview-graph.memory .memory-pressure-event):
* UserInterface/Views/MemoryTimelineOverviewGraph.js:
(WebInspector.MemoryTimelineOverviewGraph):
(WebInspector.MemoryTimelineOverviewGraph.prototype.reset):
(WebInspector.MemoryTimelineOverviewGraph.prototype._visibleMemoryPressureEvents):
(WebInspector.MemoryTimelineOverviewGraph.prototype._memoryTimelineMemoryPressureEventAdded):
Include markers for memory pressure events.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (197826 => 197827)


--- trunk/Source/_javascript_Core/ChangeLog	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-03-09 02:06:55 UTC (rev 197827)
@@ -1,5 +1,15 @@
 2016-03-08  Joseph Pecoraro  <pecor...@apple.com>
 
+        Web Inspector: Memory Timeline should show MemoryPressure events
+        https://bugs.webkit.org/show_bug.cgi?id=155158
+        <rdar://problem/25026610>
+
+        Reviewed by Brian Burg.
+
+        * inspector/protocol/Memory.json:
+
+2016-03-08  Joseph Pecoraro  <pecor...@apple.com>
+
         Web Inspector: Add Heap domain start/stop tracking commands
         https://bugs.webkit.org/show_bug.cgi?id=155190
 

Modified: trunk/Source/_javascript_Core/inspector/protocol/Memory.json (197826 => 197827)


--- trunk/Source/_javascript_Core/inspector/protocol/Memory.json	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/_javascript_Core/inspector/protocol/Memory.json	2016-03-09 02:06:55 UTC (rev 197827)
@@ -23,6 +23,14 @@
     ],
     "commands": [
         {
+            "name": "enable",
+            "description": "Enables Memory domain events."
+        },
+        {
+            "name": "disable",
+            "description": "Disables Memory domain events."
+        },
+        {
             "name": "startTracking",
             "description": "Start tracking memory. This will produce a `trackingStart` event."
         },
@@ -33,6 +41,14 @@
     ],
     "events": [
         {
+            "name": "memoryPressure",
+            "description": "Memory pressure was encountered.",
+            "parameters": [
+                { "name": "timestamp", "type": "number" },
+                { "name": "severity", "type": "string", "enum": ["critical", "non-critical"], "description": "The severity of the memory pressure event." }
+            ]
+        },
+        {
             "name": "trackingStart",
             "description": "Tracking started.",
             "parameters": [

Modified: trunk/Source/WebCore/ChangeLog (197826 => 197827)


--- trunk/Source/WebCore/ChangeLog	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/ChangeLog	2016-03-09 02:06:55 UTC (rev 197827)
@@ -1,3 +1,40 @@
+2016-03-08  Joseph Pecoraro  <pecor...@apple.com>
+
+        Web Inspector: Memory Timeline should show MemoryPressure events
+        https://bugs.webkit.org/show_bug.cgi?id=155158
+        <rdar://problem/25026610>
+
+        Reviewed by Brian Burg.
+
+        * platform/MemoryPressureHandler.cpp:
+        (WebCore::MemoryPressureHandler::releaseMemory):
+        When responding to memory pressure, notify page inspectors.
+
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        Remove unused includes.
+
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::didHandleMemoryPressureImpl):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::playbackStarted):
+        (WebCore::InspectorInstrumentation::playbackPaused):
+        (WebCore::InspectorInstrumentation::playbackFinished):
+        (WebCore::InspectorInstrumentation::playbackHitPosition):
+        (WebCore::InspectorInstrumentation::didHandleMemoryPressure):
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore::InspectorMemoryAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorMemoryAgent::willDestroyFrontendAndBackend):
+        (WebCore::InspectorMemoryAgent::enable):
+        (WebCore::InspectorMemoryAgent::disable):
+        (WebCore::InspectorMemoryAgent::didHandleMemoryPressure):
+        * inspector/InspectorMemoryAgent.h:
+        * inspector/InstrumentingAgents.cpp:
+        (WebCore::InstrumentingAgents::reset):
+        * inspector/InstrumentingAgents.h:
+        (WebCore::InstrumentingAgents::inspectorMemoryAgent):
+        (WebCore::InstrumentingAgents::setInspectorMemoryAgent):
+        Plumbing to notify the right active inspector.
+
 2016-03-08  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Delete dead scrolling code

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (197826 => 197827)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2016-03-09 02:06:55 UTC (rev 197827)
@@ -48,6 +48,7 @@
 #include "InspectorDOMStorageAgent.h"
 #include "InspectorDatabaseAgent.h"
 #include "InspectorLayerTreeAgent.h"
+#include "InspectorMemoryAgent.h"
 #include "InspectorNetworkAgent.h"
 #include "InspectorPageAgent.h"
 #include "InspectorTimelineAgent.h"
@@ -1033,6 +1034,14 @@
 }
 #endif
 
+#if ENABLE(RESOURCE_USAGE)
+void InspectorInstrumentation::didHandleMemoryPressureImpl(InstrumentingAgents& instrumentingAgents, Critical critical)
+{
+    if (InspectorMemoryAgent* memoryAgent = instrumentingAgents.inspectorMemoryAgent())
+        memoryAgent->didHandleMemoryPressure(critical);
+}
+#endif
+
 void InspectorInstrumentation::networkStateChangedImpl(InstrumentingAgents& instrumentingAgents)
 {
     if (InspectorApplicationCacheAgent* applicationCacheAgent = instrumentingAgents.inspectorApplicationCacheAgent())

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (197826 => 197827)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2016-03-09 02:06:55 UTC (rev 197827)
@@ -38,6 +38,7 @@
 #include "Frame.h"
 #include "HitTestResult.h"
 #include "InspectorInstrumentationCookie.h"
+#include "MemoryPressureHandler.h"
 #include "Page.h"
 #include "ScriptExecutionContext.h"
 #include "ScriptState.h"
@@ -258,6 +259,10 @@
     static Deprecated::ScriptObject wrapWebGLRenderingContextForInstrumentation(Document*, const Deprecated::ScriptObject&);
 #endif
 
+#if ENABLE(RESOURCE_USAGE)
+    static void didHandleMemoryPressure(Page&, Critical);
+#endif
+
     static void networkStateChanged(Page*);
     static void updateApplicationCacheStatus(Frame*);
 
@@ -422,6 +427,10 @@
     static void didReceiveWebSocketFrameErrorImpl(InstrumentingAgents&, unsigned long identifier, const String&);
 #endif
 
+#if ENABLE(RESOURCE_USAGE)
+    static void didHandleMemoryPressureImpl(InstrumentingAgents&, Critical);
+#endif
+
     static void networkStateChangedImpl(InstrumentingAgents&);
     static void updateApplicationCacheStatusImpl(InstrumentingAgents&, Frame*);
 
@@ -1161,28 +1170,37 @@
 inline void InspectorInstrumentation::playbackStarted(Page& page)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-        playbackStartedImpl(instrumentingAgentsForPage(page));
+    playbackStartedImpl(instrumentingAgentsForPage(page));
 }
 
 inline void InspectorInstrumentation::playbackPaused(Page& page, const ReplayPosition& position)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-        playbackPausedImpl(instrumentingAgentsForPage(page), position);
+    playbackPausedImpl(instrumentingAgentsForPage(page), position);
 }
 
 inline void InspectorInstrumentation::playbackFinished(Page& page)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-        playbackFinishedImpl(instrumentingAgentsForPage(page));
+    playbackFinishedImpl(instrumentingAgentsForPage(page));
 }
 
 inline void InspectorInstrumentation::playbackHitPosition(Page& page, const ReplayPosition& position)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-        playbackHitPositionImpl(instrumentingAgentsForPage(page), position);
+    playbackHitPositionImpl(instrumentingAgentsForPage(page), position);
 }
 #endif // ENABLE(WEB_REPLAY)
 
+#if ENABLE(RESOURCE_USAGE)
+inline void InspectorInstrumentation::didHandleMemoryPressure(Page& page, Critical critical)
+{
+    FAST_RETURN_IF_NO_FRONTENDS(void());
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(&page))
+        didHandleMemoryPressureImpl(*instrumentingAgents, critical);
+}
+#endif
+
 inline void InspectorInstrumentation::networkStateChanged(Page* page)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (197826 => 197827)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2016-03-09 02:06:55 UTC (rev 197827)
@@ -28,6 +28,7 @@
 
 #if ENABLE(RESOURCE_USAGE)
 
+#include "InstrumentingAgents.h"
 #include "ResourceUsageThread.h"
 #include <inspector/InspectorEnvironment.h>
 #include <wtf/Stopwatch.h>
@@ -45,14 +46,28 @@
 
 void InspectorMemoryAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
 {
+    m_instrumentingAgents.setInspectorMemoryAgent(this);
 }
 
 void InspectorMemoryAgent::willDestroyFrontendAndBackend(DisconnectReason)
 {
+    m_instrumentingAgents.setInspectorMemoryAgent(nullptr);
+
     ErrorString ignored;
     stopTracking(ignored);
+    disable(ignored);
 }
 
+void InspectorMemoryAgent::enable(ErrorString&)
+{
+    m_enabled = true;
+}
+
+void InspectorMemoryAgent::disable(ErrorString&)
+{
+    m_enabled = false;
+}
+
 void InspectorMemoryAgent::startTracking(ErrorString&)
 {
     if (m_tracking)
@@ -79,6 +94,15 @@
     m_frontendDispatcher->trackingComplete();
 }
 
+void InspectorMemoryAgent::didHandleMemoryPressure(Critical critical)
+{
+    if (!m_enabled)
+        return;
+
+    MemoryFrontendDispatcher::Severity severity = critical == Critical::Yes ? MemoryFrontendDispatcher::Severity::Critical : MemoryFrontendDispatcher::Severity::NonCritical;
+    m_frontendDispatcher->memoryPressure(m_environment.executionStopwatch()->elapsedTime(), severity);
+}
+
 void InspectorMemoryAgent::collectSample(const ResourceUsageData& data)
 {
     auto _javascript_Category = Protocol::Memory::CategoryData::create()

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.h (197826 => 197827)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.h	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.h	2016-03-09 02:06:55 UTC (rev 197827)
@@ -29,6 +29,7 @@
 #if ENABLE(RESOURCE_USAGE)
 
 #include "InspectorWebAgentBase.h"
+#include "MemoryPressureHandler.h"
 #include "ResourceUsageData.h"
 #include <inspector/InspectorBackendDispatchers.h>
 #include <inspector/InspectorFrontendDispatchers.h>
@@ -48,14 +49,20 @@
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
 
     // MemoryBackendDispatcherHandler
+    void enable(ErrorString&) override;
+    void disable(ErrorString&) override;
     void startTracking(ErrorString&) override;
     void stopTracking(ErrorString&) override;
 
+    // InspectorInstrumentation
+    void didHandleMemoryPressure(Critical);
+
 private:
     void collectSample(const ResourceUsageData&);
 
     std::unique_ptr<Inspector::MemoryFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::MemoryBackendDispatcher> m_backendDispatcher;
+    bool m_enabled { false };
     bool m_tracking { false };
 };
 

Modified: trunk/Source/WebCore/inspector/InstrumentingAgents.cpp (197826 => 197827)


--- trunk/Source/WebCore/inspector/InstrumentingAgents.cpp	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/inspector/InstrumentingAgents.cpp	2016-03-09 02:06:55 UTC (rev 197827)
@@ -57,6 +57,9 @@
 #if ENABLE(WEB_REPLAY)
     m_inspectorReplayAgent = nullptr;
 #endif
+#if ENABLE(RESOURCE_USAGE)
+    m_inspectorMemoryAgent = nullptr;
+#endif
     m_inspectorDatabaseAgent = nullptr;
     m_inspectorApplicationCacheAgent = nullptr;
     m_inspectorDebuggerAgent = nullptr;

Modified: trunk/Source/WebCore/inspector/InstrumentingAgents.h (197826 => 197827)


--- trunk/Source/WebCore/inspector/InstrumentingAgents.h	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/inspector/InstrumentingAgents.h	2016-03-09 02:06:55 UTC (rev 197827)
@@ -51,6 +51,7 @@
 class InspectorDOMStorageAgent;
 class InspectorDatabaseAgent;
 class InspectorLayerTreeAgent;
+class InspectorMemoryAgent;
 class InspectorNetworkAgent;
 class InspectorPageAgent;
 class InspectorReplayAgent;
@@ -110,6 +111,11 @@
     void setInspectorReplayAgent(InspectorReplayAgent* agent) { m_inspectorReplayAgent = agent; }
 #endif
 
+#if ENABLE(RESOURCE_USAGE)
+    InspectorMemoryAgent* inspectorMemoryAgent() const { return m_inspectorMemoryAgent; }
+    void setInspectorMemoryAgent(InspectorMemoryAgent* agent) { m_inspectorMemoryAgent = agent; }
+#endif
+
     InspectorDatabaseAgent* inspectorDatabaseAgent() const { return m_inspectorDatabaseAgent; }
     void setInspectorDatabaseAgent(InspectorDatabaseAgent* agent) { m_inspectorDatabaseAgent = agent; }
 
@@ -147,6 +153,9 @@
 #if ENABLE(WEB_REPLAY)
     InspectorReplayAgent* m_inspectorReplayAgent { nullptr };
 #endif
+#if ENABLE(RESOURCE_USAGE)
+    InspectorMemoryAgent* m_inspectorMemoryAgent { nullptr };
+#endif
     InspectorDatabaseAgent* m_inspectorDatabaseAgent { nullptr };
     InspectorApplicationCacheAgent* m_inspectorApplicationCacheAgent { nullptr };
     Inspector::InspectorDebuggerAgent* m_inspectorDebuggerAgent { nullptr };

Modified: trunk/Source/WebCore/platform/MemoryPressureHandler.cpp (197826 => 197827)


--- trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/platform/MemoryPressureHandler.cpp	2016-03-09 02:06:55 UTC (rev 197827)
@@ -29,13 +29,11 @@
 #include "CSSValuePool.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
-#include "DOMWindow.h"
 #include "Document.h"
 #include "FontCache.h"
-#include "FontCascade.h"
 #include "GCController.h"
 #include "HTMLMediaElement.h"
-#include "JSDOMWindow.h"
+#include "InspectorInstrumentation.h"
 #include "MemoryCache.h"
 #include "Page.h"
 #include "PageCache.h"
@@ -178,6 +176,12 @@
 #endif
         WTF::releaseFastMallocFreeMemory();
     }
+
+#if ENABLE(RESOURCE_USAGE)
+    Page::forEachPage([&](Page& page) {
+        InspectorInstrumentation::didHandleMemoryPressure(page, critical);
+    });
+#endif
 }
 
 void MemoryPressureHandler::ReliefLogger::logMemoryUsageChange()

Modified: trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm (197826 => 197827)


--- trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm	2016-03-09 02:06:55 UTC (rev 197827)
@@ -27,19 +27,13 @@
 #import "MemoryPressureHandler.h"
 
 #import "IOSurfacePool.h"
-#import "GCController.h"
-#import "JSDOMWindow.h"
-#import "JSDOMWindowBase.h"
 #import "LayerPool.h"
 #import "Logging.h"
 #import "ResourceUsageThread.h"
-#import "WebCoreSystemInterface.h"
 #import <mach/mach.h>
 #import <mach/task_info.h>
 #import <malloc/malloc.h>
 #import <notify.h>
-#import <wtf/CurrentTime.h>
-#import <sys/sysctl.h>
 
 #if PLATFORM(IOS)
 #import "SystemMemory.h"

Modified: trunk/Source/WebInspectorUI/ChangeLog (197826 => 197827)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-03-09 02:06:55 UTC (rev 197827)
@@ -1,5 +1,58 @@
 2016-03-08  Joseph Pecoraro  <pecor...@apple.com>
 
+        Web Inspector: Memory Timeline should show MemoryPressure events
+        https://bugs.webkit.org/show_bug.cgi?id=155158
+        <rdar://problem/25026610>
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Main.html:
+        New resources.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector.loaded):
+        * UserInterface/Controllers/MemoryManager.js:
+        (WebInspector.MemoryManager):
+        (WebInspector.MemoryManager.prototype.memoryPressure):
+        * UserInterface/Protocol/MemoryObserver.js:
+        (WebInspector.MemoryObserver.prototype.memoryPressure):
+        New manager for Memory domain events.
+
+        * UserInterface/Controllers/TimelineManager.js:
+        (WebInspector.TimelineManager):
+        (WebInspector.TimelineManager.defaultInstruments):
+        (WebInspector.TimelineManager.prototype._memoryPressure):
+        * UserInterface/Models/TimelineRecording.js:
+        (WebInspector.TimelineRecording.prototype.addMemoryPressureEvent):
+        Add events to the Memory Timeline of the active recording.
+
+        * UserInterface/Models/MemoryTimeline.js:
+        (WebInspector.MemoryTimeline.prototype.get memoryPressureEvents):
+        (WebInspector.MemoryTimeline.prototype.addMemoryPressureEvent):
+        (WebInspector.MemoryTimeline.prototype.reset):
+        (WebInspector.MemoryTimeline):
+        * UserInterface/Models/Timeline.js:
+        (WebInspector.Timeline.create):
+        Create a specific MemoryTimeline to hold records and memory pressure events.
+
+        * UserInterface/Models/MemoryPressureEvent.js:
+        (WebInspector.MemoryPressureEvent):
+        (WebInspector.MemoryPressureEvent.fromPayload):
+        (WebInspector.MemoryPressureEvent.prototype.get timestamp):
+        (WebInspector.MemoryPressureEvent.prototype.get severity):
+        Model object for a memory pressure event.
+
+        * UserInterface/Views/MemoryTimelineOverviewGraph.css:
+        (.timeline-overview-graph.memory .memory-pressure-event):
+        * UserInterface/Views/MemoryTimelineOverviewGraph.js:
+        (WebInspector.MemoryTimelineOverviewGraph):
+        (WebInspector.MemoryTimelineOverviewGraph.prototype.reset):
+        (WebInspector.MemoryTimelineOverviewGraph.prototype._visibleMemoryPressureEvents):
+        (WebInspector.MemoryTimelineOverviewGraph.prototype._memoryTimelineMemoryPressureEventAdded):
+        Include markers for memory pressure events.
+
+2016-03-08  Joseph Pecoraro  <pecor...@apple.com>
+
         Web Inspector: Add Heap domain start/stop tracking commands
         https://bugs.webkit.org/show_bug.cgi?id=155190
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -114,6 +114,7 @@
     this.analyzerManager = new WebInspector.AnalyzerManager;
     this.runtimeManager = new WebInspector.RuntimeManager;
     this.heapManager = new WebInspector.HeapManager;
+    this.memoryManager = new WebInspector.MemoryManager;
     this.applicationCacheManager = new WebInspector.ApplicationCacheManager;
     this.timelineManager = new WebInspector.TimelineManager;
     this.debuggerManager = new WebInspector.DebuggerManager;

Copied: trunk/Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js (from rev 197826, trunk/Source/WebInspectorUI/UserInterface/Protocol/MemoryObserver.js) (0 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+WebInspector.MemoryManager = class MemoryManager extends WebInspector.Object
+{
+    constructor()
+    {
+        super();
+
+        if (window.MemoryAgent)
+            MemoryAgent.enable();
+    }
+
+    // Public
+
+    memoryPressure(timestamp, protocolSeverity)
+    {
+        // Called from WebInspector.MemoryObserver.
+
+        let memoryPressureEvent = WebInspector.MemoryPressureEvent.fromPayload(timestamp, protocolSeverity);
+        this.dispatchEventToListeners(WebInspector.MemoryManager.Event.MemoryPressure, {memoryPressureEvent});
+    }
+};
+
+WebInspector.MemoryManager.Event = {
+    MemoryPressure: "memory-manager-memory-pressure",
+};

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -34,6 +34,7 @@
         WebInspector.Frame.addEventListener(WebInspector.Frame.Event.ResourceWasAdded, this._resourceWasAdded, this);
 
         WebInspector.heapManager.addEventListener(WebInspector.HeapManager.Event.GarbageCollected, this._garbageCollected, this);
+        WebInspector.memoryManager.addEventListener(WebInspector.MemoryManager.Event.MemoryPressure, this._memoryPressure, this);
 
         this._persistentNetworkTimeline = new WebInspector.NetworkTimeline;
 
@@ -670,6 +671,14 @@
         this._addRecord(new WebInspector.ScriptTimelineRecord(WebInspector.ScriptTimelineRecord.EventType.GarbageCollected, collection.startTime, collection.endTime, null, null, collection));
     }
 
+    _memoryPressure(event)
+    {
+        if (!this._isCapturing)
+            return;
+
+        this.activeRecording.addMemoryPressureEvent(event.data.memoryPressureEvent);
+    }
+
     _scriptProfilerTypeToScriptTimelineRecordType(type)
     {
         switch (type) {

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2016-03-09 02:06:55 UTC (rev 197827)
@@ -323,6 +323,8 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""
@@ -661,6 +663,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""

Copied: trunk/Source/WebInspectorUI/UserInterface/Models/MemoryPressureEvent.js (from rev 197826, trunk/Source/WebInspectorUI/UserInterface/Protocol/MemoryObserver.js) (0 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Models/MemoryPressureEvent.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/MemoryPressureEvent.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+WebInspector.MemoryPressureEvent = class MemoryPressureEvent extends WebInspector.Object
+{
+    constructor(timestamp, severity)
+    {
+        super();
+
+        this._timestamp = timestamp;
+        this._severity = severity;
+    }
+
+    // Static
+
+    static fromPayload(timestamp, protocolSeverity)
+    {
+        let severity;
+        switch (protocolSeverity) {
+        case MemoryAgent.MemoryPressureSeverity.Critical:
+            severity = WebInspector.MemoryPressureEvent.Severity.Critical;
+            break;
+        case MemoryAgent.MemoryPressureSeverity.NonCritical:
+            severity = WebInspector.MemoryPressureEvent.Severity.NonCritical;
+            break;
+        default:
+            console.error("Unexpected memory pressure severity", protocolSeverity);
+            severity = WebInspector.MemoryPressureEvent.Severity.NonCritical;
+            break;
+        }
+
+        return new WebInspector.MemoryPressureEvent(timestamp, severity);
+    }
+
+    // Public
+
+    get timestamp() { return this._timestamp; }
+    get severity() { return this._severity; }
+};
+
+WebInspector.MemoryPressureEvent.Severity = {
+    Critical: Symbol("Critical"),
+    NonCritical: Symbol("NonCritical"),
+};

Copied: trunk/Source/WebInspectorUI/UserInterface/Models/MemoryTimeline.js (from rev 197826, trunk/Source/WebInspectorUI/UserInterface/Protocol/MemoryObserver.js) (0 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Models/MemoryTimeline.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/MemoryTimeline.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+WebInspector.MemoryTimeline = class MemoryTimeline extends WebInspector.Timeline
+{
+    // Public
+
+    get memoryPressureEvents() { return this._pressureEvents; }
+
+    addMemoryPressureEvent(memoryPressureEvent)
+    {
+        console.assert(memoryPressureEvent instanceof WebInspector.MemoryPressureEvent);
+
+        this._pressureEvents.push(memoryPressureEvent);
+
+        this.dispatchEventToListeners(WebInspector.MemoryTimeline.Event.MemoryPressureEventAdded, {memoryPressureEvent})
+    }
+
+    // Protected
+
+    reset(suppressEvents)
+    {
+        super.reset(suppressEvents);
+
+        this._pressureEvents = [];
+    }
+};
+
+WebInspector.MemoryTimeline.Event = {
+    MemoryPressureEventAdded: "memory-timeline-memory-pressure-event-added",
+};

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Timeline.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Timeline.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Timeline.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -41,6 +41,9 @@
         if (type === WebInspector.TimelineRecord.Type.Network)
             return new WebInspector.NetworkTimeline(type);
 
+        if (type === WebInspector.TimelineRecord.Type.Memory)
+            return new WebInspector.MemoryTimeline(type);
+
         return new WebInspector.Timeline(type);
     }
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -274,6 +274,16 @@
             this.dispatchEventToListeners(WebInspector.TimelineRecording.Event.SourceCodeTimelineAdded, {sourceCodeTimeline});
     }
 
+    addMemoryPressureEvent(memoryPressureEvent)
+    {
+        let memoryTimeline = this._timelines.get(WebInspector.TimelineRecord.Type.Memory);
+        console.assert(memoryTimeline, this._timelines);
+        if (!memoryTimeline)
+            return;
+
+        memoryTimeline.addMemoryPressureEvent(memoryPressureEvent);
+    }
+
     computeElapsedTime(timestamp)
     {
         if (!timestamp || isNaN(timestamp))

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/MemoryObserver.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/MemoryObserver.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/MemoryObserver.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -27,6 +27,11 @@
 {
     // Events defined by the "Memory" domain.
 
+    memoryPressure(timestamp, severity)
+    {
+        WebInspector.memoryManager.memoryPressure(timestamp, severity);
+    }
+
     trackingStart(timestamp)
     {
         WebInspector.timelineManager.memoryTrackingStart(timestamp);

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/Test.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -56,6 +56,7 @@
     this.issueManager = new WebInspector.IssueManager;
     this.runtimeManager = new WebInspector.RuntimeManager;
     this.heapManager = new WebInspector.HeapManager;
+    this.memoryManager = new WebInspector.MemoryManager;
     this.timelineManager = new WebInspector.TimelineManager;
     this.debuggerManager = new WebInspector.DebuggerManager;
     this.probeManager = new WebInspector.ProbeManager;

Modified: trunk/Source/WebInspectorUI/UserInterface/Test.html (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Test.html	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Test.html	2016-03-09 02:06:55 UTC (rev 197827)
@@ -124,6 +124,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""
@@ -165,6 +166,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/MemoryTimelineOverviewGraph.css (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Views/MemoryTimelineOverviewGraph.css	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/MemoryTimelineOverviewGraph.css	2016-03-09 02:06:55 UTC (rev 197827)
@@ -44,6 +44,13 @@
     color: hsl(0, 0%, 50%);
 }
 
+.timeline-overview-graph.memory .memory-pressure-event {
+    border-left: 1px solid black;
+    position: absolute;
+    top: 0;
+    bottom: 0;
+}
+
 .timeline-overview-graph:nth-child(even) > .legend {
     background-color: hsl(0, 0%, 96%);
 }

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/MemoryTimelineOverviewGraph.js (197826 => 197827)


--- trunk/Source/WebInspectorUI/UserInterface/Views/MemoryTimelineOverviewGraph.js	2016-03-09 02:06:45 UTC (rev 197826)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/MemoryTimelineOverviewGraph.js	2016-03-09 02:06:55 UTC (rev 197827)
@@ -31,19 +31,25 @@
 
         this.element.classList.add("memory");
 
+        console.assert(timeline instanceof WebInspector.MemoryTimeline);
+
         this._memoryTimeline = timeline;
         this._memoryTimeline.addEventListener(WebInspector.Timeline.Event.RecordAdded, this._memoryTimelineRecordAdded, this);
+        this._memoryTimeline.addEventListener(WebInspector.MemoryTimeline.Event.MemoryPressureEventAdded, this._memoryTimelineMemoryPressureEventAdded, this)
 
         this._didInitializeCategories = false;
 
         let size = new WebInspector.Size(0, this.height);
         this._chart = new WebInspector.StackedLineChart(size);
-
         this.element.appendChild(this._chart.element);
 
         this._legendElement = this.element.appendChild(document.createElement("div"));
         this._legendElement.classList.add("legend");
 
+        this._memoryPressureMarkersContainerElement = this.element.appendChild(document.createElement("div"));
+        this._memoryPressureMarkersContainerElement.classList.add("memory-pressure-markers-container");
+        this._memoryPressureMarkerElements = [];
+
         this.reset();
     }
 
@@ -63,6 +69,9 @@
         this._updateLegend();
         this._chart.clear();
         this._chart.needsLayout();
+
+        this._memoryPressureMarkersContainerElement.removeChildren();
+        this._memoryPressureMarkerElements = [];
     }
 
     layout()
@@ -85,10 +94,6 @@
         let graphCurrentTime = this.currentTime;
         let visibleEndTime = Math.min(this.endTime, this.currentTime);
 
-        let visibleRecords = this._visibleRecords(graphStartTime, visibleEndTime);
-        if (!visibleRecords.length)
-            return;
-
         let secondsPerPixel = this.timelineOverview.secondsPerPixel;
         let maxCapacity = this._maxSize * 1.05; // Add 5% for padding.
 
@@ -101,6 +106,33 @@
             return height - ((size / maxCapacity) * height);
         }
 
+        let visibleMemoryPressureEventMarkers = this._visibleMemoryPressureEvents(graphStartTime, visibleEndTime);
+
+        // Reuse existing marker elements.
+        for (let i = 0; i < visibleMemoryPressureEventMarkers.length; ++i) {
+            let markerElement = this._memoryPressureMarkerElements[i];
+            if (!markerElement) {
+                markerElement = this._memoryPressureMarkersContainerElement.appendChild(document.createElement("div"));
+                markerElement.classList.add("memory-pressure-event");
+                this._memoryPressureMarkerElements[i] = markerElement;
+            }
+
+            let memoryPressureEvent = visibleMemoryPressureEventMarkers[i];
+            markerElement.style.left = xScale(memoryPressureEvent.timestamp) + "px";
+        }
+
+        // Remove excess marker elements.
+        let excess = this._memoryPressureMarkerElements.length - visibleMemoryPressureEventMarkers.length;
+        if (excess) {
+            let elementsToRemove = this._memoryPressureMarkerElements.splice(visibleMemoryPressureEventMarkers.length);
+            for (let element of elementsToRemove)
+                element.remove();
+        }
+
+        let visibleRecords = this._visibleRecords(graphStartTime, visibleEndTime);
+        if (!visibleRecords.length)
+            return;
+
         function pointSetForRecord(record) {
             let size = 0;
             let ys = [];
@@ -142,6 +174,17 @@
         }
     }
 
+    _visibleMemoryPressureEvents(startTime, endTime)
+    {
+        let events = this._memoryTimeline.memoryPressureEvents;
+        if (!events.length)
+            return [];
+
+        let lowerIndex = events.lowerBound(startTime, (time, event) => time - event.timestamp);
+        let upperIndex = events.upperBound(endTime, (time, event) => time - event.timestamp);
+        return events.slice(lowerIndex, upperIndex);
+    }
+
     _visibleRecords(startTime, endTime)
     {
         let records = this._memoryTimeline.records;
@@ -174,4 +217,9 @@
 
         this.needsLayout();
     }
+
+    _memoryTimelineMemoryPressureEventAdded(event)
+    {
+        this.needsLayout();
+    }
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to