# Global Metrics

path: .metrics.cyclomatic.sum
old: 4.0
new: 22.0
path: .metrics.cyclomatic.average
old: 1.0
new: 1.8333333333333333
path: .metrics.loc.sloc
old: 57.0
new: 101.0
path: .metrics.loc.blank
old: 15.0
new: 17.0
path: .metrics.loc.cloc
old: 8.0
new: 15.0
path: .metrics.loc.lloc
old: 0.0
new: 18.0
path: .metrics.loc.ploc
old: 34.0
new: 69.0
path: .metrics.nexits.sum
old: 0.0
new: 4.0
path: .metrics.nexits.average
old: null
new: 0.5
path: .metrics.nargs.sum
old: 0.0
new: 15.0
path: .metrics.nargs.average
old: null
new: 1.875
path: .metrics.halstead.n1
old: 12.0
new: 21.0
path: .metrics.halstead.volume
old: 758.2757018414163
new: 1903.0682289169915
path: .metrics.halstead.length
old: 130.0
new: 316.0
path: .metrics.halstead.time
old: 325.77770893927516
new: 2850.9980474873864
path: .metrics.halstead.vocabulary
old: 57.0
new: 65.0
path: .metrics.halstead.bugs
old: 0.10839468605518446
new: 0.4603184285468408
path: .metrics.halstead.N1
old: 72.0
new: 203.0
path: .metrics.halstead.N2
old: 58.0
new: 113.0
path: .metrics.halstead.effort
old: 5863.998760906953
new: 51317.96485477296
path: .metrics.halstead.n2
old: 45.0
new: 44.0
path: .metrics.halstead.estimated_program_length
old: 290.1529393434892
new: 332.45365709839507
path: .metrics.halstead.purity_ratio
old: 2.231945687257609
new: 1.0520685351215031
path: .metrics.halstead.difficulty
old: 7.733333333333333
new: 26.96590909090909
path: .metrics.halstead.level
old: 0.12931034482758622
new: 0.03708386009270965
path: .metrics.mi.mi_original
old: 70.10112484134275
new: 51.90868948317576
path: .metrics.mi.mi_visual_studio
old: 40.99480984873845
new: 30.355958762091092
path: .metrics.mi.mi_sei
old: 53.258102082524815
new: 29.536712990988608
path: .metrics.cognitive.sum
old: 0.0
new: 9.0
path: .metrics.cognitive.average
old: null
new: 1.125
path: .metrics.nom.total
old: 0.0
new: 8.0
path: .metrics.nom.functions
old: 0.0
new: 8.0

# Spaces Data

## Minimal test - lines (17, 99)

path: .spaces[0].metrics.nexits.average
old: null
new: 0.5
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 4.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.9090909090909092
path: .spaces[0].metrics.cyclomatic.sum
old: 3.0
new: 21.0
path: .spaces[0].metrics.loc.cloc
old: 1.0
new: 8.0
path: .spaces[0].metrics.loc.ploc
old: 28.0
new: 62.0
path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 18.0
path: .spaces[0].metrics.loc.sloc
old: 42.0
new: 83.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 2.1014334575839624
new: 0.9810797095622136
path: .spaces[0].metrics.halstead.volume
old: 715.9900568203999
new: 1844.4593119820577
path: .spaces[0].metrics.halstead.bugs
old: 0.10453111467892603
new: 0.4661154591752633
path: .spaces[0].metrics.halstead.level
old: 0.1289308176100629
new: 0.03527336860670194
path: .spaces[0].metrics.halstead.time
old: 308.5160407437495
new: 2905.023416371741
path: .spaces[0].metrics.halstead.N1
old: 72.0
new: 203.0
path: .spaces[0].metrics.halstead.effort
old: 5553.288733387491
new: 52290.421494691334
path: .spaces[0].metrics.halstead.estimated_program_length
old: 262.6791821979953
new: 305.11578967384844
path: .spaces[0].metrics.halstead.vocabulary
old: 53.0
new: 61.0
path: .spaces[0].metrics.halstead.n1
old: 12.0
new: 21.0
path: .spaces[0].metrics.halstead.n2
old: 41.0
new: 40.0
path: .spaces[0].metrics.halstead.N2
old: 53.0
new: 108.0
path: .spaces[0].metrics.halstead.difficulty
old: 7.7560975609756095
new: 28.35
path: .spaces[0].metrics.halstead.length
old: 125.0
new: 311.0
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 9.0
path: .spaces[0].metrics.cognitive.average
old: null
new: 1.125
path: .spaces[0].metrics.nargs.average
old: null
new: 1.875
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 15.0
path: .spaces[0].metrics.mi.mi_original
old: 75.57668752915168
new: 55.481086573711835
path: .spaces[0].metrics.mi.mi_sei
old: 45.47749947867216
new: 29.61130549625927
path: .spaces[0].metrics.mi.mi_visual_studio
old: 44.196893291901574
new: 32.445079867667744
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 8.0
path: .spaces[0].metrics.nom.total
old: 0.0
new: 8.0

### Code

    namespace mozilla {
    namespace widget {

    class GeckoTelemetryDelegate final
        : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate,
          public mozilla::java::RuntimeTelemetry::Proxy::Natives<
              GeckoTelemetryDelegate> {
     public:
      // Implement Proxy native.
      static void RegisterDelegateProxy(
          mozilla::java::RuntimeTelemetry::Proxy::Param aProxy) {
        MOZ_ASSERT(aProxy);

        GeckoViewStreamingTelemetry::RegisterDelegate(
            new GeckoTelemetryDelegate(aProxy));
      }

      explicit GeckoTelemetryDelegate(
          mozilla::java::RuntimeTelemetry::Proxy::Param aProxy)
          : mProxy(aProxy) {}

     private:
      void DispatchHistogram(bool aIsCategorical, const nsCString& aName,
                             const nsTArray& aSamples) {
        if (!mozilla::jni::IsAvailable() || !mProxy || aSamples.Length() < 1) {
          return;
        }

        // Convert aSamples to an array of int64_t. We know |samples| required
        // capacity needs to match |aSamples.Length()|.
        nsTArray samples(aSamples.Length());
        for (size_t i = 0, l = aSamples.Length(); i < l; ++i) {
          samples.AppendElement(static_cast(aSamples[i]));
        }

        // LongArray::New *copies* the elements
        mProxy->DispatchHistogram(
            aIsCategorical, aName,
            mozilla::jni::LongArray::New(samples.Elements(), samples.Length()));
      }

      // Implement StreamingTelemetryDelegate.
      void ReceiveHistogramSamples(const nsCString& aName,
                                   const nsTArray& aSamples) override {
        DispatchHistogram(/* isCategorical */ false, aName, aSamples);
      }

      void ReceiveCategoricalHistogramSamples(
          const nsCString& aName, const nsTArray& aSamples) override {
        DispatchHistogram(/* isCategorical */ true, aName, aSamples);
      }

      void ReceiveBoolScalarValue(const nsCString& aName, bool aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchBooleanScalar(aName, aValue);
      }

      void ReceiveStringScalarValue(const nsCString& aName,
                                    const nsCString& aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchStringScalar(aName, aValue);
      }

      void ReceiveUintScalarValue(const nsCString& aName,
                                  uint32_t aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchLongScalar(aName, static_cast(aValue));
      }

      mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy;
    };

    }  // namespace widget
    }  // namespace mozilla

## Minimal test - lines (18, 98)

path: .spaces[0].spaces[0].metrics.halstead.volume
old: 701.1540853313543
new: 1825.2291940430323
path: .spaces[0].spaces[0].metrics.halstead.vocabulary
old: 52.0
new: 60.0
path: .spaces[0].spaces[0].metrics.halstead.n1
old: 12.0
new: 21.0
path: .spaces[0].spaces[0].metrics.halstead.time
old: 303.8334369769202
new: 2921.1467229449386
path: .spaces[0].spaces[0].metrics.halstead.effort
old: 5469.001865584563
new: 52580.64101300889
path: .spaces[0].spaces[0].metrics.halstead.N2
old: 52.0
new: 107.0
path: .spaces[0].spaces[0].metrics.halstead.length
old: 123.0
new: 309.0
path: .spaces[0].spaces[0].metrics.halstead.level
old: 0.12820512820512822
new: 0.03471295060080107
path: .spaces[0].spaces[0].metrics.halstead.bugs
old: 0.1034707172592252
new: 0.4678385405660071
path: .spaces[0].spaces[0].metrics.halstead.N1
old: 71.0
new: 202.0
path: .spaces[0].spaces[0].metrics.halstead.difficulty
old: 7.8
new: 28.807692307692307
path: .spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 255.8966738041484
new: 298.3693524139817
path: .spaces[0].spaces[0].metrics.halstead.n2
old: 40.0
new: 39.0
path: .spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 2.0804607626353526
new: 0.965596609753986
path: .spaces[0].spaces[0].metrics.loc.cloc
old: 0.0
new: 7.0
path: .spaces[0].spaces[0].metrics.loc.ploc
old: 26.0
new: 60.0
path: .spaces[0].spaces[0].metrics.loc.lloc
old: 0.0
new: 18.0
path: .spaces[0].spaces[0].metrics.loc.sloc
old: 40.0
new: 81.0
path: .spaces[0].spaces[0].metrics.mi.mi_sei
old: 35.16610874525496
new: 29.35032673508155
path: .spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 44.85729178675137
new: 32.84253058829416
path: .spaces[0].spaces[0].metrics.mi.mi_original
old: 76.70596895534483
new: 56.160727305983016
path: .spaces[0].spaces[0].metrics.nom.functions
old: 0.0
new: 8.0
path: .spaces[0].spaces[0].metrics.nom.total
old: 0.0
new: 8.0
path: .spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .spaces[0].spaces[0].metrics.cyclomatic.sum
old: 2.0
new: 20.0
path: .spaces[0].spaces[0].metrics.nargs.average
old: null
new: 1.875
path: .spaces[0].spaces[0].metrics.nargs.sum
old: 0.0
new: 15.0
path: .spaces[0].spaces[0].metrics.nexits.sum
old: 0.0
new: 4.0
path: .spaces[0].spaces[0].metrics.nexits.average
old: null
new: 0.5
path: .spaces[0].spaces[0].metrics.cognitive.sum
old: 0.0
new: 9.0
path: .spaces[0].spaces[0].metrics.cognitive.average
old: null
new: 1.125

### Code

    namespace widget {

    class GeckoTelemetryDelegate final
        : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate,
          public mozilla::java::RuntimeTelemetry::Proxy::Natives<
              GeckoTelemetryDelegate> {
     public:
      // Implement Proxy native.
      static void RegisterDelegateProxy(
          mozilla::java::RuntimeTelemetry::Proxy::Param aProxy) {
        MOZ_ASSERT(aProxy);

        GeckoViewStreamingTelemetry::RegisterDelegate(
            new GeckoTelemetryDelegate(aProxy));
      }

      explicit GeckoTelemetryDelegate(
          mozilla::java::RuntimeTelemetry::Proxy::Param aProxy)
          : mProxy(aProxy) {}

     private:
      void DispatchHistogram(bool aIsCategorical, const nsCString& aName,
                             const nsTArray& aSamples) {
        if (!mozilla::jni::IsAvailable() || !mProxy || aSamples.Length() < 1) {
          return;
        }

        // Convert aSamples to an array of int64_t. We know |samples| required
        // capacity needs to match |aSamples.Length()|.
        nsTArray samples(aSamples.Length());
        for (size_t i = 0, l = aSamples.Length(); i < l; ++i) {
          samples.AppendElement(static_cast(aSamples[i]));
        }

        // LongArray::New *copies* the elements
        mProxy->DispatchHistogram(
            aIsCategorical, aName,
            mozilla::jni::LongArray::New(samples.Elements(), samples.Length()));
      }

      // Implement StreamingTelemetryDelegate.
      void ReceiveHistogramSamples(const nsCString& aName,
                                   const nsTArray& aSamples) override {
        DispatchHistogram(/* isCategorical */ false, aName, aSamples);
      }

      void ReceiveCategoricalHistogramSamples(
          const nsCString& aName, const nsTArray& aSamples) override {
        DispatchHistogram(/* isCategorical */ true, aName, aSamples);
      }

      void ReceiveBoolScalarValue(const nsCString& aName, bool aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchBooleanScalar(aName, aValue);
      }

      void ReceiveStringScalarValue(const nsCString& aName,
                                    const nsCString& aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchStringScalar(aName, aValue);
      }

      void ReceiveUintScalarValue(const nsCString& aName,
                                  uint32_t aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchLongScalar(aName, static_cast(aValue));
      }

      mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy;
    };

    }  // namespace widget

## Minimal test - lines (20, 96)

path: .spaces[0].spaces[0].spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 19.0
path: .spaces[0].spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.0
new: 2.111111111111111
path: .spaces[0].spaces[0].spaces[0].metrics.nexits.average
old: null
new: 0.5
path: .spaces[0].spaces[0].spaces[0].metrics.nexits.sum
old: 0.0
new: 4.0
path: .spaces[0].spaces[0].spaces[0].metrics.nom.total
old: 0.0
new: 8.0
path: .spaces[0].spaces[0].spaces[0].metrics.nom.functions
old: 0.0
new: 8.0
path: .spaces[0].spaces[0].spaces[0].metrics.nargs.sum
old: 0.0
new: 15.0
path: .spaces[0].spaces[0].spaces[0].metrics.nargs.average
old: null
new: 1.875
path: .spaces[0].spaces[0].spaces[0].metrics.loc.cloc
old: 0.0
new: 7.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.lloc
old: 0.0
new: 18.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.sloc
old: 36.0
new: 77.0
path: .spaces[0].spaces[0].spaces[0].metrics.loc.ploc
old: 24.0
new: 58.0
path: .spaces[0].spaces[0].spaces[0].metrics.cognitive.average
old: null
new: 1.125
path: .spaces[0].spaces[0].spaces[0].metrics.cognitive.sum
old: 0.0
new: 9.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.volume
old: 680.6910410365795
new: 1800.0887731047235
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n2
old: 39.0
new: 38.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.level
old: 0.12745098039215688
new: 0.034141958670260555
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.difficulty
old: 7.846153846153846
new: 29.289473684210527
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.effort
old: 5340.806629671623
new: 52723.65274909361
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N1
old: 69.0
new: 200.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 249.15023654428157
new: 291.6599113892102
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 2.0762519712023466
new: 0.9531369653242164
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.time
old: 296.7114794262013
new: 2929.0918193940897
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.length
old: 120.0
new: 306.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.N2
old: 51.0
new: 106.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.bugs
old: 0.10184740813930444
new: 0.4686864585819811
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.n1
old: 12.0
new: 21.0
path: .spaces[0].spaces[0].spaces[0].metrics.halstead.vocabulary
old: 51.0
new: 59.0
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_original
old: 78.79682889836918
new: 57.28327760846011
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_sei
old: 38.0807621568451
new: 31.390939415307265
path: .spaces[0].spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 46.080016899631104
new: 33.498992753485446

### Code

    class GeckoTelemetryDelegate final
        : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate,
          public mozilla::java::RuntimeTelemetry::Proxy::Natives<
              GeckoTelemetryDelegate> {
     public:
      // Implement Proxy native.
      static void RegisterDelegateProxy(
          mozilla::java::RuntimeTelemetry::Proxy::Param aProxy) {
        MOZ_ASSERT(aProxy);

        GeckoViewStreamingTelemetry::RegisterDelegate(
            new GeckoTelemetryDelegate(aProxy));
      }

      explicit GeckoTelemetryDelegate(
          mozilla::java::RuntimeTelemetry::Proxy::Param aProxy)
          : mProxy(aProxy) {}

     private:
      void DispatchHistogram(bool aIsCategorical, const nsCString& aName,
                             const nsTArray& aSamples) {
        if (!mozilla::jni::IsAvailable() || !mProxy || aSamples.Length() < 1) {
          return;
        }

        // Convert aSamples to an array of int64_t. We know |samples| required
        // capacity needs to match |aSamples.Length()|.
        nsTArray samples(aSamples.Length());
        for (size_t i = 0, l = aSamples.Length(); i < l; ++i) {
          samples.AppendElement(static_cast(aSamples[i]));
        }

        // LongArray::New *copies* the elements
        mProxy->DispatchHistogram(
            aIsCategorical, aName,
            mozilla::jni::LongArray::New(samples.Elements(), samples.Length()));
      }

      // Implement StreamingTelemetryDelegate.
      void ReceiveHistogramSamples(const nsCString& aName,
                                   const nsTArray& aSamples) override {
        DispatchHistogram(/* isCategorical */ false, aName, aSamples);
      }

      void ReceiveCategoricalHistogramSamples(
          const nsCString& aName, const nsTArray& aSamples) override {
        DispatchHistogram(/* isCategorical */ true, aName, aSamples);
      }

      void ReceiveBoolScalarValue(const nsCString& aName, bool aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchBooleanScalar(aName, aValue);
      }

      void ReceiveStringScalarValue(const nsCString& aName,
                                    const nsCString& aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchStringScalar(aName, aValue);
      }

      void ReceiveUintScalarValue(const nsCString& aName,
                                  uint32_t aValue) override {
        if (!mozilla::jni::IsAvailable() || !mProxy) {
          return;
        }

        mProxy->DispatchLongScalar(aName, static_cast(aValue));
      }

      mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy;
    };