STAllocation* allocationTracker(PRUint32 aTimeval, char aType, tmcallsite* aCallsite, PRUint32 aHeapID, PRUint32 aSize, tmcallsite* aOldCallsite, PRUint32 aOldHeapID, PRUint32 aOldSize)
STAllocation* allocationTracker(PRUint32 aTimeval, char aType, PRUint32 aHeapRuntimeCost, tmcallsite* aCallsite, PRUint32 aHeapID, PRUint32 aSize, tmcallsite* aOldCallsite, PRUint32 aOldHeapID, PRUint32 aOldSize)
STAllocation* allocationTracker(PRUint32 aTimeval, char aType, tmcallsite* aCallsite, PRUint32 aHeapID, PRUint32 aSize, tmcallsite* aOldCallsite, PRUint32 aOldHeapID, PRUint32 aOldSize){    STAllocation* retval = NULL;    static int compactor = 1;    const int frequency = 10000;    if(NULL != aCallsite)    {        int newAllocation = 0;        tmcallsite* searchCallsite = NULL;        PRUint32 searchHeapID = 0;        STAllocation* allocation = NULL;        /*        ** Global operation ID increases.        */        globals.mOperationCount++;        /*        ** Fix up the timevals if needed.        */        if(aTimeval < globals.mMinTimeval)        {            globals.mMinTimeval = aTimeval;        }        if(aTimeval > globals.mMaxTimeval)        {            globals.mMaxTimeval = aTimeval;        }        switch(aType)        {            case TM_EVENT_FREE:            {                /*                ** Update the global counter.                */                globals.mFreeCount++;                /*                ** Not a new allocation, will need to search passed in site                **  for the original allocation.                */                searchCallsite = aCallsite;                searchHeapID = aHeapID;            }            break;            case TM_EVENT_MALLOC:            {                /*                ** Update the global counter.                */                globals.mMallocCount++;                /*                ** This will be a new allocation.                */                newAllocation = __LINE__;            }            break;            case TM_EVENT_CALLOC:            {                /*                ** Update the global counter.                */                globals.mCallocCount++;                /*                ** This will be a new allocation.                */                newAllocation = __LINE__;            }            break;            case TM_EVENT_REALLOC:            {                /*                ** Update the global counter.                */                globals.mReallocCount++;                /*                ** This might be a new allocation.                */                if(NULL == aOldCallsite)                {                    newAllocation = __LINE__;                }                else                {                    /*                    ** Need to search for the original callsite for the                    **  index to the allocation.                    */                    searchCallsite = aOldCallsite;                    searchHeapID = aOldHeapID;                }            }            break;            default:            {                REPORT_ERROR(__LINE__, allocationTracker);            }            break;        }        /*        ** We are either modifying an existing allocation or we are creating        **  a new one.        */        if(0 != newAllocation)        {            allocation = (STAllocation*)calloc(1, sizeof(STAllocation));            if(NULL != allocation)            {                /*                ** Fixup the min timeval so if logic later will just work.                */                allocation->mMinTimeval = ST_TIMEVAL_MAX;                allocation->mMaxTimeval = ST_TIMEVAL_MAX;            }        }        else if(NULL != searchCallsite && NULL != CALLSITE_RUN(searchCallsite) && 0 != searchHeapID)        {            /*            ** We know what to search for, and we reduce what we search            **  by only looking for those allocations at a known callsite.            */            allocation = getLiveAllocationByHeapID(CALLSITE_RUN(searchCallsite), searchHeapID);        }        else        {            REPORT_ERROR(__LINE__, allocationTracker);        }        if(NULL != allocation)        {            STAllocEvent* appendResult = NULL;            /*            ** Now that we have an allocation, we need to make sure it has            **  the proper event.            */            appendResult = appendEvent(allocation, aTimeval, aType, aHeapID, aSize, aCallsite);            if(NULL != appendResult)            {                if(0 != newAllocation)                {                    int runAppendResult = 0;                    int callsiteAppendResult = 0;                    /*                    ** A new allocation needs to be added to the global run.                    ** A new allocation needs to be added to the callsite.                    */                    runAppendResult = appendAllocation(&(globals.mRun), allocation);                    callsiteAppendResult = appendAllocation(CALLSITE_RUN(aCallsite), allocation);                    if(0 != runAppendResult && 0 != callsiteAppendResult)                    {                        /*                        ** Success.                        */                        retval = allocation;                    }                    else                    {                        REPORT_ERROR(__LINE__, appendAllocation);                    }                }                else                {                    /*                    ** An existing allocation, if a realloc situation,                    **  may need to be added to the new callsite.                    ** This can only occur if the new and old callsites                    **  differ.                    ** Even then, a brute force check will need to be made                    **  to ensure the allocation was not added twice;                     **  consider a realloc scenario where two different                    **  call stacks bump the allocation back and forth.                    */                    if(aCallsite != searchCallsite)                    {                        int found = 0;                        found = hasAllocation(CALLSITE_RUN(aCallsite), allocation);                        if(0 == found)                        {                            int appendResult = 0;                            appendResult = appendAllocation(CALLSITE_RUN(aCallsite), allocation);                            if(0 != appendResult)                            {                                /*                                ** Success.                                */                                retval = allocation;                            }                            else                            {                                REPORT_ERROR(__LINE__, appendAllocation);                            }                        }                        else                        {                            /*                            ** Already there.                            */                            retval = allocation;                        }                    }                    else                    {                        /*                        ** Success.                        */                        retval = allocation;                    }                }            }            else            {                REPORT_ERROR(__LINE__, appendEvent);            }        }        else        {            REPORT_ERROR(__LINE__, allocationTracker);        }    }    else    {        REPORT_ERROR(__LINE__, allocationTracker);    }    /*    ** Compact the heap a bit if you can.    */    compactor++;    if(0 == (compactor % frequency))    {        heapCompact();    }    return retval;}