ResourceUsageOverlay should show GC timers.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Dec 2015 21:36:27 +0000 (21:36 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Dec 2015 21:36:27 +0000 (21:36 +0000)
<https://webkit.org/b/152151>

Reviewed by Darin Adler.

Source/JavaScriptCore:

Expose the next fire time (in WTF timestamp style) of a GCActivityCallback.

* heap/GCActivityCallback.cpp:
(JSC::GCActivityCallback::scheduleTimer):
(JSC::GCActivityCallback::cancelTimer):
* heap/GCActivityCallback.h:

Source/WebCore:

Add countdowns until next Eden and Full GC to the overlay. It also shows if there
is no garbage collection scheduled. This will be helpful in understanding why GC
sometimes takes a very long time to happen.

* page/ResourceUsageOverlay.h:
* page/cocoa/ResourceUsageOverlayCocoa.mm:
(WebCore::formatByteNumber): Drive-by silly math fix. :|
(WebCore::gcTimerString):
(WebCore::ResourceUsageOverlay::platformDraw):
(WebCore::nextFireTimeForGCTimer):
(WebCore::runSamplerThread):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194057 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/GCActivityCallback.cpp
Source/JavaScriptCore/heap/GCActivityCallback.h
Source/WebCore/ChangeLog
Source/WebCore/page/ResourceUsageOverlay.h
Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm

index 2be3ab6..827fb8b 100644 (file)
@@ -1,3 +1,17 @@
+2015-12-14  Andreas Kling  <akling@apple.com>
+
+        ResourceUsageOverlay should show GC timers.
+        <https://webkit.org/b/152151>
+
+        Reviewed by Darin Adler.
+
+        Expose the next fire time (in WTF timestamp style) of a GCActivityCallback.
+
+        * heap/GCActivityCallback.cpp:
+        (JSC::GCActivityCallback::scheduleTimer):
+        (JSC::GCActivityCallback::cancelTimer):
+        * heap/GCActivityCallback.h:
+
 2015-12-14  Filip Pizlo  <fpizlo@apple.com>
 
         Unreviewed, fix merge issue in a test.
index 4c37b19..4d5d20a 100644 (file)
@@ -95,12 +95,14 @@ void GCActivityCallback::scheduleTimer(double newDelay)
         return;
     double delta = m_delay - newDelay;
     m_delay = newDelay;
+    m_nextFireTime = WTF::currentTime() + newDelay;
     CFRunLoopTimerSetNextFireDate(m_timer.get(), CFRunLoopTimerGetNextFireDate(m_timer.get()) - delta);
 }
 
 void GCActivityCallback::cancelTimer()
 {
     m_delay = s_decade;
+    m_nextFireTime = 0;
     CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade);
 }
 #elif PLATFORM(EFL)
index 57bd999..c0283e9 100644 (file)
@@ -61,6 +61,10 @@ public:
 
     static bool s_shouldCreateGCTimer;
 
+#if USE(CF) || PLATFORM(EFL)
+    double nextFireTime() const { return m_nextFireTime; }
+#endif
+
 protected:
     virtual double lastGCLength() = 0;
     virtual double gcTimeSlice(size_t bytes) = 0;
@@ -109,6 +113,7 @@ protected:
 
 private:
     double m_delay;
+    double m_nextFireTime { 0 };
 #endif
 };
 
index 8763a81..ec207c4 100644 (file)
@@ -1,3 +1,22 @@
+2015-12-14  Andreas Kling  <akling@apple.com>
+
+        ResourceUsageOverlay should show GC timers.
+        <https://webkit.org/b/152151>
+
+        Reviewed by Darin Adler.
+
+        Add countdowns until next Eden and Full GC to the overlay. It also shows if there
+        is no garbage collection scheduled. This will be helpful in understanding why GC
+        sometimes takes a very long time to happen.
+
+        * page/ResourceUsageOverlay.h:
+        * page/cocoa/ResourceUsageOverlayCocoa.mm:
+        (WebCore::formatByteNumber): Drive-by silly math fix. :|
+        (WebCore::gcTimerString):
+        (WebCore::ResourceUsageOverlay::platformDraw):
+        (WebCore::nextFireTimeForGCTimer):
+        (WebCore::runSamplerThread):
+
 2015-12-14  Chris Fleizach  <cfleizach@apple.com>
 
         AX: iOS: Text field variations do not have the correct traits
index b075cff..fd92f4c 100644 (file)
@@ -59,7 +59,7 @@ public:
 #endif
 
     static const int normalWidth = 570;
-    static const int normalHeight = 130;
+    static const int normalHeight = 160;
 
 private:
     void pageOverlayDestroyed(PageOverlay&) override { }
index c33beb7..d5093e1 100644 (file)
@@ -32,6 +32,7 @@
 #include "MachVMSPI.h"
 #include "PlatformCALayer.h"
 #include <CoreGraphics/CGContext.h>
+#include <JavaScriptCore/GCActivityCallback.h>
 #include <QuartzCore/CALayer.h>
 #include <QuartzCore/CATransaction.h>
 #include <array>
@@ -185,6 +186,9 @@ struct ResourceUsageData {
 
     HashSet<CALayer *> overlayLayers;
     JSC::VM* vm { nullptr };
+
+    double timeOfNextEdenCollection { 0 };
+    double timeOfNextFullCollection { 0 };
 };
 
 ResourceUsageData::ResourceUsageData()
@@ -421,7 +425,7 @@ static void drawMemoryPie(CGContextRef context, FloatRect& rect, ResourceUsageDa
 static String formatByteNumber(size_t number)
 {
     if (number >= 1024 * 1048576)
-        return String::format("%.3f GB", static_cast<double>(number) / 1024 * 1048576);
+        return String::format("%.3f GB", static_cast<double>(number) / (1024 * 1048576));
     if (number >= 1048576)
         return String::format("%.2f MB", static_cast<double>(number) / 1048576);
     if (number >= 1024)
@@ -429,6 +433,13 @@ static String formatByteNumber(size_t number)
     return String::format("%lu", number);
 }
 
+static String gcTimerString(double timerFireDate, double now)
+{
+    if (!timerFireDate)
+        return ASCIILiteral("[not scheduled]");
+    return String::format("%g", timerFireDate - now);
+}
+
 void ResourceUsageOverlay::platformDraw(CGContextRef context)
 {
     auto& data = sharedData();
@@ -461,6 +472,10 @@ void ResourceUsageOverlay::platformDraw(CGContextRef context)
         y += 10;
     }
 
+    double now = WTF::currentTime();
+    showText(context, 10, y + 10, colorForLabels, String::format("    Eden GC: %s", gcTimerString(data.timeOfNextEdenCollection, now).ascii().data()));
+    showText(context, 10, y + 20, colorForLabels, String::format("    Full GC: %s", gcTimerString(data.timeOfNextFullCollection, now).ascii().data()));
+
     drawCpuHistory(context, viewBounds.size.width - 70, 0, viewBounds.size.height, data.cpuHistory);
     drawGCHistory(context, viewBounds.size.width - 140, 0, viewBounds.size.height, data.gcHeapSizeHistory, data.categories[MemoryCategory::GCHeap].history);
     drawMemHistory(context, viewBounds.size.width - 210, 0, viewBounds.size.height, data);
@@ -609,6 +624,9 @@ NO_RETURN void runSamplerThread(void*)
             // Subtract known subchunks from the bmalloc bucket.
             // FIXME: Handle running with bmalloc disabled.
             data.categories[MemoryCategory::bmalloc].history.last() -= currentGCHeapCapacity + currentGCOwned;
+
+            data.timeOfNextEdenCollection = data.vm->heap.edenActivityCallback()->nextFireTime();
+            data.timeOfNextFullCollection = data.vm->heap.fullActivityCallback()->nextFireTime();
         }
 
         [CATransaction begin];