no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / xpcom / string / nsStringStats.cpp
blob7fc3d82ad5aafb85b53f6614fa5c6cb6108693a8
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsStringStats.h"
9 #include "mozilla/IntegerPrintfMacros.h"
10 #include "mozilla/MemoryReporting.h"
11 #include "nsString.h"
13 #include <stdint.h>
14 #include <stdio.h>
16 #ifdef XP_WIN
17 # include <windows.h>
18 # include <process.h>
19 #else
20 # include <unistd.h>
21 # include <pthread.h>
22 #endif
24 nsStringStats gStringStats;
26 nsStringStats::~nsStringStats() {
27 // this is a hack to suppress duplicate string stats printing
28 // in seamonkey as a result of the string code being linked
29 // into seamonkey and libxpcom! :-(
30 if (!mAllocCount && !mAdoptCount) {
31 return;
34 // Only print the stats if we detect a leak.
35 if (mAllocCount <= mFreeCount && mAdoptCount <= mAdoptFreeCount) {
36 return;
39 printf("nsStringStats\n");
40 printf(" => mAllocCount: % 10d\n", int(mAllocCount));
41 printf(" => mReallocCount: % 10d\n", int(mReallocCount));
42 printf(" => mFreeCount: % 10d", int(mFreeCount));
43 if (mAllocCount > mFreeCount) {
44 printf(" -- LEAKED %d !!!\n", mAllocCount - mFreeCount);
45 } else {
46 printf("\n");
48 printf(" => mShareCount: % 10d\n", int(mShareCount));
49 printf(" => mAdoptCount: % 10d\n", int(mAdoptCount));
50 printf(" => mAdoptFreeCount: % 10d", int(mAdoptFreeCount));
51 if (mAdoptCount > mAdoptFreeCount) {
52 printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount);
53 } else {
54 printf("\n");
57 #ifdef XP_WIN
58 auto pid = uintptr_t(_getpid());
59 auto tid = uintptr_t(GetCurrentThreadId());
60 #else
61 auto pid = uintptr_t(getpid());
62 auto tid = uintptr_t(pthread_self());
63 #endif
65 printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n", pid, tid);