Commit 1ef06c2b authored by blythe%netscape.com's avatar blythe%netscape.com
Browse files

Fix bug 114149, trace-malloc output platform specific

r=dp, sr=brendan
parent e16686b0
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@

#endif /* WIN32 */

/*
 * Record the intervals in a platform independent manner.
 */
#define MILLISECONDS_NOW PR_IntervalToMilliseconds(PR_IntervalNow())

#ifdef XP_UNIX
#define WRITE_FLAGS "w"
@@ -1385,7 +1389,7 @@ __ptr_t malloc(size_t size)
        site = backtrace(1);
        if (site)
            log_event4(logfp, TM_EVENT_MALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -1418,7 +1422,7 @@ __ptr_t calloc(size_t count, size_t size)
        size *= count;
        if (site)
            log_event4(logfp, TM_EVENT_CALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -1476,7 +1480,7 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
        site = backtrace(1);
        if (site) {
            log_event7(logfp, TM_EVENT_REALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size,
                       oldsite ? oldsite->serial : 0,
                       (uint32)NS_PTR_TO_INT32(oldptr), oldsize);
@@ -1532,7 +1536,7 @@ void free(__ptr_t ptr)
                if (site) {
                    alloc = (allocation*) he;
                    log_event4(logfp, TM_EVENT_FREE,
                               site->serial, PR_IntervalNow(),
                               site->serial, MILLISECONDS_NOW,
                               (uint32)NS_PTR_TO_INT32(ptr), alloc->size);
                }
                PL_HashTableRawRemove(allocations, hep, he);
@@ -1967,7 +1971,7 @@ MallocCallback(void *ptr, size_t size)
        site = backtrace(4);
        if (site)
            log_event4(logfp, TM_EVENT_MALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -1998,7 +2002,7 @@ CallocCallback(void *ptr, size_t count, size_t size)
        size *= count;
        if (site)
            log_event4(logfp, TM_EVENT_CALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -2050,7 +2054,7 @@ ReallocCallback(void * oldptr, void *ptr, size_t size)
        site = backtrace(1);
        if (site) {
            log_event7(logfp, TM_EVENT_REALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size,
                       oldsite ? oldsite->serial : 0,
                       (uint32)NS_PTR_TO_INT32(oldptr), oldsize);
@@ -2105,7 +2109,7 @@ FreeCallback(void * ptr)
                if (site) {
                    alloc = (allocation*) he;
                    log_event4(logfp, TM_EVENT_FREE,
                               site->serial, PR_IntervalNow(),
                               site->serial, MILLISECONDS_NOW,
                               (uint32)NS_PTR_TO_INT32(ptr), alloc->size);
                }
                PL_HashTableRawRemove(allocations, hep, he);
+1 −16
Original line number Diff line number Diff line
@@ -2211,23 +2211,8 @@ void tmEventHandler(tmreader* aReader, tmevent* aEvent)
                    */
                    if(NULL != CALLSITE_RUN(callsite))
                    {
                        static PRIntervalTime sec2int = 0;
                        PRUint32 timeval = 0;
                        PRUint64 timeval64 = LL_INIT(0, 0);
                        char eventType = aEvent->type;
                        
                        if(0 == sec2int)
                        {
                            sec2int = PR_SecondsToInterval(1);
                        }

                        /*
                        ** Convert the interval to a timeval.
                        */
                        LL_MUL(timeval64, (PRUint64)aEvent->u.alloc.interval, (PRUint64)ST_TIMEVAL_RESOLUTION);
                        LL_DIV(timeval64, timeval64, (PRUint64)sec2int);
                        LL_L2UI(timeval, timeval64);

                        /*
                        ** Play a nasty trick on reallocs of size zero.
                        ** They are to become free events.
@@ -2237,7 +2222,7 @@ void tmEventHandler(tmreader* aReader, tmevent* aEvent)
                        {
                            eventType = TM_EVENT_FREE;
                        }
                        trackEvent(timeval, eventType, callsite, aEvent->u.alloc.ptr, aEvent->u.alloc.size, oldcallsite, oldptr, oldsize);
                        trackEvent(aEvent->u.alloc.interval, eventType, callsite, aEvent->u.alloc.ptr, aEvent->u.alloc.size, oldcallsite, oldptr, oldsize);
                    }
                }
                else
+2 −3
Original line number Diff line number Diff line
@@ -114,9 +114,8 @@

/*
** Set the desired resolution of the timevals.
** Too large, and you'll wrap uint32.
** A value of 1 would mean report in seconds.
** A value of 1000 would mean to report in milliseconds.
** The resolution is just mimicking what is recorded in the trace-malloc
**  output, and that is currently milliseconds.
*/
#define ST_TIMEVAL_RESOLUTION 1000
#define ST_TIMEVAL_FORMAT "%.3f"
+12 −8
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@

#endif /* WIN32 */

/*
 * Record the intervals in a platform independent manner.
 */
#define MILLISECONDS_NOW PR_IntervalToMilliseconds(PR_IntervalNow())

#ifdef XP_UNIX
#define WRITE_FLAGS "w"
@@ -1385,7 +1389,7 @@ __ptr_t malloc(size_t size)
        site = backtrace(1);
        if (site)
            log_event4(logfp, TM_EVENT_MALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -1418,7 +1422,7 @@ __ptr_t calloc(size_t count, size_t size)
        size *= count;
        if (site)
            log_event4(logfp, TM_EVENT_CALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -1476,7 +1480,7 @@ __ptr_t realloc(__ptr_t ptr, size_t size)
        site = backtrace(1);
        if (site) {
            log_event7(logfp, TM_EVENT_REALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size,
                       oldsite ? oldsite->serial : 0,
                       (uint32)NS_PTR_TO_INT32(oldptr), oldsize);
@@ -1532,7 +1536,7 @@ void free(__ptr_t ptr)
                if (site) {
                    alloc = (allocation*) he;
                    log_event4(logfp, TM_EVENT_FREE,
                               site->serial, PR_IntervalNow(),
                               site->serial, MILLISECONDS_NOW,
                               (uint32)NS_PTR_TO_INT32(ptr), alloc->size);
                }
                PL_HashTableRawRemove(allocations, hep, he);
@@ -1967,7 +1971,7 @@ MallocCallback(void *ptr, size_t size)
        site = backtrace(4);
        if (site)
            log_event4(logfp, TM_EVENT_MALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -1998,7 +2002,7 @@ CallocCallback(void *ptr, size_t count, size_t size)
        size *= count;
        if (site)
            log_event4(logfp, TM_EVENT_CALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size);
        if (get_allocations()) {
            suppress_tracing++;
@@ -2050,7 +2054,7 @@ ReallocCallback(void * oldptr, void *ptr, size_t size)
        site = backtrace(1);
        if (site) {
            log_event7(logfp, TM_EVENT_REALLOC,
                       site->serial, PR_IntervalNow(),
                       site->serial, MILLISECONDS_NOW,
                       (uint32)NS_PTR_TO_INT32(ptr), size,
                       oldsite ? oldsite->serial : 0,
                       (uint32)NS_PTR_TO_INT32(oldptr), oldsize);
@@ -2105,7 +2109,7 @@ FreeCallback(void * ptr)
                if (site) {
                    alloc = (allocation*) he;
                    log_event4(logfp, TM_EVENT_FREE,
                               site->serial, PR_IntervalNow(),
                               site->serial, MILLISECONDS_NOW,
                               (uint32)NS_PTR_TO_INT32(ptr), alloc->size);
                }
                PL_HashTableRawRemove(allocations, hep, he);