mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Revamp REALLOC record for rayw's tool; add flush-log-files function (r=rayw, a=waterson, not part of build).
This commit is contained in:
parent
dcf94d699d
commit
4a242ba8a6
@ -895,21 +895,23 @@ __ptr_t calloc(size_t count, size_t size)
|
||||
|
||||
__ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
{
|
||||
callsite *oldsite, *site;
|
||||
size_t oldsize;
|
||||
PLHashNumber hash;
|
||||
PLHashEntry *he;
|
||||
allocation *alloc;
|
||||
callsite *site;
|
||||
|
||||
tmstats.realloc_calls++;
|
||||
if (suppress_tracing == 0) {
|
||||
if (tmmon)
|
||||
PR_EnterMonitor(tmmon);
|
||||
oldsite = NULL;
|
||||
oldsize = 0;
|
||||
if (ptr && get_allocations()) {
|
||||
hash = hash_pointer(ptr);
|
||||
he = *PL_HashTableRawLookup(allocations, hash, ptr);
|
||||
if (he) {
|
||||
oldsite = (callsite*) he->value;
|
||||
alloc = (allocation*) he;
|
||||
oldsize = alloc->size;
|
||||
}
|
||||
@ -938,8 +940,10 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
PR_EnterMonitor(tmmon);
|
||||
#endif
|
||||
site = backtrace(1);
|
||||
if (site)
|
||||
log_event3(logfp, TM_EVENT_REALLOC, site->serial, oldsize, size);
|
||||
if (site) {
|
||||
log_event4(logfp, TM_EVENT_REALLOC, site->serial, size,
|
||||
oldsite ? oldsite->serial : 0, oldsize);
|
||||
}
|
||||
if (ptr && allocations) {
|
||||
suppress_tracing++;
|
||||
he = PL_HashTableAdd(allocations, ptr, site);
|
||||
@ -1298,4 +1302,19 @@ NS_TraceMallocDumpAllocations(const char *pathname)
|
||||
return rv;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
NS_TraceMallocFlushLogfiles()
|
||||
{
|
||||
logfile *fp;
|
||||
|
||||
if (tmmon)
|
||||
PR_EnterMonitor(tmmon);
|
||||
|
||||
for (fp = logfile_list; fp; fp = fp->next)
|
||||
flush_logfile(fp);
|
||||
|
||||
if (tmmon)
|
||||
PR_ExitMonitor(tmmon);
|
||||
}
|
||||
|
||||
#endif /* NS_TRACE_MALLOC */
|
||||
|
@ -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\nTMLog03\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog04\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC_SIZE 16
|
||||
|
||||
/**
|
||||
@ -105,6 +105,9 @@ typedef struct nsTMStats {
|
||||
* Event Operands (magic TMLog03)
|
||||
* 'T' seconds, microseconds, caption
|
||||
*
|
||||
* Event Operands (magic TMLog04)
|
||||
* 'R' site serial, realloc size, old site serial, realloc oldsize
|
||||
*
|
||||
* See xpcom/base/bloatblame.c for an example log-file reader.
|
||||
*/
|
||||
#define TM_EVENT_LIBRARY 'L'
|
||||
@ -168,6 +171,12 @@ PR_EXTERN(void) NS_TraceMallocLogTimestamp(const char *caption);
|
||||
PR_EXTERN(int)
|
||||
NS_TraceMallocDumpAllocations(const char *pathname);
|
||||
|
||||
/**
|
||||
* Flush all logfile buffers.
|
||||
*/
|
||||
PR_EXTERN(void)
|
||||
NS_TraceMallocFlushLogfiles(void);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* nsTraceMalloc_h___ */
|
||||
|
@ -169,10 +169,12 @@ static int get_tmevent(FILE *fp, tmevent *event)
|
||||
break;
|
||||
|
||||
case TM_EVENT_REALLOC:
|
||||
if (!get_uint32(fp, &event->u.alloc.oldsize))
|
||||
return 0;
|
||||
if (!get_uint32(fp, &event->u.alloc.size))
|
||||
return 0;
|
||||
if (!get_uint32(fp, &event->u.alloc.oldserial))
|
||||
return 0;
|
||||
if (!get_uint32(fp, &event->u.alloc.oldsize))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case TM_EVENT_STATS:
|
||||
|
@ -65,8 +65,9 @@ struct tmevent {
|
||||
uint32 offset;
|
||||
} site;
|
||||
struct {
|
||||
uint32 oldsize;
|
||||
uint32 size;
|
||||
uint32 oldserial;
|
||||
uint32 oldsize;
|
||||
} alloc;
|
||||
struct {
|
||||
nsTMStats tmstats;
|
||||
|
@ -895,21 +895,23 @@ __ptr_t calloc(size_t count, size_t size)
|
||||
|
||||
__ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
{
|
||||
callsite *oldsite, *site;
|
||||
size_t oldsize;
|
||||
PLHashNumber hash;
|
||||
PLHashEntry *he;
|
||||
allocation *alloc;
|
||||
callsite *site;
|
||||
|
||||
tmstats.realloc_calls++;
|
||||
if (suppress_tracing == 0) {
|
||||
if (tmmon)
|
||||
PR_EnterMonitor(tmmon);
|
||||
oldsite = NULL;
|
||||
oldsize = 0;
|
||||
if (ptr && get_allocations()) {
|
||||
hash = hash_pointer(ptr);
|
||||
he = *PL_HashTableRawLookup(allocations, hash, ptr);
|
||||
if (he) {
|
||||
oldsite = (callsite*) he->value;
|
||||
alloc = (allocation*) he;
|
||||
oldsize = alloc->size;
|
||||
}
|
||||
@ -938,8 +940,10 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
|
||||
PR_EnterMonitor(tmmon);
|
||||
#endif
|
||||
site = backtrace(1);
|
||||
if (site)
|
||||
log_event3(logfp, TM_EVENT_REALLOC, site->serial, oldsize, size);
|
||||
if (site) {
|
||||
log_event4(logfp, TM_EVENT_REALLOC, site->serial, size,
|
||||
oldsite ? oldsite->serial : 0, oldsize);
|
||||
}
|
||||
if (ptr && allocations) {
|
||||
suppress_tracing++;
|
||||
he = PL_HashTableAdd(allocations, ptr, site);
|
||||
@ -1298,4 +1302,19 @@ NS_TraceMallocDumpAllocations(const char *pathname)
|
||||
return rv;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
NS_TraceMallocFlushLogfiles()
|
||||
{
|
||||
logfile *fp;
|
||||
|
||||
if (tmmon)
|
||||
PR_EnterMonitor(tmmon);
|
||||
|
||||
for (fp = logfile_list; fp; fp = fp->next)
|
||||
flush_logfile(fp);
|
||||
|
||||
if (tmmon)
|
||||
PR_ExitMonitor(tmmon);
|
||||
}
|
||||
|
||||
#endif /* NS_TRACE_MALLOC */
|
||||
|
@ -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\nTMLog03\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC "XPCOM\nTMLog04\r\n\032"
|
||||
#define NS_TRACE_MALLOC_MAGIC_SIZE 16
|
||||
|
||||
/**
|
||||
@ -105,6 +105,9 @@ typedef struct nsTMStats {
|
||||
* Event Operands (magic TMLog03)
|
||||
* 'T' seconds, microseconds, caption
|
||||
*
|
||||
* Event Operands (magic TMLog04)
|
||||
* 'R' site serial, realloc size, old site serial, realloc oldsize
|
||||
*
|
||||
* See xpcom/base/bloatblame.c for an example log-file reader.
|
||||
*/
|
||||
#define TM_EVENT_LIBRARY 'L'
|
||||
@ -168,6 +171,12 @@ PR_EXTERN(void) NS_TraceMallocLogTimestamp(const char *caption);
|
||||
PR_EXTERN(int)
|
||||
NS_TraceMallocDumpAllocations(const char *pathname);
|
||||
|
||||
/**
|
||||
* Flush all logfile buffers.
|
||||
*/
|
||||
PR_EXTERN(void)
|
||||
NS_TraceMallocFlushLogfiles(void);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* nsTraceMalloc_h___ */
|
||||
|
@ -1039,7 +1039,7 @@ nsTraceRefcnt::WalkTheStack(FILE* aStream)
|
||||
Dl_info info;
|
||||
int ok = dladdr((void*) pc, &info);
|
||||
if (!ok) {
|
||||
fprintf(aStream, "UNKNOWN 0x%08X\n", (char*)pc);
|
||||
fprintf(aStream, "UNKNOWN 0x%8p\n", (char*)pc);
|
||||
bp = nextbp;
|
||||
continue;
|
||||
}
|
||||
|
@ -1039,7 +1039,7 @@ nsTraceRefcnt::WalkTheStack(FILE* aStream)
|
||||
Dl_info info;
|
||||
int ok = dladdr((void*) pc, &info);
|
||||
if (!ok) {
|
||||
fprintf(aStream, "UNKNOWN 0x%08X\n", (char*)pc);
|
||||
fprintf(aStream, "UNKNOWN 0x%8p\n", (char*)pc);
|
||||
bp = nextbp;
|
||||
continue;
|
||||
}
|
||||
|
@ -169,10 +169,12 @@ static int get_tmevent(FILE *fp, tmevent *event)
|
||||
break;
|
||||
|
||||
case TM_EVENT_REALLOC:
|
||||
if (!get_uint32(fp, &event->u.alloc.oldsize))
|
||||
return 0;
|
||||
if (!get_uint32(fp, &event->u.alloc.size))
|
||||
return 0;
|
||||
if (!get_uint32(fp, &event->u.alloc.oldserial))
|
||||
return 0;
|
||||
if (!get_uint32(fp, &event->u.alloc.oldsize))
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case TM_EVENT_STATS:
|
||||
|
@ -65,8 +65,9 @@ struct tmevent {
|
||||
uint32 offset;
|
||||
} site;
|
||||
struct {
|
||||
uint32 oldsize;
|
||||
uint32 size;
|
||||
uint32 oldserial;
|
||||
uint32 oldsize;
|
||||
} alloc;
|
||||
struct {
|
||||
nsTMStats tmstats;
|
||||
|
Loading…
Reference in New Issue
Block a user