Expose trace-malloc stack tracing. b=422847 r=brendan a=NPOTDB

This commit is contained in:
dbaron@dbaron.org 2008-03-14 17:11:37 -07:00
Родитель 5d05870000
Коммит db479f0ae5
2 изменённых файлов: 45 добавлений и 7 удалений

Просмотреть файл

@ -1656,6 +1656,18 @@ NS_TraceMallocLogTimestamp(const char *caption)
TM_EXIT_LOCK_AND_UNSUPPRESS_TRACING(t);
}
static void
print_stack(FILE *ofp, callsite *site)
{
while (site) {
if (site->name || site->parent) {
fprintf(ofp, "%s[%s +0x%X]\n",
site->name, site->library, site->offset);
}
site = site->parent;
}
}
static PRIntn
allocation_enumerator(PLHashEntry *he, PRIntn i, void *arg)
{
@ -1677,13 +1689,7 @@ allocation_enumerator(PLHashEntry *he, PRIntn i, void *arg)
fprintf(ofp, "\t0x%08lX\n", *p);
}
while (site) {
if (site->name || site->parent) {
fprintf(ofp, "%s[%s +0x%X]\n",
site->name, site->library, site->offset);
}
site = site->parent;
}
print_stack(ofp, site);
fputc('\n', ofp);
return HT_ENUMERATE_NEXT;
}
@ -1958,4 +1964,20 @@ FreeCallback(void * ptr, PRUint32 start, PRUint32 end, tm_thread *t)
TM_EXIT_LOCK_AND_UNSUPPRESS_TRACING(t);
}
PR_IMPLEMENT(nsTMStackTraceID)
NS_TraceMallocGetStackTrace(void)
{
callsite *site;
tm_thread *t = tm_get_thread();
site = backtrace(t, 2);
return (nsTMStackTraceID) site;
}
PR_IMPLEMENT(void)
NS_TraceMallocPrintStackTrace(FILE *ofp, nsTMStackTraceID id)
{
print_stack(ofp, (callsite *)id);
}
#endif /* NS_TRACE_MALLOC */

Просмотреть файл

@ -229,6 +229,22 @@ NS_TraceMallocFlushLogfiles(void);
PR_EXTERN(void)
NS_TrackAllocation(void* ptr, FILE *ofp);
/* opaque type for API */
typedef struct nsTMStackTraceIDStruct *nsTMStackTraceID;
/**
* Get an identifier for the stack trace of the current thread (to this
* function's callsite) that can be used to print that stack trace later.
*/
PR_EXTERN(nsTMStackTraceID)
NS_TraceMallocGetStackTrace(void);
/**
* Print the stack trace identified.
*/
PR_EXTERN(void)
NS_TraceMallocPrintStackTrace(FILE *ofp, nsTMStackTraceID id);
PR_END_EXTERN_C
#endif /* nsTraceMalloc_h___ */