void Dump(int i, FILE* out, nsTraceRefcntImpl::StatisticsType type) {
    nsTraceRefcntStats* stats = (type == nsTraceRefcntImpl::NEW_STATS) ? &mNewStats : &mAllStats;
    if (gLogLeaksOnly && !HaveLeaks(stats)) {
      return;
    }

    double meanRefs, stddevRefs;
    NS_MeanAndStdDev(stats->mAddRefs + stats->mReleases,
                     stats->mRefsOutstandingTotal,
                     stats->mRefsOutstandingSquared,
                     &meanRefs, &stddevRefs);

    double meanObjs, stddevObjs;
    NS_MeanAndStdDev(stats->mCreates + stats->mDestroys,
                     stats->mObjsOutstandingTotal,
                     stats->mObjsOutstandingSquared,
                     &meanObjs, &stddevObjs);

    if ((stats->mAddRefs - stats->mReleases) != 0 ||
        stats->mAddRefs != 0 ||
        meanRefs != 0 ||
        stddevRefs != 0 ||
        (stats->mCreates - stats->mDestroys) != 0 ||
        stats->mCreates != 0 ||
        meanObjs != 0 ||
        stddevObjs != 0) {
      fprintf(out, "%4d %-40.40s %8d %8llu %8llu %8llu (%8.2f +/- %8.2f) %8llu %8llu (%8.2f +/- %8.2f)\n",
              i+1, mClassName,
              (int32_t)mClassSize,
              (nsCRT::strcmp(mClassName, "TOTAL"))
                  ?(uint64_t)((stats->mCreates - stats->mDestroys) * mClassSize)
                  :mTotalLeaked,
              stats->mCreates,
              (stats->mCreates - stats->mDestroys),
              meanObjs,
              stddevObjs,
              stats->mAddRefs,
              (stats->mAddRefs - stats->mReleases),
              meanRefs,
              stddevRefs);
    }
  }
示例#2
0
int
Test(const char* filename, int32_t minSize, int32_t maxSize, 
     int32_t sizeIncrement, int32_t iterations)
{
    fprintf(stdout, "      size  write:    mean     stddev      iters  total:    mean     stddev      iters\n");
    for (int32_t size = minSize; size <= maxSize; size += sizeIncrement) {
        // create a buffer of stuff to write
        char* buf = (char*)PR_Malloc(size);
        if (buf == nullptr)
            return -1;

        // initialize it with a pattern
        int32_t i;
        char hex[] = "0123456789ABCDEF";
        for (i = 0; i < size; i++) {
            buf[i] = hex[i & 0xF];
        }

        double writeCount = 0, writeRate = 0, writeRateSquared = 0;
        double totalCount = 0, totalRate = 0, totalRateSquared = 0;
        for (i = 0; i < iterations; i++) {
            PRIntervalTime start = PR_IntervalNow();

            char name[1024];
            sprintf(name, "%s_%d", filename, i);
            PRFileDesc* fd = PR_Open(name, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664);
            if (fd == nullptr)
                return -1;

            PRIntervalTime writeStart = PR_IntervalNow();
            int32_t rv = PR_Write(fd, buf, size);
            if (rv < 0) return rv;
            if (rv != size) return -1;
            PRIntervalTime writeStop = PR_IntervalNow();

            PRStatus st = PR_Close(fd);
            if (st == PR_FAILURE) return -1; 

            PRIntervalTime stop = PR_IntervalNow();

            PRIntervalTime writeTime = PR_IntervalToMilliseconds(writeStop - writeStart);
            if (writeTime > 0) {
                double wr = size / writeTime;
                writeRate += wr;
                writeRateSquared += wr * wr;
                writeCount++;
            }

            PRIntervalTime totalTime = PR_IntervalToMilliseconds(stop - start);
            if (totalTime > 0) {
                double t = size / totalTime;
                totalRate += t;
                totalRateSquared += t * t;
                totalCount++;
            }
        }

        PR_Free(buf);

        double writeMean, writeStddev;
        double totalMean, totalStddev;
        NS_MeanAndStdDev(writeCount, writeRate, writeRateSquared,
                         &writeMean, &writeStddev);
        NS_MeanAndStdDev(totalCount, totalRate, totalRateSquared,
                         &totalMean, &totalStddev);
        fprintf(stdout, "%10d      %10.2f %10.2f %10d      %10.2f %10.2f %10d\n",
                size, writeMean, writeStddev, (int32_t)writeCount, 
                totalMean, totalStddev, (int32_t)totalCount);
    }
    return 0;
}