Bug 1580227 - Add GC 'effectiveness' score to help understand whether we trigger GC at the right time r=pbone data-review=mmccorquodale
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 30 Sep 2019 09:53:55 +0000
changeset 495620 6b0aaa84ee8e574923e53ab503e38daeaa07bb0c
parent 495619 c62a28520dd66c0697afbf8d809db55778ea66f8
child 495621 a864ed2ae59a54616d40dabc67265ab4341a73a8
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbone
bugs1580227
milestone71.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 1580227 - Add GC 'effectiveness' score to help understand whether we trigger GC at the right time r=pbone data-review=mmccorquodale Differential Revision: https://phabricator.services.mozilla.com/D45517
js/src/gc/Statistics.cpp
js/src/jsfriendapi.h
js/xpconnect/src/XPCJSRuntime.cpp
toolkit/components/telemetry/Histograms.json
--- a/js/src/gc/Statistics.cpp
+++ b/js/src/gc/Statistics.cpp
@@ -1095,16 +1095,26 @@ void Statistics::sendGCTelemetry() {
     }
   }
 
   MOZ_ASSERT(preCollectedHeapBytes >= bytesSurvived);
   double survialRate =
       100.0 * double(bytesSurvived) / double(preCollectedHeapBytes);
   runtime->addTelemetry(JS_TELEMETRY_GC_TENURED_SURVIVAL_RATE,
                         uint32_t(survialRate));
+
+  // Calculate 'effectiveness' in MB / second, on main thread only for now.
+  if (!runtime->parentRuntime) {
+    size_t bytesFreed = preCollectedHeapBytes - bytesSurvived;
+    TimeDuration clampedTotal =
+        TimeDuration::Max(total, TimeDuration::FromMilliseconds(1));
+    double effectiveness =
+        (double(bytesFreed) / (1024.0 * 1024.0)) / clampedTotal.ToSeconds();
+    runtime->addTelemetry(JS_TELEMETRY_GC_EFFECTIVENESS, uint32_t(effectiveness));
+  }
 }
 
 void Statistics::beginNurseryCollection(JS::GCReason reason) {
   count(COUNT_MINOR_GC);
   startingMinorGCNumber = runtime->gc.minorGCCount();
   if (nurseryCollectionCallback) {
     (*nurseryCollectionCallback)(
         runtime->mainContextFromOwnThread(),
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -168,16 +168,17 @@ enum {
   JS_TELEMETRY_GC_NURSERY_BYTES,
   JS_TELEMETRY_GC_PRETENURE_COUNT,
   JS_TELEMETRY_GC_NURSERY_PROMOTION_RATE,
   JS_TELEMETRY_GC_TENURED_SURVIVAL_RATE,
   JS_TELEMETRY_GC_MARK_RATE,
   JS_TELEMETRY_GC_TIME_BETWEEN_S,
   JS_TELEMETRY_GC_TIME_BETWEEN_SLICES_MS,
   JS_TELEMETRY_GC_SLICE_COUNT,
+  JS_TELEMETRY_GC_EFFECTIVENESS,
   JS_TELEMETRY_PRIVILEGED_PARSER_COMPILE_LAZY_AFTER_MS,
   JS_TELEMETRY_WEB_PARSER_COMPILE_LAZY_AFTER_MS,
   JS_TELEMETRY_DEPRECATED_ARRAY_GENERICS,
   JS_TELEMETRY_END
 };
 
 typedef void (*JSAccumulateTelemetryDataCallback)(int id, uint32_t sample,
                                                   const char* key);
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2755,16 +2755,19 @@ static void AccumulateTelemetryCallback(
       Telemetry::Accumulate(Telemetry::GC_TIME_BETWEEN_S, sample);
       break;
     case JS_TELEMETRY_GC_TIME_BETWEEN_SLICES_MS:
       Telemetry::Accumulate(Telemetry::GC_TIME_BETWEEN_SLICES_MS, sample);
       break;
     case JS_TELEMETRY_GC_SLICE_COUNT:
       Telemetry::Accumulate(Telemetry::GC_SLICE_COUNT, sample);
       break;
+    case JS_TELEMETRY_GC_EFFECTIVENESS:
+      Telemetry::Accumulate(Telemetry::GC_EFFECTIVENESS, sample);
+      break;
     case JS_TELEMETRY_PRIVILEGED_PARSER_COMPILE_LAZY_AFTER_MS:
       Telemetry::Accumulate(
           Telemetry::JS_PRIVILEGED_PARSER_COMPILE_LAZY_AFTER_MS, sample);
       break;
     case JS_TELEMETRY_WEB_PARSER_COMPILE_LAZY_AFTER_MS:
       Telemetry::Accumulate(Telemetry::JS_WEB_PARSER_COMPILE_LAZY_AFTER_MS,
                             sample);
       break;
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -1045,16 +1045,29 @@
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 200,
     "n_buckets": 50,
     "releaseChannelCollection": "opt-out",
     "bug_numbers": [1556467],
     "description": "The number of slices in an incremental GC for the main runtime"
   },
+  "GC_EFFECTIVENESS": {
+    "record_in_processes": ["main", "content"],
+    "products": ["firefox", "fennec", "geckoview"],
+    "alert_emails": ["dev-telemetry-gc-alerts@mozilla.org", "jcoppeard@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "releaseChannelCollection": "opt-out",
+    "low": 1,
+    "high": 50000,
+    "n_buckets": 100,
+    "bug_numbers": [1580227],
+    "description": "GC 'effectiveness', the amount of memory freed divided by main-thread collection time (MB/s)"
+  },
   "GEOLOCATION_ACCURACY_EXPONENTIAL": {
     "record_in_processes": ["main", "content"],
     "products": ["firefox", "fennec", "geckoview"],
     "expires_in_version": "never",
     "kind": "exponential",
     "releaseChannelCollection": "opt-out",
     "bug_numbers": [1507925],
     "high": 100000,