forked from mirrors/gecko-dev
Bug 1893668 - Make string stats more obviously debug-only. r=xpcom-reviewers,mccr8
Also, make them relaxed atomic. Sequentially consistent atomics might help paper concurrency issues in debug builds, and there's really no good reason these counts need to be sequentially consistent. Differential Revision: https://phabricator.services.mozilla.com/D208759
This commit is contained in:
parent
d416fbeae3
commit
de27e73e27
4 changed files with 26 additions and 31 deletions
|
|
@ -9,12 +9,7 @@
|
||||||
#include "mozilla/MemoryReporting.h"
|
#include "mozilla/MemoryReporting.h"
|
||||||
#include "nsISupportsImpl.h"
|
#include "nsISupportsImpl.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
#include "nsStringStats.h"
|
||||||
#ifdef DEBUG
|
|
||||||
# include "nsStringStats.h"
|
|
||||||
#else
|
|
||||||
# define STRING_STAT_INCREMENT(_s)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void nsStringBuffer::AddRef() {
|
void nsStringBuffer::AddRef() {
|
||||||
// Memory synchronization is not required when incrementing a
|
// Memory synchronization is not required when incrementing a
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,21 @@
|
||||||
|
|
||||||
#include "nsStringStats.h"
|
#include "nsStringStats.h"
|
||||||
|
|
||||||
#include "mozilla/IntegerPrintfMacros.h"
|
#ifdef DEBUG
|
||||||
#include "mozilla/MemoryReporting.h"
|
# include "mozilla/IntegerPrintfMacros.h"
|
||||||
#include "nsString.h"
|
# include "mozilla/MemoryReporting.h"
|
||||||
|
# include "nsString.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
# include <stdint.h>
|
||||||
#include <stdio.h>
|
# include <stdio.h>
|
||||||
|
|
||||||
#ifdef XP_WIN
|
# ifdef XP_WIN
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <process.h>
|
# include <process.h>
|
||||||
#else
|
# else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
nsStringStats gStringStats;
|
nsStringStats gStringStats;
|
||||||
|
|
||||||
|
|
@ -54,13 +55,14 @@ nsStringStats::~nsStringStats() {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef XP_WIN
|
# ifdef XP_WIN
|
||||||
auto pid = uintptr_t(_getpid());
|
auto pid = uintptr_t(_getpid());
|
||||||
auto tid = uintptr_t(GetCurrentThreadId());
|
auto tid = uintptr_t(GetCurrentThreadId());
|
||||||
#else
|
# else
|
||||||
auto pid = uintptr_t(getpid());
|
auto pid = uintptr_t(getpid());
|
||||||
auto tid = uintptr_t(pthread_self());
|
auto tid = uintptr_t(pthread_self());
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n", pid, tid);
|
printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n", pid, tid);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
#ifndef nsStringStats_h
|
#ifndef nsStringStats_h
|
||||||
#define nsStringStats_h
|
#define nsStringStats_h
|
||||||
|
|
||||||
#include "mozilla/Atomics.h"
|
#ifdef DEBUG
|
||||||
|
# include "mozilla/Atomics.h"
|
||||||
|
|
||||||
class nsStringStats {
|
class nsStringStats {
|
||||||
public:
|
public:
|
||||||
|
|
@ -15,7 +16,7 @@ class nsStringStats {
|
||||||
|
|
||||||
~nsStringStats();
|
~nsStringStats();
|
||||||
|
|
||||||
using AtomicInt = mozilla::Atomic<int32_t, mozilla::SequentiallyConsistent>;
|
using AtomicInt = mozilla::Atomic<int32_t, mozilla::Relaxed>;
|
||||||
|
|
||||||
AtomicInt mAllocCount{0};
|
AtomicInt mAllocCount{0};
|
||||||
AtomicInt mReallocCount{0};
|
AtomicInt mReallocCount{0};
|
||||||
|
|
@ -26,7 +27,9 @@ class nsStringStats {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern nsStringStats gStringStats;
|
extern nsStringStats gStringStats;
|
||||||
|
# define STRING_STAT_INCREMENT(_s) (gStringStats.m##_s##Count)++
|
||||||
#define STRING_STAT_INCREMENT(_s) (gStringStats.m##_s##Count)++
|
#else
|
||||||
|
# define STRING_STAT_INCREMENT(_s)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // nsStringStats_h
|
#endif // nsStringStats_h
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,7 @@
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsTArray.h"
|
#include "nsTArray.h"
|
||||||
|
#include "nsStringStats.h"
|
||||||
#ifdef DEBUG
|
|
||||||
# include "nsStringStats.h"
|
|
||||||
#else
|
|
||||||
# define STRING_STAT_INCREMENT(_s)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// It's not worthwhile to reallocate the buffer and memcpy the
|
// It's not worthwhile to reallocate the buffer and memcpy the
|
||||||
// contents over when the size difference isn't large. With
|
// contents over when the size difference isn't large. With
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue