# Global Metrics

path: .metrics.cognitive.sum
old: 36.0
new: 6.0
path: .metrics.cognitive.average
old: null
new: 1.0
path: .metrics.nargs.sum
old: 0.0
new: 3.0
path: .metrics.nargs.average
old: null
new: 0.5
path: .metrics.cyclomatic.average
old: 2.8947368421052633
new: 1.4545454545454546
path: .metrics.cyclomatic.sum
old: 55.0
new: 16.0
path: .metrics.nexits.sum
old: 0.0
new: 3.0
path: .metrics.nexits.average
old: null
new: 0.5
path: .metrics.mi.mi_sei
old: -29.509388235226385
new: 34.25866506970071
path: .metrics.mi.mi_visual_studio
old: 1.268978424672195
new: 26.484609383282763
path: .metrics.mi.mi_original
old: 2.1699531061894533
new: 45.28868204541352
path: .metrics.halstead.volume
old: 16129.879753876166
new: 1543.5865269956753
path: .metrics.halstead.effort
old: 240304.10388143884
new: 23773.98892024589
path: .metrics.halstead.vocabulary
old: 379.0
new: 71.0
path: .metrics.halstead.N1
old: 1207.0
new: 136.0
path: .metrics.halstead.n1
old: 16.0
new: 15.0
path: .metrics.halstead.estimated_program_length
old: 3150.8887428924577
new: 383.8152345693536
path: .metrics.halstead.bugs
old: 1.28840639095166
new: 0.27560057284144757
path: .metrics.halstead.n2
old: 363.0
new: 56.0
path: .metrics.halstead.time
old: 13350.22799341327
new: 1320.7771622358828
path: .metrics.halstead.N2
old: 676.0
new: 115.0
path: .metrics.halstead.difficulty
old: 14.898071625344352
new: 15.401785714285714
path: .metrics.halstead.length
old: 1883.0
new: 251.0
path: .metrics.halstead.level
old: 0.06712278106508876
new: 0.06492753623188406
path: .metrics.halstead.purity_ratio
old: 1.6733344359492606
new: 1.529144360834078
path: .metrics.loc.ploc
old: 384.0
new: 74.0
path: .metrics.loc.blank
old: 97.0
new: 24.0
path: .metrics.loc.lloc
old: 1.0
new: 9.0
path: .metrics.loc.cloc
old: 205.0
new: 79.0
path: .metrics.loc.sloc
old: 686.0
new: 177.0
path: .metrics.nom.functions
old: 0.0
new: 6.0
path: .metrics.nom.total
old: 0.0
new: 6.0

# Spaces Data

## Minimal test - lines (25, 175)

path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 1.5
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 15.0
path: .spaces[0].metrics.halstead.bugs
old: 0.0
new: 0.26944027112815216
path: .spaces[0].metrics.halstead.length
old: 1.0
new: 240.0
path: .spaces[0].metrics.halstead.time
old: 0.0
new: 1276.7419763620323
path: .spaces[0].metrics.halstead.level
old: null
new: 0.06289308176100629
path: .spaces[0].metrics.halstead.purity_ratio
old: null
new: 1.4199840350952664
path: .spaces[0].metrics.halstead.n1
old: 0.0
new: 15.0
path: .spaces[0].metrics.halstead.volume
old: 0.0
new: 1445.368275126829
path: .spaces[0].metrics.halstead.estimated_program_length
old: null
new: 340.79616842286396
path: .spaces[0].metrics.halstead.n2
old: 1.0
new: 50.0
path: .spaces[0].metrics.halstead.difficulty
old: 0.0
new: 15.9
path: .spaces[0].metrics.halstead.N1
old: 0.0
new: 134.0
path: .spaces[0].metrics.halstead.effort
old: 0.0
new: 22981.355574516583
path: .spaces[0].metrics.halstead.N2
old: 1.0
new: 106.0
path: .spaces[0].metrics.halstead.vocabulary
old: 1.0
new: 65.0
path: .spaces[0].metrics.loc.blank
old: 0.0
new: 20.0
path: .spaces[0].metrics.loc.sloc
old: 1.0
new: 151.0
path: .spaces[0].metrics.loc.ploc
old: 1.0
new: 59.0
path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 72.0
path: .spaces[0].metrics.loc.lloc
old: 0.0
new: 9.0
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 6.0
path: .spaces[0].metrics.nom.total
old: 0.0
new: 6.0
path: .spaces[0].metrics.mi.mi_original
old: null
new: 48.434245608876
path: .spaces[0].metrics.mi.mi_sei
old: null
new: 39.55637922907813
path: .spaces[0].metrics.mi.mi_visual_studio
old: null
new: 28.324120239108773
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 3.0
path: .spaces[0].metrics.nargs.average
old: null
new: 0.5
path: .spaces[0].metrics.cognitive.average
old: null
new: 1.0
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 6.0
path: .spaces[0].metrics.nexits.average
old: null
new: 0.5
path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 3.0

### Code

    namespace mozilla {

    #if defined(XP_WIN)
    typedef void* filedesc_t;
    typedef const wchar_t* pathstr_t;
    #else
    typedef int filedesc_t;
    typedef const char* pathstr_t;
    #endif

    /**
     * ScopedCloseFD is a RAII wrapper for POSIX file descriptors
     *
     * Instances |close()| their fds when they go out of scope.
     */
    struct ScopedCloseFDTraits {
      typedef int type;
      static type empty() { return -1; }
      static void release(type aFd) {
        if (aFd != -1) {
          while (close(aFd) == -1 && errno == EINTR) {
          }
        }
      }
    };
    typedef Scoped ScopedClose;

    #if defined(MOZILLA_INTERNAL_API)

    /**
     * AutoFDClose is a RAII wrapper for PRFileDesc.
     *
     * Instances |PR_Close| their fds when they go out of scope.
     **/
    struct ScopedClosePRFDTraits {
      typedef PRFileDesc* type;
      static type empty() { return nullptr; }
      static void release(type aFd) {
        if (aFd) {
          PR_Close(aFd);
        }
      }
    };
    typedef Scoped AutoFDClose;

    /* RAII wrapper for FILE descriptors */
    struct ScopedCloseFileTraits {
      typedef FILE* type;
      static type empty() { return nullptr; }
      static void release(type aFile) {
        if (aFile) {
          fclose(aFile);
        }
      }
    };
    typedef Scoped ScopedCloseFile;

    /**
     * Fallocate efficiently and continuously allocates files via fallocate-type
     * APIs. This is useful for avoiding fragmentation. On sucess the file be padded
     * with zeros to grow to aLength.
     *
     * @param aFD file descriptor.
     * @param aLength length of file to grow to.
     * @return true on success.
     */
    bool fallocate(PRFileDesc* aFD, int64_t aLength);

    /**
     * Use readahead to preload shared libraries into the file cache before loading.
     * WARNING: This function should not be used without a telemetry field trial
     *          demonstrating a clear performance improvement!
     *
     * @param aFile nsIFile representing path to shared library
     */
    void ReadAheadLib(nsIFile* aFile);

    /**
     * Use readahead to preload a file into the file cache before reading.
     * WARNING: This function should not be used without a telemetry field trial
     *          demonstrating a clear performance improvement!
     *
     * @param aFile nsIFile representing path to shared library
     * @param aOffset Offset into the file to begin preloading
     * @param aCount Number of bytes to preload (SIZE_MAX implies file size)
     * @param aOutFd Pointer to file descriptor. If specified, ReadAheadFile will
     *        return its internal, opened file descriptor instead of closing it.
     */
    void ReadAheadFile(nsIFile* aFile, const size_t aOffset = 0,
                       const size_t aCount = SIZE_MAX,
                       filedesc_t* aOutFd = nullptr);

    /*
     * Wrappers for PR_GetLibraryName and PR_GetLibraryFilePathname.
     */
    PathString GetLibraryName(pathstr_t aDirectory, const char* aLib);
    PathString GetLibraryFilePathname(pathstr_t aName, PRFuncPtr aAddr);

    #endif  // MOZILLA_INTERNAL_API

    /**
     * Use readahead to preload shared libraries into the file cache before loading.
     * WARNING: This function should not be used without a telemetry field trial
     *          demonstrating a clear performance improvement!
     *
     * @param aFilePath path to shared library
     */
    void ReadAheadLib(pathstr_t aFilePath);

    /**
     * Use readahead to preload a file into the file cache before loading.
     * WARNING: This function should not be used without a telemetry field trial
     *          demonstrating a clear performance improvement!
     *
     * @param aFilePath path to shared library
     * @param aOffset Offset into the file to begin preloading
     * @param aCount Number of bytes to preload (SIZE_MAX implies file size)
     * @param aOutFd Pointer to file descriptor. If specified, ReadAheadFile will
     *        return its internal, opened file descriptor instead of closing it.
     */
    void ReadAheadFile(pathstr_t aFilePath, const size_t aOffset = 0,
                       const size_t aCount = SIZE_MAX,
                       filedesc_t* aOutFd = nullptr);

    /**
     * Use readahead to preload a file into the file cache before reading.
     * When this function exits, the file pointer is guaranteed to be in the same
     * position it was in before this function was called.
     * WARNING: This function should not be used without a telemetry field trial
     *          demonstrating a clear performance improvement!
     *
     * @param aFd file descriptor opened for read access
     * (on Windows, file must be opened with FILE_FLAG_SEQUENTIAL_SCAN)
     * @param aOffset Offset into the file to begin preloading
     * @param aCount Number of bytes to preload (SIZE_MAX implies file size)
     */
    void ReadAhead(filedesc_t aFd, const size_t aOffset = 0,
                   const size_t aCount = SIZE_MAX);

    #if defined(XP_UNIX)
    #  define MOZ_TEMP_FAILURE_RETRY(exp)        \
        (__extension__({                         \
          typeof(exp) _rc;                       \
          do {                                   \
            _rc = (exp);                         \
          } while (_rc == -1 && errno == EINTR); \
          _rc;                                   \
        }))
    #endif

    }  // namespace mozilla