bug 113738 Cost of malloc into trace-malloc log r=blythe, sr=brendan
This commit is contained in:
@@ -58,6 +58,7 @@
|
||||
#include "prmon.h"
|
||||
#include "prprf.h"
|
||||
#include "prenv.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsTraceMalloc.h"
|
||||
#include "nscore.h"
|
||||
|
||||
@@ -73,11 +74,6 @@
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*
|
||||
* Record the intervals in a platform independent manner.
|
||||
*/
|
||||
#define MILLISECONDS_NOW PR_IntervalToMilliseconds(PR_IntervalNow())
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define WRITE_FLAGS "w"
|
||||
|
||||
@@ -474,6 +470,13 @@ static void log_event7(logfile *fp, char event, uint32 serial, uint32 ui2,
|
||||
log_uint32(fp, ui7);
|
||||
}
|
||||
|
||||
static void log_event8(logfile *fp, char event, uint32 serial, uint32 ui2,
|
||||
uint32 ui3, uint32 ui4, uint32 ui5, uint32 ui6,
|
||||
uint32 ui7, uint32 ui8)
|
||||
{
|
||||
log_event7(fp, event, serial, ui2, ui3, ui4, ui5, ui6, ui7);
|
||||
log_uint32(fp, ui8);
|
||||
}
|
||||
|
||||
typedef struct callsite callsite;
|
||||
|
||||
@@ -1301,12 +1304,15 @@ static PLHashTable *new_allocations(void)
|
||||
|
||||
__ptr_t malloc(size_t size)
|
||||
{
|
||||
PRUint32 start, end;
|
||||
__ptr_t *ptr;
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
allocation *alloc;
|
||||
|
||||
start = PR_IntervalNow();
|
||||
ptr = __libc_malloc(size);
|
||||
end = PR_IntervalNow();
|
||||
TM_ENTER_MONITOR();
|
||||
tmstats.malloc_calls++;
|
||||
if (!ptr) {
|
||||
@@ -1314,8 +1320,8 @@ __ptr_t malloc(size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(1);
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1333,12 +1339,15 @@ __ptr_t malloc(size_t size)
|
||||
|
||||
__ptr_t calloc(size_t count, size_t size)
|
||||
{
|
||||
PRUint32 start, end;
|
||||
__ptr_t *ptr;
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
allocation *alloc;
|
||||
|
||||
start = PR_IntervalNow();
|
||||
ptr = __libc_calloc(count, size);
|
||||
end = PR_IntervalNow();
|
||||
TM_ENTER_MONITOR();
|
||||
tmstats.calloc_calls++;
|
||||
if (!ptr) {
|
||||
@@ -1347,8 +1356,8 @@ __ptr_t calloc(size_t count, size_t size)
|
||||
site = backtrace(1);
|
||||
size *= count;
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1366,6 +1375,7 @@ __ptr_t calloc(size_t count, size_t size)
|
||||
|
||||
__ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
{
|
||||
PRUint32 start, end;
|
||||
__ptr_t oldptr;
|
||||
callsite *oldsite, *site;
|
||||
size_t oldsize;
|
||||
@@ -1393,7 +1403,9 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
}
|
||||
TM_EXIT_MONITOR();
|
||||
|
||||
start = PR_IntervalNow();
|
||||
ptr = __libc_realloc(ptr, size);
|
||||
end = PR_IntervalNow();
|
||||
|
||||
TM_ENTER_MONITOR();
|
||||
if (!ptr && size) {
|
||||
@@ -1405,8 +1417,8 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(1);
|
||||
if (site) {
|
||||
log_event7(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event8(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size,
|
||||
oldsite ? oldsite->serial : 0,
|
||||
(uint32)NS_PTR_TO_INT32(oldptr), oldsize);
|
||||
@@ -1448,6 +1460,8 @@ void free(__ptr_t ptr)
|
||||
PLHashEntry **hep, *he;
|
||||
callsite *site;
|
||||
allocation *alloc;
|
||||
uint32 serial = 0, size = 0;
|
||||
PRUint32 start, end;
|
||||
|
||||
TM_ENTER_MONITOR();
|
||||
tmstats.free_calls++;
|
||||
@@ -1461,22 +1475,40 @@ void free(__ptr_t ptr)
|
||||
site = (callsite*) he->value;
|
||||
if (site) {
|
||||
alloc = (allocation*) he;
|
||||
log_event4(logfp, TM_EVENT_FREE,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), alloc->size);
|
||||
serial = site->serial;
|
||||
size = alloc->size;
|
||||
}
|
||||
PL_HashTableRawRemove(allocations, hep, he);
|
||||
}
|
||||
}
|
||||
}
|
||||
TM_EXIT_MONITOR();
|
||||
|
||||
start = PR_IntervalNow();
|
||||
__libc_free(ptr);
|
||||
end = PR_IntervalNow();
|
||||
|
||||
if (size != 0) {
|
||||
TM_ENTER_MONITOR();
|
||||
log_event5(logfp, TM_EVENT_FREE,
|
||||
serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
TM_EXIT_MONITOR();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
static const char magic[] = NS_TRACE_MALLOC_MAGIC;
|
||||
|
||||
static void
|
||||
log_header(int logfd)
|
||||
{
|
||||
uint32 ticksPerSec = PR_htonl(PR_TicksPerSecond());
|
||||
(void) write(logfd, magic, NS_TRACE_MALLOC_MAGIC_SIZE);
|
||||
(void) write(logfd, &ticksPerSec, sizeof ticksPerSec);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void) NS_TraceMallocStartup(int logfd)
|
||||
{
|
||||
/* We must be running on the primordial thread. */
|
||||
@@ -1490,8 +1522,7 @@ PR_IMPLEMENT(void) NS_TraceMallocStartup(int logfd)
|
||||
logfile_list = &default_logfile;
|
||||
logfp->prevp = &logfile_list;
|
||||
logfile_tail = &logfp->next;
|
||||
(void) write(logfd, magic, NS_TRACE_MALLOC_MAGIC_SIZE);
|
||||
flush_logfile(logfp);
|
||||
log_header(logfd);
|
||||
}
|
||||
|
||||
atexit(NS_TraceMallocShutdown);
|
||||
@@ -1562,7 +1593,9 @@ PR_IMPLEMENT(int) NS_TraceMallocStartupArgs(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if (tmlogname) {
|
||||
#ifdef XP_UNIX
|
||||
int pipefds[2];
|
||||
#endif
|
||||
|
||||
switch (*tmlogname) {
|
||||
#ifdef XP_UNIX
|
||||
@@ -1716,7 +1749,7 @@ PR_IMPLEMENT(int) NS_TraceMallocChangeLogFD(int fd)
|
||||
if (!fp)
|
||||
return -2;
|
||||
if (fd >= 0 && fstat(fd, &sb) == 0 && sb.st_size == 0)
|
||||
(void) write(fd, magic, NS_TRACE_MALLOC_MAGIC_SIZE);
|
||||
log_header(fd);
|
||||
logfp = fp;
|
||||
}
|
||||
TM_EXIT_MONITOR();
|
||||
@@ -1883,7 +1916,7 @@ NS_TraceMallocFlushLogfiles()
|
||||
#ifdef XP_WIN32
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
MallocCallback(void *ptr, size_t size)
|
||||
MallocCallback(void *ptr, size_t size, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
@@ -1896,8 +1929,8 @@ MallocCallback(void *ptr, size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(4);
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1913,7 +1946,7 @@ MallocCallback(void *ptr, size_t size)
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
CallocCallback(void *ptr, size_t count, size_t size)
|
||||
CallocCallback(void *ptr, size_t count, size_t size, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
@@ -1927,8 +1960,8 @@ CallocCallback(void *ptr, size_t count, size_t size)
|
||||
site = backtrace(1);
|
||||
size *= count;
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1944,7 +1977,7 @@ CallocCallback(void *ptr, size_t count, size_t size)
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
ReallocCallback(void * oldptr, void *ptr, size_t size)
|
||||
ReallocCallback(void * oldptr, void *ptr, size_t size, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
callsite *oldsite, *site;
|
||||
size_t oldsize;
|
||||
@@ -1979,8 +2012,8 @@ ReallocCallback(void * oldptr, void *ptr, size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(1);
|
||||
if (site) {
|
||||
log_event7(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event8(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size,
|
||||
oldsite ? oldsite->serial : 0,
|
||||
(uint32)NS_PTR_TO_INT32(oldptr), oldsize);
|
||||
@@ -2016,7 +2049,7 @@ ReallocCallback(void * oldptr, void *ptr, size_t size)
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
FreeCallback(void * ptr)
|
||||
FreeCallback(void * ptr, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
PLHashEntry **hep, *he;
|
||||
callsite *site;
|
||||
@@ -2034,8 +2067,8 @@ FreeCallback(void * ptr)
|
||||
site = (callsite*) he->value;
|
||||
if (site) {
|
||||
alloc = (allocation*) he;
|
||||
log_event4(logfp, TM_EVENT_FREE,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_FREE,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), alloc->size);
|
||||
}
|
||||
PL_HashTableRawRemove(allocations, hep, he);
|
||||
|
||||
@@ -45,7 +45,7 @@ PR_BEGIN_EXTERN_C
|
||||
* NS_TraceMallocStartup comment (below) for magic number differences in log
|
||||
* file structure.
|
||||
*/
|
||||
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog06\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog07\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC_SIZE 16
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,10 +7,10 @@ PR_BEGIN_EXTERN_C
|
||||
PR_EXTERN(void) StartupHooker();/*implemented in TraceMalloc.cpp*/
|
||||
PR_EXTERN(void) ShutdownHooker();
|
||||
|
||||
PR_EXTERN(void) MallocCallback(void *aPtr, size_t aSize);/*implemented in nsTraceMalloc.c*/
|
||||
PR_EXTERN(void) CallocCallback(void *aPtr, size_t aCount, size_t aSize);
|
||||
PR_EXTERN(void) ReallocCallback(void *aPin, void* aPout, size_t aSize);
|
||||
PR_EXTERN(void) FreeCallback(void *aPtr);
|
||||
PR_EXTERN(void) MallocCallback(void *aPtr, size_t aSize, PRUint32 start, PRUint32 end);/*implemented in nsTraceMalloc.c*/
|
||||
PR_EXTERN(void) CallocCallback(void *aPtr, size_t aCount, size_t aSize, PRUint32 start, PRUint32 end);
|
||||
PR_EXTERN(void) ReallocCallback(void *aPin, void* aPout, size_t aSize, PRUint32 start, PRUint32 end);
|
||||
PR_EXTERN(void) FreeCallback(void *aPtr, PRUint32 start, PRUint32 end);
|
||||
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
@@ -138,14 +138,16 @@ DHWImportHooker &getMallocHooker()
|
||||
|
||||
void * __cdecl dhw_malloc( size_t size )
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* result = DHW_ORIGINAL(MALLOC_, getMallocHooker())(size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return result;
|
||||
g_lockOut = TRUE;
|
||||
#ifdef VERBOSE
|
||||
printf("* malloc called to get %d bytes. returned %#x\n", size, result);
|
||||
#endif
|
||||
MallocCallback(result, size);
|
||||
MallocCallback(result, size, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -162,13 +164,16 @@ DHWImportHooker &getCallocHooker()
|
||||
|
||||
void * __cdecl dhw_calloc( size_t count, size_t size )
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* result = DHW_ORIGINAL(CALLOC_, getCallocHooker())(count,size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return result;
|
||||
g_lockOut = TRUE;
|
||||
#ifdef VERBOSE
|
||||
printf("* calloc called to get %d many of %d bytes. returned %#x\n", count, size, result);
|
||||
#endif CallocCallback(result, count, size);
|
||||
#endif
|
||||
CallocCallback(result, count, size, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -184,14 +189,16 @@ DHWImportHooker &getFreeHooker()
|
||||
|
||||
void __cdecl dhw_free( void* p )
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
DHW_ORIGINAL(FREE_, getFreeHooker())(p);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return;
|
||||
g_lockOut = TRUE;
|
||||
#ifdef VERBOSE
|
||||
printf("* free called for %#x\n", p);
|
||||
#endif
|
||||
FreeCallback(p);
|
||||
FreeCallback(p, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -207,7 +214,9 @@ DHWImportHooker &getReallocHooker()
|
||||
|
||||
void * __cdecl dhw_realloc(void * pin, size_t size)
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* pout = DHW_ORIGINAL(REALLOC_, getReallocHooker())(pin, size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return pout;
|
||||
g_lockOut = TRUE;
|
||||
@@ -216,7 +225,7 @@ void * __cdecl dhw_realloc(void * pin, size_t size)
|
||||
printf("* realloc called to resize to %d. old ptr: %#x. new ptr: %#x\n",
|
||||
size, pin, pout);
|
||||
#endif
|
||||
ReallocCallback(pin,pout,size);
|
||||
ReallocCallback(pin, pout, size, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -233,8 +242,9 @@ DHWImportHooker &getNewHooker()
|
||||
|
||||
void * __cdecl dhw_new(size_t size)
|
||||
{
|
||||
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* result = DHW_ORIGINAL(NEW_, getNewHooker())(size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return result;
|
||||
g_lockOut = TRUE;
|
||||
@@ -243,7 +253,7 @@ void * __cdecl dhw_new(size_t size)
|
||||
printf("* new called to get %d bytes. returned %#x\n", size, result);
|
||||
dumpStack();
|
||||
#endif
|
||||
MallocCallback(result,size);//do we need a different one for new?
|
||||
MallocCallback(result, size, start, end);//do we need a different one for new?
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
return result;
|
||||
@@ -259,7 +269,9 @@ DHWImportHooker &getDeleteHooker()
|
||||
|
||||
void __cdecl dhw_delete(void* p)
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
DHW_ORIGINAL(DELETE_, getDeleteHooker())(p);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return;
|
||||
g_lockOut = TRUE;
|
||||
@@ -267,7 +279,7 @@ void __cdecl dhw_delete(void* p)
|
||||
printf("* delete called for %#x\n", p);
|
||||
dumpStack();
|
||||
#endif
|
||||
FreeCallback(p);
|
||||
FreeCallback(p, start, end);
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "prmon.h"
|
||||
#include "prprf.h"
|
||||
#include "prenv.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsTraceMalloc.h"
|
||||
#include "nscore.h"
|
||||
|
||||
@@ -73,11 +74,6 @@
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*
|
||||
* Record the intervals in a platform independent manner.
|
||||
*/
|
||||
#define MILLISECONDS_NOW PR_IntervalToMilliseconds(PR_IntervalNow())
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define WRITE_FLAGS "w"
|
||||
|
||||
@@ -474,6 +470,13 @@ static void log_event7(logfile *fp, char event, uint32 serial, uint32 ui2,
|
||||
log_uint32(fp, ui7);
|
||||
}
|
||||
|
||||
static void log_event8(logfile *fp, char event, uint32 serial, uint32 ui2,
|
||||
uint32 ui3, uint32 ui4, uint32 ui5, uint32 ui6,
|
||||
uint32 ui7, uint32 ui8)
|
||||
{
|
||||
log_event7(fp, event, serial, ui2, ui3, ui4, ui5, ui6, ui7);
|
||||
log_uint32(fp, ui8);
|
||||
}
|
||||
|
||||
typedef struct callsite callsite;
|
||||
|
||||
@@ -1301,12 +1304,15 @@ static PLHashTable *new_allocations(void)
|
||||
|
||||
__ptr_t malloc(size_t size)
|
||||
{
|
||||
PRUint32 start, end;
|
||||
__ptr_t *ptr;
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
allocation *alloc;
|
||||
|
||||
start = PR_IntervalNow();
|
||||
ptr = __libc_malloc(size);
|
||||
end = PR_IntervalNow();
|
||||
TM_ENTER_MONITOR();
|
||||
tmstats.malloc_calls++;
|
||||
if (!ptr) {
|
||||
@@ -1314,8 +1320,8 @@ __ptr_t malloc(size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(1);
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1333,12 +1339,15 @@ __ptr_t malloc(size_t size)
|
||||
|
||||
__ptr_t calloc(size_t count, size_t size)
|
||||
{
|
||||
PRUint32 start, end;
|
||||
__ptr_t *ptr;
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
allocation *alloc;
|
||||
|
||||
start = PR_IntervalNow();
|
||||
ptr = __libc_calloc(count, size);
|
||||
end = PR_IntervalNow();
|
||||
TM_ENTER_MONITOR();
|
||||
tmstats.calloc_calls++;
|
||||
if (!ptr) {
|
||||
@@ -1347,8 +1356,8 @@ __ptr_t calloc(size_t count, size_t size)
|
||||
site = backtrace(1);
|
||||
size *= count;
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1366,6 +1375,7 @@ __ptr_t calloc(size_t count, size_t size)
|
||||
|
||||
__ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
{
|
||||
PRUint32 start, end;
|
||||
__ptr_t oldptr;
|
||||
callsite *oldsite, *site;
|
||||
size_t oldsize;
|
||||
@@ -1393,7 +1403,9 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
}
|
||||
TM_EXIT_MONITOR();
|
||||
|
||||
start = PR_IntervalNow();
|
||||
ptr = __libc_realloc(ptr, size);
|
||||
end = PR_IntervalNow();
|
||||
|
||||
TM_ENTER_MONITOR();
|
||||
if (!ptr && size) {
|
||||
@@ -1405,8 +1417,8 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(1);
|
||||
if (site) {
|
||||
log_event7(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event8(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size,
|
||||
oldsite ? oldsite->serial : 0,
|
||||
(uint32)NS_PTR_TO_INT32(oldptr), oldsize);
|
||||
@@ -1448,6 +1460,8 @@ void free(__ptr_t ptr)
|
||||
PLHashEntry **hep, *he;
|
||||
callsite *site;
|
||||
allocation *alloc;
|
||||
uint32 serial = 0, size = 0;
|
||||
PRUint32 start, end;
|
||||
|
||||
TM_ENTER_MONITOR();
|
||||
tmstats.free_calls++;
|
||||
@@ -1461,22 +1475,40 @@ void free(__ptr_t ptr)
|
||||
site = (callsite*) he->value;
|
||||
if (site) {
|
||||
alloc = (allocation*) he;
|
||||
log_event4(logfp, TM_EVENT_FREE,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), alloc->size);
|
||||
serial = site->serial;
|
||||
size = alloc->size;
|
||||
}
|
||||
PL_HashTableRawRemove(allocations, hep, he);
|
||||
}
|
||||
}
|
||||
}
|
||||
TM_EXIT_MONITOR();
|
||||
|
||||
start = PR_IntervalNow();
|
||||
__libc_free(ptr);
|
||||
end = PR_IntervalNow();
|
||||
|
||||
if (size != 0) {
|
||||
TM_ENTER_MONITOR();
|
||||
log_event5(logfp, TM_EVENT_FREE,
|
||||
serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
TM_EXIT_MONITOR();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
static const char magic[] = NS_TRACE_MALLOC_MAGIC;
|
||||
|
||||
static void
|
||||
log_header(int logfd)
|
||||
{
|
||||
uint32 ticksPerSec = PR_htonl(PR_TicksPerSecond());
|
||||
(void) write(logfd, magic, NS_TRACE_MALLOC_MAGIC_SIZE);
|
||||
(void) write(logfd, &ticksPerSec, sizeof ticksPerSec);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void) NS_TraceMallocStartup(int logfd)
|
||||
{
|
||||
/* We must be running on the primordial thread. */
|
||||
@@ -1490,8 +1522,7 @@ PR_IMPLEMENT(void) NS_TraceMallocStartup(int logfd)
|
||||
logfile_list = &default_logfile;
|
||||
logfp->prevp = &logfile_list;
|
||||
logfile_tail = &logfp->next;
|
||||
(void) write(logfd, magic, NS_TRACE_MALLOC_MAGIC_SIZE);
|
||||
flush_logfile(logfp);
|
||||
log_header(logfd);
|
||||
}
|
||||
|
||||
atexit(NS_TraceMallocShutdown);
|
||||
@@ -1562,7 +1593,9 @@ PR_IMPLEMENT(int) NS_TraceMallocStartupArgs(int argc, char* argv[])
|
||||
}
|
||||
|
||||
if (tmlogname) {
|
||||
#ifdef XP_UNIX
|
||||
int pipefds[2];
|
||||
#endif
|
||||
|
||||
switch (*tmlogname) {
|
||||
#ifdef XP_UNIX
|
||||
@@ -1716,7 +1749,7 @@ PR_IMPLEMENT(int) NS_TraceMallocChangeLogFD(int fd)
|
||||
if (!fp)
|
||||
return -2;
|
||||
if (fd >= 0 && fstat(fd, &sb) == 0 && sb.st_size == 0)
|
||||
(void) write(fd, magic, NS_TRACE_MALLOC_MAGIC_SIZE);
|
||||
log_header(fd);
|
||||
logfp = fp;
|
||||
}
|
||||
TM_EXIT_MONITOR();
|
||||
@@ -1883,7 +1916,7 @@ NS_TraceMallocFlushLogfiles()
|
||||
#ifdef XP_WIN32
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
MallocCallback(void *ptr, size_t size)
|
||||
MallocCallback(void *ptr, size_t size, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
@@ -1896,8 +1929,8 @@ MallocCallback(void *ptr, size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(4);
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_MALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1913,7 +1946,7 @@ MallocCallback(void *ptr, size_t size)
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
CallocCallback(void *ptr, size_t count, size_t size)
|
||||
CallocCallback(void *ptr, size_t count, size_t size, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
callsite *site;
|
||||
PLHashEntry *he;
|
||||
@@ -1927,8 +1960,8 @@ CallocCallback(void *ptr, size_t count, size_t size)
|
||||
site = backtrace(1);
|
||||
size *= count;
|
||||
if (site)
|
||||
log_event4(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_CALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size);
|
||||
if (get_allocations()) {
|
||||
suppress_tracing++;
|
||||
@@ -1944,7 +1977,7 @@ CallocCallback(void *ptr, size_t count, size_t size)
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
ReallocCallback(void * oldptr, void *ptr, size_t size)
|
||||
ReallocCallback(void * oldptr, void *ptr, size_t size, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
callsite *oldsite, *site;
|
||||
size_t oldsize;
|
||||
@@ -1979,8 +2012,8 @@ ReallocCallback(void * oldptr, void *ptr, size_t size)
|
||||
} else if (suppress_tracing == 0) {
|
||||
site = backtrace(1);
|
||||
if (site) {
|
||||
log_event7(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event8(logfp, TM_EVENT_REALLOC,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), size,
|
||||
oldsite ? oldsite->serial : 0,
|
||||
(uint32)NS_PTR_TO_INT32(oldptr), oldsize);
|
||||
@@ -2016,7 +2049,7 @@ ReallocCallback(void * oldptr, void *ptr, size_t size)
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
FreeCallback(void * ptr)
|
||||
FreeCallback(void * ptr, PRUint32 start, PRUint32 end)
|
||||
{
|
||||
PLHashEntry **hep, *he;
|
||||
callsite *site;
|
||||
@@ -2034,8 +2067,8 @@ FreeCallback(void * ptr)
|
||||
site = (callsite*) he->value;
|
||||
if (site) {
|
||||
alloc = (allocation*) he;
|
||||
log_event4(logfp, TM_EVENT_FREE,
|
||||
site->serial, MILLISECONDS_NOW,
|
||||
log_event5(logfp, TM_EVENT_FREE,
|
||||
site->serial, start, end - start,
|
||||
(uint32)NS_PTR_TO_INT32(ptr), alloc->size);
|
||||
}
|
||||
PL_HashTableRawRemove(allocations, hep, he);
|
||||
|
||||
@@ -45,7 +45,7 @@ PR_BEGIN_EXTERN_C
|
||||
* NS_TraceMallocStartup comment (below) for magic number differences in log
|
||||
* file structure.
|
||||
*/
|
||||
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog06\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog07\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC_SIZE 16
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,10 +7,10 @@ PR_BEGIN_EXTERN_C
|
||||
PR_EXTERN(void) StartupHooker();/*implemented in TraceMalloc.cpp*/
|
||||
PR_EXTERN(void) ShutdownHooker();
|
||||
|
||||
PR_EXTERN(void) MallocCallback(void *aPtr, size_t aSize);/*implemented in nsTraceMalloc.c*/
|
||||
PR_EXTERN(void) CallocCallback(void *aPtr, size_t aCount, size_t aSize);
|
||||
PR_EXTERN(void) ReallocCallback(void *aPin, void* aPout, size_t aSize);
|
||||
PR_EXTERN(void) FreeCallback(void *aPtr);
|
||||
PR_EXTERN(void) MallocCallback(void *aPtr, size_t aSize, PRUint32 start, PRUint32 end);/*implemented in nsTraceMalloc.c*/
|
||||
PR_EXTERN(void) CallocCallback(void *aPtr, size_t aCount, size_t aSize, PRUint32 start, PRUint32 end);
|
||||
PR_EXTERN(void) ReallocCallback(void *aPin, void* aPout, size_t aSize, PRUint32 start, PRUint32 end);
|
||||
PR_EXTERN(void) FreeCallback(void *aPtr, PRUint32 start, PRUint32 end);
|
||||
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
@@ -138,14 +138,16 @@ DHWImportHooker &getMallocHooker()
|
||||
|
||||
void * __cdecl dhw_malloc( size_t size )
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* result = DHW_ORIGINAL(MALLOC_, getMallocHooker())(size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return result;
|
||||
g_lockOut = TRUE;
|
||||
#ifdef VERBOSE
|
||||
printf("* malloc called to get %d bytes. returned %#x\n", size, result);
|
||||
#endif
|
||||
MallocCallback(result, size);
|
||||
MallocCallback(result, size, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -162,13 +164,16 @@ DHWImportHooker &getCallocHooker()
|
||||
|
||||
void * __cdecl dhw_calloc( size_t count, size_t size )
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* result = DHW_ORIGINAL(CALLOC_, getCallocHooker())(count,size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return result;
|
||||
g_lockOut = TRUE;
|
||||
#ifdef VERBOSE
|
||||
printf("* calloc called to get %d many of %d bytes. returned %#x\n", count, size, result);
|
||||
#endif CallocCallback(result, count, size);
|
||||
#endif
|
||||
CallocCallback(result, count, size, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -184,14 +189,16 @@ DHWImportHooker &getFreeHooker()
|
||||
|
||||
void __cdecl dhw_free( void* p )
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
DHW_ORIGINAL(FREE_, getFreeHooker())(p);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return;
|
||||
g_lockOut = TRUE;
|
||||
#ifdef VERBOSE
|
||||
printf("* free called for %#x\n", p);
|
||||
#endif
|
||||
FreeCallback(p);
|
||||
FreeCallback(p, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -207,7 +214,9 @@ DHWImportHooker &getReallocHooker()
|
||||
|
||||
void * __cdecl dhw_realloc(void * pin, size_t size)
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* pout = DHW_ORIGINAL(REALLOC_, getReallocHooker())(pin, size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return pout;
|
||||
g_lockOut = TRUE;
|
||||
@@ -216,7 +225,7 @@ void * __cdecl dhw_realloc(void * pin, size_t size)
|
||||
printf("* realloc called to resize to %d. old ptr: %#x. new ptr: %#x\n",
|
||||
size, pin, pout);
|
||||
#endif
|
||||
ReallocCallback(pin,pout,size);
|
||||
ReallocCallback(pin, pout, size, start, end);
|
||||
// dumpStack();
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
@@ -233,8 +242,9 @@ DHWImportHooker &getNewHooker()
|
||||
|
||||
void * __cdecl dhw_new(size_t size)
|
||||
{
|
||||
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
void* result = DHW_ORIGINAL(NEW_, getNewHooker())(size);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return result;
|
||||
g_lockOut = TRUE;
|
||||
@@ -243,7 +253,7 @@ void * __cdecl dhw_new(size_t size)
|
||||
printf("* new called to get %d bytes. returned %#x\n", size, result);
|
||||
dumpStack();
|
||||
#endif
|
||||
MallocCallback(result,size);//do we need a different one for new?
|
||||
MallocCallback(result, size, start, end);//do we need a different one for new?
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
return result;
|
||||
@@ -259,7 +269,9 @@ DHWImportHooker &getDeleteHooker()
|
||||
|
||||
void __cdecl dhw_delete(void* p)
|
||||
{
|
||||
PRUint32 start = PR_IntervalNow();
|
||||
DHW_ORIGINAL(DELETE_, getDeleteHooker())(p);
|
||||
PRUint32 end = PR_IntervalNow();
|
||||
if (g_lockOut)
|
||||
return;
|
||||
g_lockOut = TRUE;
|
||||
@@ -267,7 +279,7 @@ void __cdecl dhw_delete(void* p)
|
||||
printf("* delete called for %#x\n", p);
|
||||
dumpStack();
|
||||
#endif
|
||||
FreeCallback(p);
|
||||
FreeCallback(p, start, end);
|
||||
// printf("\n");
|
||||
g_lockOut = FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user