Bug 1895346 - Drop nsStringStats. r=nika,xpcom-reviewers
As per the discussion in D208771, they don't bring much value so seems worth doing this first. Differential Revision: https://phabricator.services.mozilla.com/D209580
This commit is contained in:
@@ -56,7 +56,4 @@ UNIFIED_SOURCES += [
|
||||
"RustStringAPI.cpp",
|
||||
]
|
||||
|
||||
if CONFIG["MOZ_DEBUG"]:
|
||||
UNIFIED_SOURCES += ["nsStringStats.cpp"]
|
||||
|
||||
FINAL_LIBRARY = "xul"
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringStats.h"
|
||||
|
||||
void nsStringBuffer::AddRef() {
|
||||
// Memory synchronization is not required when incrementing a
|
||||
@@ -28,7 +27,6 @@ void nsStringBuffer::AddRef() {
|
||||
+ 1
|
||||
#endif
|
||||
;
|
||||
STRING_STAT_INCREMENT(Share);
|
||||
NS_LOG_ADDREF(this, count, "nsStringBuffer", sizeof(*this));
|
||||
}
|
||||
|
||||
@@ -46,7 +44,6 @@ void nsStringBuffer::Release() {
|
||||
// writes prior to that release are now visible on this thread.
|
||||
count = mRefCount.load(std::memory_order_acquire);
|
||||
|
||||
STRING_STAT_INCREMENT(Free);
|
||||
free(this); // we were allocated with |malloc|
|
||||
}
|
||||
}
|
||||
@@ -62,8 +59,6 @@ already_AddRefed<nsStringBuffer> nsStringBuffer::Alloc(size_t aSize) {
|
||||
|
||||
auto* hdr = (nsStringBuffer*)malloc(sizeof(nsStringBuffer) + aSize);
|
||||
if (hdr) {
|
||||
STRING_STAT_INCREMENT(Alloc);
|
||||
|
||||
hdr->mRefCount = 1;
|
||||
hdr->mStorageSize = aSize;
|
||||
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
||||
@@ -96,8 +91,6 @@ already_AddRefed<nsStringBuffer> nsStringBuffer::Create(const char16_t* aData,
|
||||
}
|
||||
|
||||
nsStringBuffer* nsStringBuffer::Realloc(nsStringBuffer* aHdr, size_t aSize) {
|
||||
STRING_STAT_INCREMENT(Realloc);
|
||||
|
||||
NS_ASSERTION(aSize != 0, "zero capacity allocation not allowed");
|
||||
NS_ASSERTION(sizeof(nsStringBuffer) + aSize <= size_t(uint32_t(-1)) &&
|
||||
sizeof(nsStringBuffer) + aSize > aSize,
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsStringStats.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
# include "mozilla/IntegerPrintfMacros.h"
|
||||
# include "mozilla/MemoryReporting.h"
|
||||
# include "nsString.h"
|
||||
|
||||
# include <stdint.h>
|
||||
# include <stdio.h>
|
||||
|
||||
# ifdef XP_WIN
|
||||
# include <windows.h>
|
||||
# include <process.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# include <pthread.h>
|
||||
# endif
|
||||
|
||||
nsStringStats gStringStats;
|
||||
|
||||
nsStringStats::~nsStringStats() {
|
||||
// this is a hack to suppress duplicate string stats printing
|
||||
// in seamonkey as a result of the string code being linked
|
||||
// into seamonkey and libxpcom! :-(
|
||||
if (!mAllocCount && !mAdoptCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only print the stats if we detect a leak.
|
||||
if (mAllocCount <= mFreeCount && mAdoptCount <= mAdoptFreeCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("nsStringStats\n");
|
||||
printf(" => mAllocCount: % 10d\n", int(mAllocCount));
|
||||
printf(" => mReallocCount: % 10d\n", int(mReallocCount));
|
||||
printf(" => mFreeCount: % 10d", int(mFreeCount));
|
||||
if (mAllocCount > mFreeCount) {
|
||||
printf(" -- LEAKED %d !!!\n", mAllocCount - mFreeCount);
|
||||
} else {
|
||||
printf("\n");
|
||||
}
|
||||
printf(" => mShareCount: % 10d\n", int(mShareCount));
|
||||
printf(" => mAdoptCount: % 10d\n", int(mAdoptCount));
|
||||
printf(" => mAdoptFreeCount: % 10d", int(mAdoptFreeCount));
|
||||
if (mAdoptCount > mAdoptFreeCount) {
|
||||
printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount);
|
||||
} else {
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
# ifdef XP_WIN
|
||||
auto pid = uintptr_t(_getpid());
|
||||
auto tid = uintptr_t(GetCurrentThreadId());
|
||||
# else
|
||||
auto pid = uintptr_t(getpid());
|
||||
auto tid = uintptr_t(pthread_self());
|
||||
# endif
|
||||
|
||||
printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n", pid, tid);
|
||||
}
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsStringStats_h
|
||||
#define nsStringStats_h
|
||||
|
||||
#ifdef DEBUG
|
||||
# include "mozilla/Atomics.h"
|
||||
|
||||
class nsStringStats {
|
||||
public:
|
||||
nsStringStats() = default;
|
||||
|
||||
~nsStringStats();
|
||||
|
||||
using AtomicInt = mozilla::Atomic<int32_t, mozilla::Relaxed>;
|
||||
|
||||
AtomicInt mAllocCount{0};
|
||||
AtomicInt mReallocCount{0};
|
||||
AtomicInt mFreeCount{0};
|
||||
AtomicInt mShareCount{0};
|
||||
AtomicInt mAdoptCount{0};
|
||||
AtomicInt mAdoptFreeCount{0};
|
||||
};
|
||||
|
||||
extern nsStringStats gStringStats;
|
||||
# define STRING_STAT_INCREMENT(_s) (gStringStats.m##_s##Count)++
|
||||
#else
|
||||
# define STRING_STAT_INCREMENT(_s)
|
||||
#endif
|
||||
|
||||
#endif // nsStringStats_h
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsStringStats.h"
|
||||
|
||||
// It's not worthwhile to reallocate the buffer and memcpy the
|
||||
// contents over when the size difference isn't large. With
|
||||
@@ -58,7 +57,6 @@ static void ReleaseData(void* aData, nsAString::DataFlags aFlags) {
|
||||
MOZ_LOG_DTOR(aData, "StringAdopt", 1);
|
||||
|
||||
free(aData);
|
||||
STRING_STAT_INCREMENT(AdoptFree);
|
||||
}
|
||||
// otherwise, nothing to do.
|
||||
}
|
||||
@@ -74,7 +72,6 @@ nsTSubstring<T>::nsTSubstring(char_type* aData, size_type aLength,
|
||||
AssertValid();
|
||||
|
||||
if (aDataFlags & DataFlags::OWNED) {
|
||||
STRING_STAT_INCREMENT(Adopt);
|
||||
MOZ_LOG_CTOR(this->mData, "StringAdopt", 1);
|
||||
}
|
||||
}
|
||||
@@ -626,7 +623,6 @@ void nsTSubstring<T>::Adopt(char_type* aData, size_type aLength) {
|
||||
|
||||
SetData(aData, aLength, DataFlags::TERMINATED | DataFlags::OWNED);
|
||||
|
||||
STRING_STAT_INCREMENT(Adopt);
|
||||
// Treat this as construction of a "StringAdopt" object for leak
|
||||
// tracking purposes.
|
||||
MOZ_LOG_CTOR(this->mData, "StringAdopt", 1);
|
||||
|
||||
Reference in New Issue
Block a user