示例#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
        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;
                }
            }
        }