Bug 1451591 - Flush CacheIR Spewer on regular intervals. r=mgaudet
authorAdam Holm <asorholm@email.arizona.edu>
Wed, 28 Nov 2018 12:08:52 -0800
changeset 505280 3a2c2eb8f481dedfdf7680b856cdef72a34fece9
parent 505279 e2a7b9a99226012bac933c5315c898ef9379211b
child 505281 e0639d2ca407392acc67e65cc7eb058363e733e3
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1451591
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1451591 - Flush CacheIR Spewer on regular intervals. r=mgaudet
js/src/jit/CacheIRSpewer.cpp
js/src/jit/CacheIRSpewer.h
--- a/js/src/jit/CacheIRSpewer.cpp
+++ b/js/src/jit/CacheIRSpewer.cpp
@@ -26,18 +26,28 @@
 #include "vm/Realm-inl.h"
 
 using namespace js;
 using namespace js::jit;
 
 CacheIRSpewer CacheIRSpewer::cacheIRspewer;
 
 CacheIRSpewer::CacheIRSpewer()
-  : outputLock(mutexid::CacheIRSpewer)
-{ }
+  : outputLock(mutexid::CacheIRSpewer),
+    guardCount_(0)
+{
+
+    spewInterval_ = getenv("CACHEIR_LOG_FLUSH") ?
+                        atoi(getenv("CACHEIR_LOG_FLUSH")) :
+                        10000;
+
+    if (spewInterval_ < 1) {
+        spewInterval_ = 1;
+    }
+}
 
 CacheIRSpewer::~CacheIRSpewer()
 {
     if (!enabled()) {
         return;
     }
 
     json.ref().endList();
--- a/js/src/jit/CacheIRSpewer.h
+++ b/js/src/jit/CacheIRSpewer.h
@@ -22,16 +22,26 @@ namespace jit {
 
 class CacheIRSpewer
 {
     Mutex outputLock;
     Fprinter output;
     mozilla::Maybe<JSONPrinter> json;
     static CacheIRSpewer cacheIRspewer;
 
+    // Counter to record how many times Guard class is called. This is used to
+    // determine when to flush outputs based on the given interval value.
+    // For example, if |spewInterval_ = 2|, outputs will be flushed on
+    // guardCount_ values 0,2,4,6,...
+    uint32_t guardCount_;
+
+    // Interval at which to flush output files. This value can be set with the
+    // environment variable |CACHEIR_LOG_FLUSH|.
+    uint32_t spewInterval_;
+
     CacheIRSpewer();
     ~CacheIRSpewer();
 
     bool enabled() { return json.isSome(); }
 
     // These methods can only be called when enabled() is true.
     Mutex& lock() { MOZ_ASSERT(enabled()); return outputLock; }
 
@@ -63,16 +73,19 @@ class CacheIRSpewer
         }
 
         ~Guard() {
           if (sp_.enabled()) {
             if (name_ != nullptr) {
               sp_.attached(name_);
             }
             sp_.endCache();
+            if (sp_.guardCount_++ % sp_.spewInterval_ == 0) {
+              sp_.output.flush();
+            }
             sp_.lock().unlock();
           }
         }
 
         void valueProperty(const char* name, const Value& v) const {
           sp_.valueProperty(name, v);
         }