bug 1498165 - Support multistore in ScalarUnsigned r=janerik
authorChris H-C <chutten@mozilla.com>
Tue, 20 Nov 2018 19:57:55 +0000
changeset 503799 14622853d38cad2becb3ae24fbdaddf45aed8cde
parent 503798 63a07c0d07ae75a54923fa946b656582d74b82eb
child 503800 c6176b21937b0ab446ffde1dcadff6e6aaa0e7af
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)
reviewersjanerik
bugs1498165
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 1498165 - Support multistore in ScalarUnsigned r=janerik This one's a little trickier than the others because it has an implicit default value of 0 for initial calls to AddValue and SetMaximum. Depends on D12129 Differential Revision: https://phabricator.services.mozilla.com/D12130
toolkit/components/telemetry/core/TelemetryScalar.cpp
--- a/toolkit/components/telemetry/core/TelemetryScalar.cpp
+++ b/toolkit/components/telemetry/core/TelemetryScalar.cpp
@@ -439,128 +439,156 @@ ScalarBase::SizeOfExcludingThis(mozilla:
 /**
  * The implementation for the unsigned int scalar type.
  */
 class ScalarUnsigned : public ScalarBase
 {
 public:
   using ScalarBase::SetValue;
 
-  ScalarUnsigned(const BaseScalarInfo& aInfo)
+  explicit ScalarUnsigned(const BaseScalarInfo& aInfo)
     : ScalarBase(aInfo)
-    , mStorage(0)
-  {};
+    , mStorage(aInfo.storeCount())
+  {
+    mStorage.SetLength(aInfo.storeCount());
+    for (auto& val: mStorage) {
+      val = 0;
+    }
+  };
 
   ~ScalarUnsigned() override = default;
 
   ScalarResult SetValue(nsIVariant* aValue) final;
   void SetValue(uint32_t aValue) final;
   ScalarResult AddValue(nsIVariant* aValue) final;
   void AddValue(uint32_t aValue) final;
   ScalarResult SetMaximum(nsIVariant* aValue) final;
   void SetMaximum(uint32_t aValue) final;
   nsresult GetValue(const nsACString& aStoreName, nsCOMPtr<nsIVariant>& aResult) const final;
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const final;
 
 private:
-  uint32_t mStorage;
+  nsTArray<uint32_t> mStorage;
 
   ScalarResult CheckInput(nsIVariant* aValue);
 
   // Prevent copying.
   ScalarUnsigned(const ScalarUnsigned& aOther) = delete;
   void operator=(const ScalarUnsigned& aOther) = delete;
 };
 
 ScalarResult
 ScalarUnsigned::SetValue(nsIVariant* aValue)
 {
   ScalarResult sr = CheckInput(aValue);
   if (sr == ScalarResult::UnsignedNegativeValue) {
     return sr;
   }
 
-  if (NS_FAILED(aValue->GetAsUint32(&mStorage))) {
+  uint32_t value = 0;
+  if (NS_FAILED(aValue->GetAsUint32(&value))) {
     return ScalarResult::InvalidValue;
   }
+
+  SetValue(value);
   return sr;
 }
 
 void
 ScalarUnsigned::SetValue(uint32_t aValue)
 {
-  mStorage = aValue;
+  for (auto& val: mStorage) {
+    val = aValue;
+  }
+  SetValueInStores();
 }
 
 ScalarResult
 ScalarUnsigned::AddValue(nsIVariant* aValue)
 {
   ScalarResult sr = CheckInput(aValue);
   if (sr == ScalarResult::UnsignedNegativeValue) {
     return sr;
   }
 
   uint32_t newAddend = 0;
   nsresult rv = aValue->GetAsUint32(&newAddend);
   if (NS_FAILED(rv)) {
     return ScalarResult::InvalidValue;
   }
-  mStorage += newAddend;
+
+  AddValue(newAddend);
   return sr;
 }
 
 void
 ScalarUnsigned::AddValue(uint32_t aValue)
 {
-  mStorage += aValue;
+  for (auto& val: mStorage) {
+    val += aValue;
+  }
+  SetValueInStores();
 }
 
 ScalarResult
 ScalarUnsigned::SetMaximum(nsIVariant* aValue)
 {
   ScalarResult sr = CheckInput(aValue);
   if (sr == ScalarResult::UnsignedNegativeValue) {
     return sr;
   }
 
   uint32_t newValue = 0;
   nsresult rv = aValue->GetAsUint32(&newValue);
   if (NS_FAILED(rv)) {
     return ScalarResult::InvalidValue;
   }
-  if (newValue > mStorage) {
-    mStorage = newValue;
-  }
+
+  SetMaximum(newValue);
   return sr;
 }
 
 void
 ScalarUnsigned::SetMaximum(uint32_t aValue)
 {
-  if (aValue > mStorage) {
-    mStorage = aValue;
+  for (auto& val: mStorage) {
+    if (aValue > val) {
+      val = aValue;
+    }
   }
+  SetValueInStores();
 }
 
 nsresult
 ScalarUnsigned::GetValue(const nsACString& aStoreName, nsCOMPtr<nsIVariant>& aResult) const
 {
+  size_t storeIndex = 0;
+  nsresult rv = StoreIndex(aStoreName, &storeIndex);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  if (!HasValueInStore(storeIndex)) {
+    return NS_ERROR_NO_CONTENT;
+  }
   nsCOMPtr<nsIWritableVariant> outVar(new nsVariant());
-  nsresult rv = outVar->SetAsUint32(mStorage);
+  rv = outVar->SetAsUint32(mStorage[storeIndex]);
   if (NS_FAILED(rv)) {
     return rv;
   }
   aResult = outVar.forget();
   return NS_OK;
 }
 
 size_t
 ScalarUnsigned::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
-  return aMallocSizeOf(this);
+  size_t n = aMallocSizeOf(this);
+  n += ScalarBase::SizeOfExcludingThis(aMallocSizeOf);
+  n += mStorage.ShallowSizeOfExcludingThis(aMallocSizeOf);
+  return n;
 }
 
 ScalarResult
 ScalarUnsigned::CheckInput(nsIVariant* aValue)
 {
   // If this is a floating point value/double, we will probably get truncated.
   uint16_t type = aValue->GetDataType();
   if (type == nsIDataType::VTYPE_FLOAT ||