Bug 1134279 - Make TelemetryPing and TelemetrySession code use the "FHR enabled" & "Telemetry enabled" prefs properly. r=vladan
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Wed, 25 Mar 2015 16:42:14 +0100
changeset 264551 2aa9f4d0385dc96b1ce0c5ff4f439ce0f42d7b41
parent 264550 01482cdccd72b4f36f10ff3706a92c4c77c48253
child 264552 135c75e6fa1eb65189ebbebddffc5654b4d67c38
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan
bugs1134279
milestone39.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 1134279 - Make TelemetryPing and TelemetrySession code use the "FHR enabled" & "Telemetry enabled" prefs properly. r=vladan
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/Telemetry.h
toolkit/components/telemetry/nsITelemetry.idl
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -643,17 +643,18 @@ class TelemetryImpl final
 {
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSITELEMETRY
   NS_DECL_NSIMEMORYREPORTER
 
 public:
   void InitMemoryReporter();
 
-  static bool CanRecord();
+  static bool CanRecordBase();
+  static bool CanRecordExtended();
   static already_AddRefed<nsITelemetry> CreateTelemetryInstance();
   static void ShutdownTelemetry();
   static void RecordSlowStatement(const nsACString &sql, const nsACString &dbName,
                                   uint32_t delay);
 #if defined(MOZ_ENABLE_PROFILER_SPS)
   static void RecordChromeHang(uint32_t aDuration,
                                Telemetry::ProcessedStack &aStack,
                                int32_t aSystemUptime,
@@ -726,17 +727,18 @@ private:
                                       AddonHistogramInfo &info);
   void ReadLateWritesStacks(nsIFile* aProfileDir);
   AddonMapType mAddonMap;
 
   // This is used for speedy string->Telemetry::ID conversions
   typedef nsBaseHashtableET<nsDepCharHashKey, Telemetry::ID> CharPtrEntryType;
   typedef AutoHashtable<CharPtrEntryType> HistogramMapType;
   HistogramMapType mHistogramMap;
-  bool mCanRecord;
+  bool mCanRecordBase;
+  bool mCanRecordExtended;
   static TelemetryImpl *sTelemetry;
   AutoHashtable<SlowSQLEntryType> mPrivateSQL;
   AutoHashtable<SlowSQLEntryType> mSanitizedSQL;
   // This gets marked immutable in debug builds, so we can't use
   // AutoHashtable here.
   nsTHashtable<nsCStringHashKey> mTrackedDBs;
   Mutex mHashMutex;
   HangReports mHangReports;
@@ -1205,17 +1207,17 @@ JSHistogram_Add(JSContext *cx, unsigned 
       return false;
     }
 
     if (!JS::ToInt32(cx, args[0], &value)) {
       return false;
     }
   }
 
-  if (TelemetryImpl::CanRecord()) {
+  if (TelemetryImpl::CanRecordExtended()) {
     HistogramAdd(*h, value);
   }
 
   return true;
 }
 
 bool
 JSHistogram_Snapshot(JSContext *cx, unsigned argc, JS::Value *vp)
@@ -1746,17 +1748,17 @@ TelemetryImpl::AsyncFetchTelemetryData(n
   if (mCallbacks.Count() != 0) {
     mCallbacks.AppendObject(aCallback);
     return NS_OK;
   }
 
   // We make this check so that GetShutdownTimeFileName() doesn't get
   // called; calling that function without telemetry enabled violates
   // assumptions that the write-the-shutdown-timestamp machinery makes.
-  if (!Telemetry::CanRecord()) {
+  if (!Telemetry::CanRecordExtended()) {
     mCachedTelemetryData = true;
     aCallback->Complete();
     return NS_OK;
   }
 
   // Send the read to a background thread provided by the stream transport
   // service to avoid a read in the main thread.
   nsCOMPtr<nsIEventTarget> targetThread =
@@ -1800,18 +1802,20 @@ TelemetryImpl::AsyncFetchTelemetryData(n
                                                          profileDir);
 
   targetThread->Dispatch(event, NS_DISPATCH_NORMAL);
   return NS_OK;
 }
 
 TelemetryImpl::TelemetryImpl():
 mHistogramMap(Telemetry::HistogramCount),
-mCanRecord(XRE_GetProcessType() == GeckoProcessType_Default ||
-           XRE_GetProcessType() == GeckoProcessType_Content),
+mCanRecordBase(XRE_GetProcessType() == GeckoProcessType_Default ||
+               XRE_GetProcessType() == GeckoProcessType_Content),
+mCanRecordExtended(XRE_GetProcessType() == GeckoProcessType_Default ||
+                   XRE_GetProcessType() == GeckoProcessType_Content),
 mHashMutex("Telemetry::mHashMutex"),
 mHangReportsMutex("Telemetry::mHangReportsMutex"),
 mThreadHangStatsMutex("Telemetry::mThreadHangStatsMutex"),
 mCachedTelemetryData(false),
 mLastShutdownTime(0),
 mFailedLockCount(0)
 {
   // A whitelist to prevent Telemetry reporting on Addon & Thunderbird DBs
@@ -3127,34 +3131,66 @@ TelemetryImpl::GetKeyedHistogramById(con
   }
 
   KeyedHistogram* keyed = nullptr;
   sTelemetry->mKeyedHistograms.Get(name, &keyed);
   return keyed;
 }
 
 NS_IMETHODIMP
-TelemetryImpl::GetCanRecord(bool *ret) {
-  *ret = mCanRecord;
+TelemetryImpl::GetCanRecordBase(bool *ret) {
+  *ret = mCanRecordBase;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-TelemetryImpl::SetCanRecord(bool canRecord) {
-  mCanRecord = !!canRecord;
+TelemetryImpl::SetCanRecordBase(bool canRecord) {
+  mCanRecordBase = canRecord;
   return NS_OK;
 }
 
+/**
+ * Indicates if Telemetry can record base data (FHR data). This is true if the
+ * FHR data reporting service or self-support are enabled.
+ *
+ * In the unlikely event that adding a new base probe is needed, please check the data
+ * collection wiki at https://wiki.mozilla.org/Firefox/Data_Collection and talk to the
+ * Telemetry team.
+ */
 bool
-TelemetryImpl::CanRecord() {
-  return !sTelemetry || sTelemetry->mCanRecord;
+TelemetryImpl::CanRecordBase() {
+  return !sTelemetry || sTelemetry->mCanRecordBase;
 }
 
 NS_IMETHODIMP
-TelemetryImpl::GetCanSend(bool *ret) {
+TelemetryImpl::GetCanRecordExtended(bool *ret) {
+  *ret = mCanRecordExtended;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+TelemetryImpl::SetCanRecordExtended(bool canRecord) {
+  mCanRecordExtended = canRecord;
+  return NS_OK;
+}
+
+/**
+ * Indicates if Telemetry is allowed to record extended data. Returns false if the user
+ * hasn't opted into "extended Telemetry" on the Release channel, when the user has
+ * explicitly opted out of Telemetry on Nightly/Aurora/Beta or if manually set to false
+ * during tests.
+ * If the returned value is false, gathering of extended telemetry statistics is disabled.
+ */
+bool
+TelemetryImpl::CanRecordExtended() {
+  return !sTelemetry || sTelemetry->mCanRecordExtended;
+}
+
+NS_IMETHODIMP
+TelemetryImpl::GetIsOfficialTelemetry(bool *ret) {
 #if defined(MOZILLA_OFFICIAL) && defined(MOZ_TELEMETRY_REPORTING)
   *ret = true;
 #else
   *ret = false;
 #endif
   return NS_OK;
 }
 
@@ -3339,17 +3375,17 @@ TelemetryImpl::SanitizeSQL(const nsACStr
 // that are appended at the end of the stored statement.
 const uint32_t kMaxSlowStatementLength = 1000;
 
 void
 TelemetryImpl::RecordSlowStatement(const nsACString &sql,
                                    const nsACString &dbName,
                                    uint32_t delay)
 {
-  if (!sTelemetry || !sTelemetry->mCanRecord)
+  if (!sTelemetry || !sTelemetry->mCanRecordExtended)
     return;
 
   bool isFirefoxDB = sTelemetry->mTrackedDBs.Contains(dbName);
   if (isFirefoxDB) {
     nsAutoCString sanitizedSQL(SanitizeSQL(sql));
     if (sanitizedSQL.Length() > kMaxSlowStatementLength) {
       sanitizedSQL.SetLength(kMaxSlowStatementLength);
       sanitizedSQL += "...";
@@ -3374,17 +3410,17 @@ TelemetryImpl::RecordSlowStatement(const
 #if defined(MOZ_ENABLE_PROFILER_SPS)
 void
 TelemetryImpl::RecordChromeHang(uint32_t aDuration,
                                 Telemetry::ProcessedStack &aStack,
                                 int32_t aSystemUptime,
                                 int32_t aFirefoxUptime,
                                 HangAnnotationsPtr aAnnotations)
 {
-  if (!sTelemetry || !sTelemetry->mCanRecord)
+  if (!sTelemetry || !sTelemetry->mCanRecordExtended)
     return;
 
   HangAnnotationsPtr annotations;
   // We only pass aAnnotations if it is not empty.
   if (aAnnotations && !aAnnotations->IsEmpty()) {
     annotations = Move(aAnnotations);
   }
 
@@ -3394,17 +3430,17 @@ TelemetryImpl::RecordChromeHang(uint32_t
                                    aSystemUptime, aFirefoxUptime,
                                    Move(annotations));
 }
 #endif
 
 void
 TelemetryImpl::RecordThreadHangStats(Telemetry::ThreadHangStats& aStats)
 {
-  if (!sTelemetry || !sTelemetry->mCanRecord)
+  if (!sTelemetry || !sTelemetry->mCanRecordExtended)
     return;
 
   MutexAutoLock autoLock(sTelemetry->mThreadHangStatsMutex);
 
   sTelemetry->mThreadHangStats.append(Move(aStats));
 }
 
 NS_IMPL_ISUPPORTS(TelemetryImpl, nsITelemetry, nsIMemoryReporter)
@@ -3514,17 +3550,17 @@ RecordShutdownStartTimeStamp() {
   // this assert has been firing. Given that if we are called multiple times
   // we just keep the last timestamp, the assert is commented for now.
   static bool recorded = false;
   //  MOZ_ASSERT(!recorded);
   (void)recorded; // Silence unused-var warnings (remove when assert re-enabled)
   recorded = true;
 #endif
 
-  if (!Telemetry::CanRecord())
+  if (!Telemetry::CanRecordExtended())
     return;
 
   gRecordedShutdownStartTime = TimeStamp::Now();
 
   GetShutdownTimeFileName();
 }
 
 void
@@ -3563,42 +3599,42 @@ RecordShutdownEndTimeStamp() {
   PR_Rename(tmpName.get(), name.get());
 }
 
 namespace Telemetry {
 
 void
 Accumulate(ID aHistogram, uint32_t aSample)
 {
-  if (!TelemetryImpl::CanRecord()) {
+  if (!TelemetryImpl::CanRecordExtended()) {
     return;
   }
   Histogram *h;
   nsresult rv = GetHistogramByEnumId(aHistogram, &h);
   if (NS_SUCCEEDED(rv))
     HistogramAdd(*h, aSample);
 }
 
 void
 Accumulate(ID aID, const nsCString& aKey, uint32_t aSample)
 {
-  if (!TelemetryImpl::CanRecord()) {
+  if (!TelemetryImpl::CanRecordExtended()) {
     return;
   }
 
   const TelemetryHistogram& th = gHistograms[aID];
   KeyedHistogram* keyed = TelemetryImpl::GetKeyedHistogramById(nsDependentCString(th.id()));
   MOZ_ASSERT(keyed);
   keyed->Add(aKey, aSample);
 }
 
 void
 Accumulate(const char* name, uint32_t sample)
 {
-  if (!TelemetryImpl::CanRecord()) {
+  if (!TelemetryImpl::CanRecordExtended()) {
     return;
   }
   ID id;
   nsresult rv = TelemetryImpl::GetHistogramEnumId(name, &id);
   if (NS_FAILED(rv)) {
     return;
   }
 
@@ -3612,19 +3648,25 @@ Accumulate(const char* name, uint32_t sa
 void
 AccumulateTimeDelta(ID aHistogram, TimeStamp start, TimeStamp end)
 {
   Accumulate(aHistogram,
              static_cast<uint32_t>((end - start).ToMilliseconds()));
 }
 
 bool
-CanRecord()
+CanRecordBase()
 {
-  return TelemetryImpl::CanRecord();
+  return TelemetryImpl::CanRecordBase();
+}
+
+bool
+CanRecordExtended()
+{
+  return TelemetryImpl::CanRecordExtended();
 }
 
 base::Histogram*
 GetHistogramById(ID id)
 {
   Histogram *h = nullptr;
   GetHistogramByEnumId(id, &h);
   return h;
@@ -4097,17 +4139,17 @@ KeyedHistogram::ClearHistogramEnumerator
 {
   entry->mData->Clear();
   return PL_DHASH_NEXT;
 }
 
 nsresult
 KeyedHistogram::Add(const nsCString& key, uint32_t sample)
 {
-  if (!TelemetryImpl::CanRecord()) {
+  if (!TelemetryImpl::CanRecordExtended()) {
     return NS_OK;
   }
 
   Histogram* histogram = GetHistogram(key, false);
   MOZ_ASSERT(histogram);
   if (!histogram) {
     return NS_ERROR_FAILURE;
   }
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -169,21 +169,25 @@ public:
   }
 
 private:
   uint32_t counter;
   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 /**
- * Indicates whether Telemetry recording is turned on.  This is intended
- * to guard calls to Accumulate when the statistic being recorded is
- * expensive to compute.
+ * Indicates whether Telemetry base data recording is turned on. Added for future uses.
  */
-bool CanRecord();
+bool CanRecordBase();
+
+/**
+ * Indicates whether Telemetry extended data recording is turned on.  This is intended
+ * to guard calls to Accumulate when the statistic being recorded is expensive to compute.
+ */
+bool CanRecordExtended();
 
 /**
  * Records slow SQL statements for Telemetry reporting.
  *
  * @param statement - offending SQL statement to record
  * @param dbName - DB filename
  * @param delay - execution time in milliseconds
  */
--- a/toolkit/components/telemetry/nsITelemetry.idl
+++ b/toolkit/components/telemetry/nsITelemetry.idl
@@ -7,17 +7,17 @@
 #include "nsIFile.idl"
 
 [scriptable,function, uuid(3d3b9075-5549-4244-9c08-b64fefa1dd60)]
 interface nsIFetchTelemetryDataCallback : nsISupports
 {
   void complete();
 };
 
-[scriptable, uuid(1cd31579-2a81-4b99-900b-e89eea2e461c)]
+[scriptable, uuid(68e82b42-cad2-411f-857b-b64ea9377929)]
 interface nsITelemetry : nsISupports
 {
   /**
    * Histogram types:
    * HISTOGRAM_EXPONENTIAL - buckets increase exponentially
    * HISTOGRAM_LINEAR - buckets increase linearly
    * HISTOGRAM_BOOLEAN - For storing 0/1 values
    * HISTOGRAM_FLAG - For storing a single value; its count is always == 1.
@@ -246,24 +246,41 @@ interface nsITelemetry : nsISupports
    *
    * @param id - unique identifier from TelemetryHistograms.h
    * The returned object has the same functions as a histogram returned from newKeyedHistogram.
    */
   [implicit_jscontext]
   jsval getKeyedHistogramById(in ACString id);
 
   /**
-   * Set this to false to disable gathering of telemetry statistics.
+   * A flag indicating if Telemetry can record base data (FHR data). This is true if the
+   * FHR data reporting service or self-support are enabled.
+   *
+   * In the unlikely event that adding a new base probe is needed, please check the data
+   * collection wiki at https://wiki.mozilla.org/Firefox/Data_Collection and talk to the
+   * Telemetry team.
    */
-  attribute boolean canRecord;
+  attribute boolean canRecordBase;
 
   /**
-   * A flag indicating whether Telemetry can submit official results.
+   * A flag indicating if Telemetry is allowed to record extended data. Returns false if
+   * the user hasn't opted into "extended Telemetry" on the Release channel, when the
+   * user has explicitly opted out of Telemetry on Nightly/Aurora/Beta or if manually
+   * set to false during tests.
+   *
+   * Set this to false in tests to disable gathering of extended telemetry statistics.
    */
-  readonly attribute boolean canSend;
+  attribute boolean canRecordExtended;
+
+  /**
+   * A flag indicating whether Telemetry can submit official results (for base or extended
+   * data). This is true on official builds with built in support for Mozilla Telemetry
+   * reporting.
+   */
+  readonly attribute boolean isOfficialTelemetry;
 
   /** Addon telemetry hooks */
 
   /**
    * Register a histogram for an addon.  Throws an error if the
    * histogram name has been registered previously.
    *
    * @param addon_id - Unique ID of the addon