Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions
nsTraceRefcntImpl Class Reference

#include <nsTraceRefcntImpl.h>

Inheritance diagram for nsTraceRefcntImpl:
Inheritance graph
[legend]
Collaboration diagram for nsTraceRefcntImpl:
Collaboration graph
[legend]

List of all members.

Public Types

enum  StatisticsType { ALL_STATS, NEW_STATS }

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSITRACEREFCNT 
nsTraceRefcntImpl ()
void logAddRef (in voidPtr aPtr, in nsrefcnt aNewRefcnt, in string aTypeName, in unsigned long aInstanceSize)
void logRelease (in voidPtr aPtr, in nsrefcnt aNewRefcnt, in string aTypeName)
void logCtor (in voidPtr aPtr, in string aTypeName, in unsigned long aInstanceSize)
void logDtor (in voidPtr aPtr, in string aTypeName, in unsigned long aInstanceSize)
void logAddCOMPtr (in voidPtr aPtr, in nsISupports aObject)
void logReleaseCOMPtr (in voidPtr aPtr, in nsISupports aObject)

Static Public Member Functions

static NS_COM void Startup ()
static NS_COM void Shutdown ()
static NS_COM nsresult DumpStatistics (StatisticsType type=ALL_STATS, FILE *out=0)
static NS_COM void ResetStatistics (void)
static NS_COM void LoadLibrarySymbols (const char *aLibraryName, void *aLibrayHandle)
static NS_COM void DemangleSymbol (const char *aSymbol, char *aBuffer, int aBufLen)
static NS_COM void WalkTheStack (FILE *aStream)
static NS_COM void SetActivityIsLegal (PRBool aLegal)
 Tell nsTraceRefcnt whether refcounting, allocation, and destruction activity is legal.
static NS_METHOD Create (nsISupports *outer, const nsIID &aIID, void **aInstancePtr)

Private Member Functions

 ~nsTraceRefcntImpl ()

Detailed Description

Definition at line 44 of file nsTraceRefcntImpl.h.


Member Enumeration Documentation

Enumerator:
ALL_STATS 
NEW_STATS 

Definition at line 55 of file nsTraceRefcntImpl.h.


Constructor & Destructor Documentation

Definition at line 957 of file nsTraceRefcntImpl.cpp.

{
  /* member initializers and constructor code */
}

Here is the caller graph for this function:

Definition at line 84 of file nsTraceRefcntImpl.h.

{}

Member Function Documentation

NS_METHOD nsTraceRefcntImpl::Create ( nsISupports *  outer,
const nsIID aIID,
void **  aInstancePtr 
) [static]

Definition at line 1297 of file nsTraceRefcntImpl.cpp.

{
  *aInstancePtr = nsnull;
  nsITraceRefcnt* tracer = new nsTraceRefcntImpl();
  if (!tracer)
    return NS_ERROR_OUT_OF_MEMORY;
  
  nsresult rv = tracer->QueryInterface(aIID, aInstancePtr);
  if (NS_FAILED(rv)) {
    delete tracer;
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_COM void nsTraceRefcntImpl::DemangleSymbol ( const char *  aSymbol,
char *  aBuffer,
int  aBufLen 
) [static]

Definition at line 847 of file nsTraceRefcntImpl.cpp.

{
  NS_ASSERTION(nsnull != aSymbol,"null symbol");
  NS_ASSERTION(nsnull != aBuffer,"null buffer");
  NS_ASSERTION(aBufLen >= 32 ,"pulled 32 out of you know where");

  aBuffer[0] = '\0';

#if defined(MOZ_DEMANGLE_SYMBOLS)
 /* See demangle.h in the gcc source for the voodoo */
  char * demangled = abi::__cxa_demangle(aSymbol,0,0,0);

  if (demangled)
  {
    strncpy(aBuffer,demangled,aBufLen);
    free(demangled);
  }
#endif // MOZ_DEMANGLE_SYMBOLS
}

Definition at line 451 of file nsTraceRefcntImpl.cpp.

{
  nsresult rv = NS_OK;
#ifdef NS_BUILD_REFCNT_LOGGING
  if (gBloatLog == nsnull || gBloatView == nsnull) {
    return NS_ERROR_FAILURE;
  }
  if (out == nsnull) {
    out = gBloatLog;
  }

  LOCK_TRACELOG();

  PRBool wasLogging = gLogging;
  gLogging = PR_FALSE;  // turn off logging for this method
  
  const char* msg;
  if (type == NEW_STATS) {
    if (gLogLeaksOnly)
      msg = "NEW (incremental) LEAK STATISTICS";
    else
      msg = "NEW (incremental) LEAK AND BLOAT STATISTICS";
  }
  else {
    if (gLogLeaksOnly)
      msg = "ALL (cumulative) LEAK STATISTICS";
    else
      msg = "ALL (cumulative) LEAK AND BLOAT STATISTICS";
  }
  rv = BloatEntry::PrintDumpHeader(out, msg);
  if (NS_FAILED(rv)) goto done;

  {
    BloatEntry total("TOTAL", 0);
    PL_HashTableEnumerateEntries(gBloatView, BloatEntry::TotalEntries, &total);
    total.DumpTotal(gBloatView->nentries, out);

    nsVoidArray entries;
    PL_HashTableEnumerateEntries(gBloatView, BloatEntry::DumpEntry, &entries);

    fprintf(stdout, "nsTraceRefcntImpl::DumpStatistics: %d entries\n",
           entries.Count());

    // Sort the entries alphabetically by classname.
    PRInt32 i, j;
    for (i = entries.Count() - 1; i >= 1; --i) {
      for (j = i - 1; j >= 0; --j) {
        BloatEntry* left  = NS_STATIC_CAST(BloatEntry*, entries[i]);
        BloatEntry* right = NS_STATIC_CAST(BloatEntry*, entries[j]);

        if (PL_strcmp(left->GetClassName(), right->GetClassName()) < 0) {
          entries.ReplaceElementAt(right, i);
          entries.ReplaceElementAt(left, j);
        }
      }
    }

    // Enumerate from back-to-front, so things come out in alpha order
    for (i = 0; i < entries.Count(); ++i) {
      BloatEntry* entry = NS_STATIC_CAST(BloatEntry*, entries[i]);
      entry->Dump(i, out, type);
    }
  }

  if (gSerialNumbers) {
    fprintf(out, "\n\nSerial Numbers of Leaked Objects:\n");
    PL_HashTableEnumerateEntries(gSerialNumbers, DumpSerialNumbers, out);
  }

done:
  gLogging = wasLogging;
  UNLOCK_TRACELOG();
#endif
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_COM void nsTraceRefcntImpl::LoadLibrarySymbols ( const char *  aLibraryName,
void aLibrayHandle 
) [static]

Definition at line 873 of file nsTraceRefcntImpl.cpp.

{
#ifdef NS_BUILD_REFCNT_LOGGING
#if defined(_WIN32) && defined(_M_IX86) /* Win32 x86 only */
  if (!gInitialized)
    InitTraceLog();

  if (gAllocLog || gRefcntsLog) {
    fprintf(stdout, "### Loading symbols for %s\n", aLibraryName);
    fflush(stdout);

    HANDLE myProcess = ::GetCurrentProcess();    
    BOOL ok = EnsureSymInitialized();
    if (ok) {
      const char* baseName = aLibraryName;
      // just get the base name of the library if a full path was given:
      PRInt32 len = strlen(aLibraryName);
      for (PRInt32 i = len - 1; i >= 0; i--) {
        if (aLibraryName[i] == '\\') {
          baseName = &aLibraryName[i + 1];
          break;
        }
      }
      DWORD baseAddr = _SymLoadModule(myProcess,
                                     NULL,
                                     (char*)baseName,
                                     (char*)baseName,
                                     0,
                                     0);
      ok = (baseAddr != nsnull);
    }
    if (!ok) {
      LPVOID lpMsgBuf;
      FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM | 
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        GetLastError(),
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
        (LPTSTR) &lpMsgBuf,
        0,
        NULL 
        );
      fprintf(stdout, "### ERROR: LoadLibrarySymbols for %s: %s\n",
              aLibraryName, lpMsgBuf);
      fflush(stdout);
      LocalFree( lpMsgBuf );
    }
  }
#endif
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsITraceRefcnt::logAddCOMPtr ( in voidPtr  aPtr,
in nsISupports  aObject 
) [inherited]
void nsITraceRefcnt::logAddRef ( in voidPtr  aPtr,
in nsrefcnt  aNewRefcnt,
in string  aTypeName,
in unsigned long  aInstanceSize 
) [inherited]
void nsITraceRefcnt::logCtor ( in voidPtr  aPtr,
in string  aTypeName,
in unsigned long  aInstanceSize 
) [inherited]
void nsITraceRefcnt::logDtor ( in voidPtr  aPtr,
in string  aTypeName,
in unsigned long  aInstanceSize 
) [inherited]
void nsITraceRefcnt::logRelease ( in voidPtr  aPtr,
in nsrefcnt  aNewRefcnt,
in string  aTypeName 
) [inherited]
void nsITraceRefcnt::logReleaseCOMPtr ( in voidPtr  aPtr,
in nsISupports  aObject 
) [inherited]

Definition at line 528 of file nsTraceRefcntImpl.cpp.

{
#ifdef NS_BUILD_REFCNT_LOGGING
  LOCK_TRACELOG();
  if (gBloatView) {
    PL_HashTableDestroy(gBloatView);
    gBloatView = nsnull;
  }
  UNLOCK_TRACELOG();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tell nsTraceRefcnt whether refcounting, allocation, and destruction activity is legal.

This is used to trigger assertions for any such activity that occurs because of static constructors or destructors.

Definition at line 1288 of file nsTraceRefcntImpl.cpp.

{
#ifdef NS_BUILD_REFCNT_LOGGING
  gActivityIsLegal = aLegal;
#endif
}

Here is the caller graph for this function:

Definition at line 1261 of file nsTraceRefcntImpl.cpp.

{
#ifdef NS_BUILD_REFCNT_LOGGING

  if (gBloatView) {
    PL_HashTableDestroy(gBloatView);
    gBloatView = nsnull;
  }
  if (gTypesToLog) {
    PL_HashTableDestroy(gTypesToLog);
    gTypesToLog = nsnull;
  }
  if (gObjectsToLog) {
    PL_HashTableDestroy(gObjectsToLog);
    gObjectsToLog = nsnull;
  }
  if (gSerialNumbers) {
    PL_HashTableDestroy(gSerialNumbers);
    gSerialNumbers = nsnull;
  }

  SetActivityIsLegal(PR_FALSE);

#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1253 of file nsTraceRefcntImpl.cpp.

{
#ifdef NS_BUILD_REFCNT_LOGGING
  SetActivityIsLegal(PR_TRUE);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 830 of file nsTraceRefcntImpl.cpp.

{
       fprintf(aStream, "write me, dammit!\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: