コード例 #1
0
        public void InitAllocationPoints(List <MemOperation> memOps)
        {
            MemBlockTree tree     = new MemBlockTree();
            uint         totalMem = 0;

            foreach (MemOperation op in memOps)
            {
                if (op.OpType == MemOperation.Type.Alloc)
                {
                    MemBlock block = op.UserData as MemBlock;
                    tree.AddMemBlock(block);
                    totalMem += block.m_size;
                }
            }
            foreach (MemOperation op in memOps)
            {
                if (op.OpType == MemOperation.Type.Alloc)
                {
                    AddAllocationPoint(op.UserData as MemBlock, tree);
                }
            }

            for (int i = 0; i < dataGridAllocs.Rows.Count; ++i)
            {
                AllocInfo allocInfo  = dataGridAllocs.Rows[i].Tag as AllocInfo;
                float     percentage = allocInfo.numBytes * 100.0f / totalMem;
                String[]  rowData    = { allocInfo.symbol.functionName, allocInfo.numBytes.ToString(), allocInfo.numBlocks.ToString(),
                                         percentage.ToString() };
                dataGridAllocs.Rows[i].SetValues(rowData);
            }
        }
コード例 #2
0
        MemBlock[] CollectLargestBlocks(MemSnapshot snap, int n)
        {
            MemBlock[] largestBlocks = new MemBlock[snap.Blocks.Values.Count];
            int        i             = 0;

            foreach (MemBlock block in snap.Blocks.Values)
            {
                largestBlocks[i++] = block;
            }
            Array.Sort(largestBlocks, new CompareBySize());

            /*for (int i = 0; i < largestBlocks.Length; ++i)
             * {
             *  if (largestBlocks[i] != null && largestBlocks[i].m_size == block.m_size)
             *      break;
             *
             *  if (largestBlocks[i] == null)
             *  {
             *      largestBlocks[i] = block;
             *      break;
             *  }
             *  if (largestBlocks[i].m_size < block.m_size)
             *  {
             *      for (int j = i + 1; j < largestBlocks.Length; ++j)
             *          largestBlocks[j] = largestBlocks[j - 1];
             *      largestBlocks[i] = block;
             *      break;
             *  }
             * }
             * }*/
            return(largestBlocks);
        }
コード例 #3
0
ファイル: MemSnapshot.cs プロジェクト: polytronicgr/memtracer
        public void AddBlock(MemBlock block)
        {
            ///System.Console.Out.Write("Adding " + block.m_address.ToString("X") + "\n");

            /*MemBlock block2 = null;
             * if (m_blocks.TryGetValue(block.m_address, out block2))
             * {
             *  StackTracer.Symbol[] sym2 = new StackTracer.Symbol[block2.m_callStack.Count];
             *  for (int i = 0; i < block2.m_callStack.Count; ++i)
             *      sym2[i] = StackTracer.GetSymbolForAddress(block2.m_callStack[i]);
             *  int k = 1;
             * }*/

            if (m_blocks.ContainsKey(block.m_address))
            {
                return;
            }
            else
            {
                m_blocks.Add(block.m_address, block);
                m_allocatedBytes += block.m_size;
                if (m_blocks.Count > m_topAllocatedBlocks)
                {
                    m_topAllocatedBlocks = m_blocks.Count;
                }
                if (m_allocatedBytes > m_topAllocatedBytes)
                {
                    m_topAllocatedBytes = m_allocatedBytes;
                }
                if (block.m_size > m_largestAllocation)
                {
                    m_largestAllocation = block.m_size;
                }
            }
        }
コード例 #4
0
        private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
            {
                DataGridViewCell cell     = dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
                MemBlock         block    = dataGridView2.Rows[e.RowIndex].Tag as MemBlock;
                string           ttText   = "";
                string           blockTag = block.GetTagString();
                if (blockTag.Length > 0)
                {
                    ttText = ttText + "Tag: " + blockTag + "\n----------------------\n";
                }

                ulong[] callStack = CallstackTab.GetCallStack(block.m_callStackCRC);
                for (int i = 0; i < callStack.Length; ++i)
                {
                    IStackTracer.Symbol symbol = MemTracerForm.ms_MainForm.StackTracer.GetSymbolForAddress(callStack[i]);
                    if (symbol.functionName != null)
                    {
                        ttText = ttText + symbol.functionName + "\n";
                    }
                }
                cell.ToolTipText = ttText;
            }
        }
コード例 #5
0
        public void AddMemBlock(MemBlock block)
        {
            if (BottomUp)
            {
                AddMemBlockBottomUp(block);
                return;
            }

            if (m_subtreeRoot != 0 && !block.DoesCallStackContainAddress(m_subtreeRoot))
            {
                return;
            }

            int rootIndex = block.FindFirstValidSymbolIndex();

            if (rootIndex < 0)
            {
                return;
            }

            Node root = m_root;

            if (Tagged)
            {
                root = FindRootForTag(block.m_tag);
                if (root == null)
                {
                    root = m_root.AddTaggedChild(block.m_tag, block.m_tagCRC);
                }
            }

            ulong[]      callStack   = CallstackTab.GetCallStack(block.m_callStackCRC);
            Node         rootNode    = root.FindChildByCallAddress(callStack[rootIndex], true);
            IStackTracer stackTracer = MemTracerForm.ms_MainForm.StackTracer;

            if (rootNode == null)
            {
                IStackTracer.Symbol symbol = stackTracer.GetSymbolForAddress(callStack[rootIndex]);
                rootNode = root.AddChild(symbol);
            }
            Node parentNode = rootNode;

            for (int i = rootIndex + 1; i < callStack.Length; ++i)
            {
                ulong callAddress = callStack[i];
                Node  thisNode    = parentNode.FindChildByCallAddress(callAddress, false);

                if (thisNode == null)
                {
                    thisNode = parentNode.AddChild(stackTracer.GetSymbolForAddress(callAddress));
                }
                if (i == callStack.Length - 1)
                {
                    thisNode.m_allocatedSize += block.m_size;
                    ++thisNode.m_allocatedBlocks;
                }
                parentNode = thisNode;
            }
        }
コード例 #6
0
            public Node AddChildDetailed(MemBlock block)
            {
                DetailedNode child = new DetailedNode();

                child.m_parent = this;
                child.m_block  = block;
                m_children.Add(child);
                return(child);
            }
コード例 #7
0
ファイル: MemSnapshot.cs プロジェクト: polytronicgr/memtracer
        public void TagBlock(ulong address, ulong tag)
        {
            MemBlock block = null;

            if (m_blocks.TryGetValue(address, out block))
            {
                block.m_tag    = tag;
                block.m_tagCRC = true;
            }
        }
コード例 #8
0
 public int MemOperationNrForBlock(MemBlock block)
 {
     for (int i = 0; i < m_memOperations.Count; ++i)
     {
         if (m_memOperations[i].OpType == MemOperation.Type.Alloc && m_memOperations[i].UserData == block)
         {
             return(i);
         }
     }
     return(-1);
 }
コード例 #9
0
ファイル: MemOpTree.cs プロジェクト: polytronicgr/memtracer
 bool WasFreed(MemBlock mb)
 {
     foreach (MemOperation op in m_memOps)
     {
         if (op.OpType == MemOperation.Type.Free)
         {
             uint address = (uint)op.UserData;
             if (address == mb.m_address)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #10
0
        void AddAllocationPoint(MemBlock block, MemBlockTree tree)
        {
            int rootIndex = block.FindFirstValidSymbolIndex();

            if (rootIndex < 0)
            {
                return;
            }

            ulong[] callStack = CallstackTab.GetCallStack(block.m_callStackCRC);
            for (int i = rootIndex; i < callStack.Length; ++i)
            {
                IStackTracer.Symbol symbol = MemTracerForm.ms_MainForm.StackTracer.GetSymbolForAddress(callStack[i]);
                if (symbol.functionName == null)
                {
                    continue;
                }
                int rowIndex = FindRowIndexForCallerAddress(callStack[i]);
                if (rowIndex >= 0)
                {
                    //AllocInfo allocInfo = dataGridAllocs.Rows[rowIndex].Tag as AllocInfo;
                    //allocInfo.numBytes += (int)block.m_size;
                    //++allocInfo.numBlocks;
                }
                else
                {
                    //MemBlockTree.Node node = tree.Root.FindChildByCallAddress(callStack[i], true);
                    List <MemBlockTree.Node> nodes = new List <MemBlockTree.Node>();
                    tree.Root.CollectChildrenByCallAddress(callStack[i], true, nodes);

                    AllocInfo allocInfo = new AllocInfo();
                    allocInfo.symbol  = symbol;
                    allocInfo.address = callStack[i];

                    foreach (MemBlockTree.Node node in nodes)
                    {
                        allocInfo.numBytes  += (int)node.GetAllocatedSize();
                        allocInfo.numBlocks += node.GetNumAllocatedBlocks();
                    }

                    String[] rowData = { symbol.functionName, allocInfo.numBytes.ToString(), allocInfo.numBlocks.ToString(), "" };
                    dataGridAllocs.Rows.Add(rowData);
                    //allocInfo.numBytes = (int)node.GetAllocatedSize();
                    //allocInfo.numBlocks = node.GetNumAllocatedBlocks();
                    dataGridAllocs.Rows[dataGridAllocs.Rows.Count - 1].Tag = allocInfo;
                }
            }
        }
コード例 #11
0
ファイル: MemSnapshot.cs プロジェクト: polytronicgr/memtracer
        public void RemoveBlock(ulong address)
        {
            //System.Console.Out.Write("Freeing " + address.ToString("X") + "\n");
            MemBlock block = null;

            if (m_blocks.TryGetValue(address, out block))
            {
                m_blocks.Remove(address);
                m_allocatedBytes -= block.m_size;
            }
            else
            {
                //int breakHere = 1;
                //System.Console.Out.Write("Cant free " + address.ToString("X") + "\n");
            }
        }
コード例 #12
0
        public void InitLargestBlocks(List <MemOperation> memOps, int numBlocks)
        {
            MemBlock[] largestBlocks = new MemBlock[numBlocks];
            foreach (MemOperation op in memOps)
            {
                if (op.OpType == MemOperation.Type.Alloc)
                {
                    MemBlock block = op.UserData as MemBlock;
                    int      i;
                    bool     alreadyPresent = false;
                    for (i = 0; i < largestBlocks.Length; ++i)
                    {
                        if (largestBlocks[i] != null && block.m_size == largestBlocks[i].m_size)
                        {
                            alreadyPresent = true;
                        }
                        if (largestBlocks[i] != null && block.m_size < largestBlocks[i].m_size)
                        {
                            break;
                        }
                    }
                    if (!alreadyPresent)
                    {
                        for (int j = 1; j < i; ++j)
                        {
                            largestBlocks[j - 1] = largestBlocks[j];
                        }
                        largestBlocks[(i == 0 ? i : i - 1)] = block;
                    }
                }
            }
            for (int i = 0; i < largestBlocks.Length; ++i)
            {
                if (largestBlocks[i] != null)
                {
                    string[] data = { largestBlocks[i].m_size.ToString() };
                    dataGridView2.Rows.Add(data);
                    dataGridView2.Rows[dataGridView2.Rows.Count - 1].Tag = largestBlocks[i];
                }
            }

            Sort();
        }
コード例 #13
0
ファイル: MemOpTree.cs プロジェクト: polytronicgr/memtracer
        void AddAlloc(MemBlock mb)
        {
            string opText = "Alloc: " + mb.m_size + " byte(s) at " + mb.m_address.ToString("X") + " (" +
                            mb.GetTagString() + ")";

            treeView1.Nodes.Add(opText);
            TreeNode n = treeView1.Nodes[treeView1.Nodes.Count - 1];

            ulong[] callStack = CallstackTab.GetCallStack(mb.m_callStackCRC);
            foreach (uint callStackEntry in callStack)
            {
                IStackTracer.Symbol symbol = MemTracerForm.ms_MainForm.StackTracer.GetSymbolForAddress(callStackEntry);
                if (symbol.functionName != null)
                {
                    n.Nodes.Add(symbol.functionName);
                    n = n.Nodes[n.Nodes.Count - 1];
                }
            }
            ++m_numAllocated;
            m_bytesAllocated += mb.m_size;
        }
コード例 #14
0
        private void HandleAlloc(byte[] msgData)
        {
            MemBlock memBlock    = new MemBlock();
            int      addressSize = 4;

            if (m_64bit)
            {
                addressSize = 8;
            }

            memBlock.m_address = GetAddress(msgData, 1);
            memBlock.m_size    = GetInt(msgData, 1 + addressSize);
            memBlock.m_tag     = GetInt(msgData, 1 + addressSize + 4);
            int stackDepth = (int)msgData[1 + addressSize + 8];

            System.Diagnostics.Debug.Assert(stackDepth > 0 && stackDepth < 100);
            ulong[] callStack      = new ulong[stackDepth];
            int     callstackStart = 1 + addressSize + 9;

            for (int i = 0; i < stackDepth; ++i)
            {
                callStack[i] = GetAddress(msgData, callstackStart + i * addressSize);
            }
            memBlock.m_callStackCRC = CallstackTab.CalcCRC(callStack);
            CallstackTab.AddCallStack(memBlock.m_callStackCRC, callStack);

            if (m_initialized)
            {
                MemOperation op = new MemOperation(MemOperation.Type.Alloc);
                op.UserData = memBlock;
                m_memOperations.Add(op);
                m_globalSnapshot.AddBlock(memBlock);
                if (memBlock.m_size < 65536)
                {
                    ++m_mostAllocatedBlocks[memBlock.m_size];
                }
            }
            m_dirty = true;
        }
コード例 #15
0
ファイル: MemBlock.cs プロジェクト: polytronicgr/memtracer
 public bool IsCallStackEqual(MemBlock other)
 {
     return(m_callStackCRC == other.m_callStackCRC);
 }