# Global Metrics

path: .metrics.nexits.average
old: null
new: 1.411764705882353
path: .metrics.nexits.sum
old: 0.0
new: 24.0
path: .metrics.nom.functions
old: 0.0
new: 17.0
path: .metrics.nom.total
old: 0.0
new: 17.0
path: .metrics.nargs.average
old: null
new: 1.588235294117647
path: .metrics.nargs.sum
old: 0.0
new: 27.0
path: .metrics.loc.ploc
old: 31.0
new: 269.0
path: .metrics.loc.sloc
old: 63.0
new: 360.0
path: .metrics.loc.blank
old: 10.0
new: 61.0
path: .metrics.loc.lloc
old: 0.0
new: 94.0
path: .metrics.loc.cloc
old: 22.0
new: 30.0
path: .metrics.halstead.volume
old: 433.9617123740648
new: 9567.922322345832
path: .metrics.halstead.n1
old: 9.0
new: 31.0
path: .metrics.halstead.length
old: 81.0
new: 1202.0
path: .metrics.halstead.vocabulary
old: 41.0
new: 249.0
path: .metrics.halstead.bugs
old: 0.05941979052208534
new: 1.6199198881127927
path: .metrics.halstead.N1
old: 42.0
new: 704.0
path: .metrics.halstead.estimated_program_length
old: 188.5293250129808
new: 1847.044268423363
path: .metrics.halstead.purity_ratio
old: 2.3275225310244547
new: 1.5366424862091206
path: .metrics.halstead.effort
old: 2380.0087663015115
new: 338783.4514045297
path: .metrics.halstead.level
old: 0.18233618233618237
new: 0.02824200025910092
path: .metrics.halstead.n2
old: 32.0
new: 218.0
path: .metrics.halstead.N2
old: 39.0
new: 498.0
path: .metrics.halstead.difficulty
old: 5.484375
new: 35.408256880733944
path: .metrics.halstead.time
old: 132.22270923897287
new: 18821.302855807204
path: .metrics.cyclomatic.average
old: 1.0
new: 2.6666666666666665
path: .metrics.cyclomatic.sum
old: 8.0
new: 56.0
path: .metrics.cognitive.average
old: null
new: 2.4705882352941178
path: .metrics.cognitive.sum
old: 0.0
new: 42.0
path: .metrics.mi.mi_sei
old: 66.41128077785477
new: -26.590026013448337
path: .metrics.mi.mi_visual_studio
old: 41.20575708837435
new: 8.831007971114092
path: .metrics.mi.mi_original
old: 70.46184462112014
new: 15.101023630605098

# Spaces Data

## Minimal test - lines (139, 139)

path: .spaces[2].metrics.cognitive.average
old: null
new: 0.0
path: .spaces[2].metrics.halstead.bugs
old: 0.05154748076954636
new: 0.006240251469155711
path: .spaces[2].metrics.halstead.level
old: 0.18518518518518515
new: 0.3333333333333333
path: .spaces[2].metrics.halstead.length
old: 70.0
new: 9.0
path: .spaces[2].metrics.halstead.purity_ratio
old: 2.066081853676413
new: 1.9455305560363263
path: .spaces[2].metrics.halstead.effort
old: 1923.0609539926284
new: 81.0
path: .spaces[2].metrics.halstead.difficulty
old: 5.4
new: 3.0
path: .spaces[2].metrics.halstead.vocabulary
old: 34.0
new: 8.0
path: .spaces[2].metrics.halstead.N2
old: 30.0
new: 2.0
path: .spaces[2].metrics.halstead.estimated_program_length
old: 144.62572975734892
new: 17.509775004326936
path: .spaces[2].metrics.halstead.volume
old: 356.12239888752373
new: 27.0
path: .spaces[2].metrics.halstead.n1
old: 9.0
new: 6.0
path: .spaces[2].metrics.halstead.n2
old: 25.0
new: 2.0
path: .spaces[2].metrics.halstead.time
old: 106.83671966625712
new: 4.5
path: .spaces[2].metrics.halstead.N1
old: 40.0
new: 7.0
path: .spaces[2].metrics.loc.cloc
old: 16.0
new: 0.0
path: .spaces[2].metrics.loc.blank
old: 6.0
new: 0.0
path: .spaces[2].metrics.loc.lloc
old: 0.0
new: 1.0
path: .spaces[2].metrics.loc.ploc
old: 21.0
new: 1.0
path: .spaces[2].metrics.loc.sloc
old: 43.0
new: 1.0
path: .spaces[2].metrics.nargs.sum
old: 0.0
new: 1.0
path: .spaces[2].metrics.nargs.average
old: null
new: 1.0
path: .spaces[2].metrics.nom.total
old: 0.0
new: 1.0
path: .spaces[2].metrics.nom.functions
old: 0.0
new: 1.0
path: .spaces[2].metrics.cyclomatic.sum
old: 5.0
new: 1.0
path: .spaces[2].metrics.mi.mi_original
old: 78.36713078369092
new: 153.6316482967775
path: .spaces[2].metrics.mi.mi_sei
old: 78.39293791706353
new: 146.04458498874996
path: .spaces[2].metrics.mi.mi_visual_studio
old: 45.82873145245083
new: 89.84306917940205
path: .spaces[2].metrics.nexits.average
old: null
new: 0.0

### Code

    nsObserverService::~nsObserverService(void) { Shutdown(); }

## Minimal test - lines (137, 137)

path: .spaces[1].metrics.halstead.difficulty
old: 0.0
new: 2.0
path: .spaces[1].metrics.halstead.time
old: 0.0
new: 2.495426597384537
path: .spaces[1].metrics.halstead.n1
old: 0.0
new: 4.0
path: .spaces[1].metrics.halstead.N2
old: 1.0
new: 3.0
path: .spaces[1].metrics.halstead.estimated_program_length
old: null
new: 12.754887502163468
path: .spaces[1].metrics.halstead.length
old: 1.0
new: 8.0
path: .spaces[1].metrics.halstead.N1
old: 0.0
new: 5.0
path: .spaces[1].metrics.halstead.effort
old: 0.0
new: 44.91767875292167
path: .spaces[1].metrics.halstead.level
old: null
new: 0.5
path: .spaces[1].metrics.halstead.volume
old: 0.0
new: 22.458839376460833
path: .spaces[1].metrics.halstead.bugs
old: 0.0
new: 0.00421201861424495
path: .spaces[1].metrics.halstead.purity_ratio
old: null
new: 1.5943609377704335
path: .spaces[1].metrics.halstead.n2
old: 1.0
new: 3.0
path: .spaces[1].metrics.halstead.vocabulary
old: 1.0
new: 7.0
path: .spaces[1].metrics.mi.mi_original
old: null
new: 154.58924178123317
path: .spaces[1].metrics.mi.mi_sei
old: null
new: 147.42610035996177
path: .spaces[1].metrics.mi.mi_visual_studio
old: null
new: 90.4030653691422
path: .spaces[1].metrics.nexits.average
old: null
new: 0.0
path: .spaces[1].metrics.cognitive.average
old: null
new: 0.0
path: .spaces[1].metrics.nom.total
old: 0.0
new: 1.0
path: .spaces[1].metrics.nom.functions
old: 0.0
new: 1.0
path: .spaces[1].metrics.nargs.average
old: null
new: 0.0

### Code

    nsObserverService::nsObserverService() : mShuttingDown(false) {}

## Minimal test - lines (45, 129)

path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 17.0
path: .spaces[0].metrics.cognitive.average
old: null
new: 8.5
path: .spaces[0].metrics.mi.mi_original
old: null
new: 56.955261626451104
path: .spaces[0].metrics.mi.mi_visual_studio
old: null
new: 33.30717054178427
path: .spaces[0].metrics.mi.mi_sei
old: null
new: 23.97526391221701
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 5.0
path: .spaces[0].metrics.nargs.average
old: null
new: 2.5
path: .spaces[0].metrics.nom.total
old: 0.0
new: 2.0
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 2.0
path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 4.0
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 10.0
path: .spaces[0].metrics.loc.ploc
old: 1.0
new: 71.0
path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 20.0
path: .spaces[0].metrics.loc.sloc
old: 1.0
new: 85.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 3.3333333333333335
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 10.0
path: .spaces[0].metrics.halstead.bugs
old: 0.0
new: 0.4730053409772802
path: .spaces[0].metrics.halstead.vocabulary
old: 1.0
new: 89.0
path: .spaces[0].metrics.halstead.effort
old: 0.0
new: 53454.091045914385
path: .spaces[0].metrics.halstead.estimated_program_length
old: null
new: 501.4930078641573
path: .spaces[0].metrics.halstead.difficulty
old: 0.0
new: 25.476923076923075
path: .spaces[0].metrics.halstead.n2
old: 1.0
new: 65.0
path: .spaces[0].metrics.halstead.volume
old: 0.0
new: 2098.137631633113
path: .spaces[0].metrics.halstead.level
old: null
new: 0.0392512077294686
path: .spaces[0].metrics.halstead.n1
old: 0.0
new: 24.0
path: .spaces[0].metrics.halstead.N2
old: 1.0
new: 138.0
path: .spaces[0].metrics.halstead.time
old: 0.0
new: 2969.671724773021
path: .spaces[0].metrics.halstead.N1
old: 0.0
new: 186.0
path: .spaces[0].metrics.halstead.length
old: 1.0
new: 324.0
path: .spaces[0].metrics.halstead.purity_ratio
old: null
new: 1.5478179255066582
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 1.0
path: .spaces[0].metrics.nexits.average
old: null
new: 0.5

### Code

    nsObserverService::CollectReports(nsIHandleReportCallback* aHandleReport,
                                      nsISupports* aData, bool aAnonymize) {
      struct SuspectObserver {
        SuspectObserver(const char* aTopic, size_t aReferentCount)
            : mTopic(aTopic), mReferentCount(aReferentCount) {}
        const char* mTopic;
        size_t mReferentCount;
      };

      size_t totalNumStrong = 0;
      size_t totalNumWeakAlive = 0;
      size_t totalNumWeakDead = 0;
      nsTArray suspectObservers;

      for (auto iter = mObserverTopicTable.Iter(); !iter.Done(); iter.Next()) {
        nsObserverList* observerList = iter.Get();
        if (!observerList) {
          continue;
        }

        size_t topicNumStrong = 0;
        size_t topicNumWeakAlive = 0;
        size_t topicNumWeakDead = 0;

        nsMaybeWeakPtrArray& observers = observerList->mObservers;
        for (uint32_t i = 0; i < observers.Length(); i++) {
          if (observers[i].IsWeak()) {
            nsCOMPtr ref = observers[i].GetValue();
            if (ref) {
              topicNumWeakAlive++;
            } else {
              topicNumWeakDead++;
            }
          } else {
            topicNumStrong++;
          }
        }

        totalNumStrong += topicNumStrong;
        totalNumWeakAlive += topicNumWeakAlive;
        totalNumWeakDead += topicNumWeakDead;

        // Keep track of topics that have a suspiciously large number
        // of referents (symptom of leaks).
        size_t topicTotal = topicNumStrong + topicNumWeakAlive + topicNumWeakDead;
        if (topicTotal > kSuspectReferentCount) {
          SuspectObserver suspect(observerList->GetKey(), topicTotal);
          suspectObservers.AppendElement(suspect);
        }
      }

      // These aren't privacy-sensitive and so don't need anonymizing.
      for (uint32_t i = 0; i < suspectObservers.Length(); i++) {
        SuspectObserver& suspect = suspectObservers[i];
        nsPrintfCString suspectPath("observer-service-suspect/referent(topic=%s)",
                                    suspect.mTopic);
        aHandleReport->Callback(
            /* process */ ""_ns, suspectPath, KIND_OTHER, UNITS_COUNT,
            suspect.mReferentCount,
            nsLiteralCString("A topic with a suspiciously large number of "
                             "referents.  This may be symptomatic of a leak "
                             "if the number of referents is high with "
                             "respect to the number of windows."),
            aData);
      }

      MOZ_COLLECT_REPORT(
          "observer-service/referent/strong", KIND_OTHER, UNITS_COUNT,
          totalNumStrong,
          "The number of strong references held by the observer service.");

      MOZ_COLLECT_REPORT(
          "observer-service/referent/weak/alive", KIND_OTHER, UNITS_COUNT,
          totalNumWeakAlive,
          "The number of weak references held by the observer service that are "
          "still alive.");

      MOZ_COLLECT_REPORT(
          "observer-service/referent/weak/dead", KIND_OTHER, UNITS_COUNT,
          totalNumWeakDead,
          "The number of weak references held by the observer service that are "
          "dead.");

      return NS_OK;
    }