示例#1
0
            public SnapShot(Log log, int index, SnapShot prev)
            {
                if (prev.mIndex > index)
                    throw new Exception("Snapshot passed needs to be behind current one");

                mIndex = index;
                Utility.AllocLists li;

                mAllocListsMutex.WaitOne();
                if (mAllocListsLastIndex == prev.mIndex)
                {
                    li = mAllocLists;
                    mAllocListsMutex.ReleaseMutex();
                }
                else
                {
                    mAllocListsMutex.ReleaseMutex();

                    // Populate snapshot with previous snapshot
                    li = new Utility.AllocLists();
                    for (int i = 0; i < prev.mArray.Count; i++)
                    {
                        int idx = (int)(prev.mArray[i]);
                        uint address = log[idx].address;
                        li.Allocate( address, idx );
                    }
                }

                // Play through allocations till index reached.
                for (int i = prev.mIndex; i < index; i++)
                {
                    LogEntry logentry = log[i];
                    if (logentry.type == 'A')
                        li.Allocate(logentry.address, i);
                    else if (logentry.type == 'F')
                        li.Free(logentry.address);
                }

                // Now store as an array
                mArray = li.GetArray();
                mSorted = false;

                mAllocListsMutex.WaitOne();
                mAllocListsLastIndex = index;
                mAllocLists = li;
                mAllocListsMutex.ReleaseMutex();
            }
示例#2
0
            // fixes up unassigned field for each "Free" log entry.
            public void FixupLog(Log log)
            {
                Utility.AllocLists li = new Utility.AllocLists();
                int index = log.Count;
                try
                {
                    for (int i = 0; i < index; i++)
                    {
                        LogEntry logentry = log[i];
                        if (logentry.type == 'A')
                        {
                            if (i != logentry.index)
                                System.Diagnostics.Debug.Print("indices don't match: {0} != {1}\n", i, logentry.index);
                            li.Allocate(logentry.address, (int)logentry.index);
                        }
                        else if (logentry.type == 'F')
                        {
                            int idx = li.Free(logentry.address);
                            if (idx > 0)
                            {
                                //  ((LogEntry)log[idx]).allocSize = logentry.allocSize;
                                logentry.category = ((LogEntry)log[idx]).category;
                                logentry.allocator = ((LogEntry)log[idx]).allocator;
                              //  System.Diagnostics.Debug.Assert(((LogEntry)log[idx]).allocSize == logentry.allocSize, "ERROR! Allocated and deleted sizes don't match");
                            }
                            else
                            {
                                // System.Diagnostics.Debug.Print("Missing alloc! For now 'disable' this Free by setting its size and address to 0");
                                ((LogEntry)log[i]).allocSize = ((LogEntry)log[i]).address = 0;
                                //   removeFrees.Add(logentry.index);
                            }
                        }
                    }

                    log.mLogFixed = true;
                }
                catch (System.ArgumentOutOfRangeException)
                {
                    System.Diagnostics.Debug.Print("!!System.ArgumentOutOfRangeException");
                }
            }
示例#3
0
            public SnapShot(Log log, int index)
            {
                mIndex = index;
                Utility.AllocLists li = new Utility.AllocLists();

                // Play thru allocations till index reached.
                for (int i = 0; i < index; i++)
                {
                    LogEntry logentry = log[i];
                    if (logentry.type == 'A')
                        li.Allocate(logentry.address, i);
                    else if (logentry.type == 'F')
                        li.Free(logentry.address);
                }

                // Now store as an array
                mArray = li.GetArray();
                mSorted = false;
                mAllocListsMutex.WaitOne();
                mAllocListsLastIndex = index;
                mAllocLists = li;
                mAllocListsMutex.ReleaseMutex();
            }
示例#4
0
            public SnapShot(Log log, SnapShot snap, string filter, int size, bool dir)
            {
                Utility.AllocLists li = new Utility.AllocLists();
                Regex r = new Regex(filter, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                for (int i = 0, e = snap.Count; i < e; i++)
                {
                    int logindex = snap[i];
                    MemManager.Log.LogEntry le = log[logindex];

                    string name = log.GetString(le.nameString);
                    if ( r.IsMatch(log.GetString(le.nameString)) )
                    {
                        if(size == 0)
                            li.Allocate(log[logindex].address, logindex);
                        else if(dir==false && le.allocSize >= size)
                            li.Allocate(log[logindex].address, logindex);
                        else if(dir==true && le.allocSize <= size)
                            li.Allocate(log[logindex].address, logindex);
                    }
                }

                mArray = li.GetArray(ref mMaxLogIndex);
                mArray.Sort();
            }
示例#5
0
            //-------------------------------------------------------------------------
            void PopulateFreeInformation()
            {
                uint rangeStart = 0;
                uint rangeEnd = 0;
                if(mLog.Count > 0)
                {
                    rangeEnd = rangeStart = mLog[0].address;
                }
                Utility.AllocLists al = new Utility.AllocLists();
                for (int i = 0; i < mLog.Count; i++)
                {
                    LogEntry l = mLog[i];
                    if (l.type == 'A')
                    {
                        rangeStart = l.address < rangeStart ? l.address : rangeStart;
                        rangeEnd = (l.address + l.allocSize) > rangeEnd ? (l.address + l.allocSize) : rangeEnd;
                        al.Allocate(l.address, i);
                    }
                    else if (l.type == 'F')
                    {
                        int index = al.Free(l.address);
                        LogEntry logentry = mLog[ index ];
                        //l.alignment = logentry.alignment;
                        l.allocSize = logentry.allocSize;
                        l.nameString = logentry.nameString;
                        l.index = logentry.index;
                    //	l.reqSize = logentry.reqSize;
                        l.category = logentry.category;
                        l.allocator = logentry.allocator;
                    }
                }

                // this is a fix for cases when we don't know the range for heap. Assumption here is that there is only one heap (i.e. Allocator)
                foreach (LogEntryAllocators e in mLog.GetAllocatorList())
                {
                    if(e.mStartAddress == 0 && e.mEndAddress == 0)
                    {
                        e.mStartAddress = rangeStart;
                        e.mEndAddress = rangeEnd;
                    }
                }
            }
示例#6
0
            public SnapShot(Log log, int index, bool addressSorted)
            {
                if (!log.mLogFixed)
                    FixupLog(log);

                mIndex = index;
                Utility.AllocLists li = new Utility.AllocLists();
                // Play through allocations till index reached.
                for (int i = 0; i < index; i++)
                {
                    LogEntry logentry = log[i];
                    if (logentry.type == 'A')
                    {
                        li.Allocate(logentry.address, (int)logentry.index);
                    }
                    else if (logentry.type == 'F')
                    {
                        int idx = li.Free(logentry.address);
                    }
                }

                // Now store as an array
                if (addressSorted)
                    mArray = li.GetArrayAddressSorted(ref mMaxLogIndex);
                else
                {
                    mArray = li.GetArray(ref mMaxLogIndex);
                    mArray.Sort(new CompareIndices());
                }

                mSorted = false;
                mAllocListsMutex.WaitOne();
                mAllocListsLastIndex = index;
                mAllocLists = li;
                mAllocListsMutex.ReleaseMutex();
            }
示例#7
0
            public SnapShot(Log log, int index, SnapShot prev, bool diff)
            {
                if (prev.mIndex > index)
                {
                    System.Diagnostics.Debug.Print("Second selection must be on the right hand side of the first one to compare");
                    //throw new Exception("Snapshot passed needs to be behind current one");
                    return;
                }

                mIndex = index;
                Utility.AllocLists li;
                if (!diff)
                {
                    mAllocListsMutex.WaitOne();
                    if (mAllocListsLastIndex == prev.mIndex)
                    {
                        li = mAllocLists;
                        mAllocListsMutex.ReleaseMutex();
                    }
                    else
                    {
                        mAllocListsMutex.ReleaseMutex();

                        // Populate snapshot with previous snapshot
                        li = new Utility.AllocLists();
                        for (int i = 0; i < prev.mArray.Count; i++)
                        {
                            int idx = (int)(prev.mArray[i]);
                            uint address = log[idx].address;
                            li.Allocate(address, idx);
                        }
                    }
                }
                else
                    li = new MemManager.Utility.AllocLists();

                // Play through allocations till index reached.
                for (int i = prev.mIndex; i < index; i++)
                {
                    LogEntry logentry = log[i];
                    if (logentry.type == 'A')
                        li.Allocate(logentry.address, i);
                    else if (logentry.type == 'F')
                        li.Free(logentry.address);
                }

                // Now store as an array
                mArray = li.GetArray(ref mMaxLogIndex);
                mSorted = false;

                mAllocListsMutex.WaitOne();
                mAllocListsLastIndex = index;
                mAllocLists = li;
                mAllocListsMutex.ReleaseMutex();
            }