Bug 1409324 (part 2) - Add a new timer for nursery chunk allocation r=sfink
authorPaul Bone <pbone@mozilla.com>
Tue, 14 Nov 2017 20:30:34 +1100
changeset 436423 cfa3672ccb302afab66b9ffe830cb6480d51a124
parent 436422 05c80a2c4462a42c6b2a45fb8e4284c9e9b1fe96
child 436424 7159964287fe161b0dda9cdfa59d74bc7bead348
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewerssfink
bugs1409324
milestone59.0a1
Bug 1409324 (part 2) - Add a new timer for nursery chunk allocation r=sfink
js/src/gc/Nursery.cpp
js/src/gc/Nursery.h
--- a/js/src/gc/Nursery.cpp
+++ b/js/src/gc/Nursery.cpp
@@ -113,16 +113,17 @@ js::Nursery::Nursery(JSRuntime* rt)
   : runtime_(rt)
   , position_(0)
   , currentStartChunk_(0)
   , currentStartPosition_(0)
   , currentEnd_(0)
   , currentChunk_(0)
   , maxChunkCount_(0)
   , chunkCountLimit_(0)
+  , timeInChunkAlloc_(0)
   , previousPromotionRate_(0)
   , profileThreshold_(0)
   , enableProfiling_(false)
   , reportTenurings_(0)
   , minorGCTriggerReason_(JS::gcreason::NO_REASON)
   , minorGcCount_(0)
   , freeMallocedBuffersTask(nullptr)
 #ifdef JS_GC_ZEAL
@@ -318,19 +319,23 @@ js::Nursery::allocate(size_t size)
     if (currentEnd() < position() + size) {
         unsigned chunkno = currentChunk_ + 1;
         MOZ_ASSERT(chunkno <= chunkCountLimit());
         MOZ_ASSERT(chunkno <= maxChunkCount());
         MOZ_ASSERT(chunkno <= allocatedChunkCount());
         if (chunkno == maxChunkCount())
             return nullptr;
         if (MOZ_UNLIKELY(chunkno == allocatedChunkCount())) {
-            AutoLockGCBgAlloc lock(runtime());
-            if (!allocateNextChunk(chunkno, lock))
-                return nullptr;
+            mozilla::TimeStamp start = TimeStamp::Now();
+            {
+                AutoLockGCBgAlloc lock(runtime());
+                if (!allocateNextChunk(chunkno, lock))
+                    return nullptr;
+            }
+            timeInChunkAlloc_ += TimeStamp::Now() - start;
             MOZ_ASSERT(chunkno < allocatedChunkCount());
         }
         setCurrentChunk(chunkno);
     }
 
     void* thing = (void*)position();
     position_ = position() + size;
 
@@ -543,16 +548,18 @@ js::Nursery::renderProfileJSON(JSONPrint
     json.property("status", "complete");
 
     json.property("reason", JS::gcreason::ExplainReason(previousGC.reason));
     json.property("bytes_tenured", previousGC.tenuredBytes);
     json.property("bytes_used", previousGC.nurseryUsedBytes);
     json.property("cur_capacity", previousGC.nurseryCapacity);
     json.property("new_capacity", spaceToEnd());
     json.property("lazy_capacity", allocatedChunkCount() * ChunkSize);
+    if (!timeInChunkAlloc_.IsZero())
+        json.property("chunk_alloc_us", timeInChunkAlloc_, json.MICROSECONDS);
 
     json.beginObjectProperty("phase_times");
 
 #define EXTRACT_NAME(name, text) #name,
     static const char* names[] = {
 FOR_EACH_NURSERY_PROFILE_TIME(EXTRACT_NAME)
 #undef EXTRACT_NAME
     "" };
@@ -719,16 +726,17 @@ js::Nursery::collect(JS::gcreason::Reaso
     rt->addTelemetry(JS_TELEMETRY_GC_MINOR_REASON, reason);
     if (totalTime.ToMilliseconds() > 1.0)
         rt->addTelemetry(JS_TELEMETRY_GC_MINOR_REASON_LONG, reason);
     rt->addTelemetry(JS_TELEMETRY_GC_NURSERY_BYTES, sizeOfHeapCommitted());
     rt->addTelemetry(JS_TELEMETRY_GC_PRETENURE_COUNT, pretenureCount);
 
     rt->gc.stats().endNurseryCollection(reason);
     TraceMinorGCEnd();
+    timeInChunkAlloc_ = mozilla::TimeDuration();
 
     if (enableProfiling_ && totalTime >= profileThreshold_) {
         rt->gc.stats().maybePrintProfileHeaders();
 
         fprintf(stderr, "MinorGC: %20s %5.1f%% %4u        ",
                 JS::gcreason::ExplainReason(reason),
                 promotionRate * 100,
                 maxChunkCount());
--- a/js/src/gc/Nursery.h
+++ b/js/src/gc/Nursery.h
@@ -325,16 +325,18 @@ class Nursery
     unsigned maxChunkCount_;
 
     /*
      * This limit is fixed by configuration.  It represents the maximum size
      * the nursery is permitted to tune itself to in maybeResizeNursery();
      */
     unsigned chunkCountLimit_;
 
+    mozilla::TimeDuration timeInChunkAlloc_;
+
     /* Promotion rate for the previous minor collection. */
     float previousPromotionRate_;
 
     /* Report minor collections taking at least this long, if enabled. */
     mozilla::TimeDuration profileThreshold_;
     bool enableProfiling_;
 
     /* Report ObjectGroups with at lest this many instances tenured. */