public void dumpEntireList(string filename) { Dictionary <string, tHashVal> fileHashes = new Dictionary <string, tHashVal>(); int numHeaps = AllocStats.getNumHeaps(); for (int i = 0; i < numHeaps; i++) { HeapAlloc pHeap = AllocStats.getHeapFromIndex(i); Hashtable pFiles = pHeap.getFileAllocations(); IDictionaryEnumerator _enumerator = pFiles.GetEnumerator(); while (_enumerator.MoveNext()) { FileAlloc fa = ((FileAlloc)_enumerator.Value); string fnameOnly = Path.GetFileName(fa.getFilename()); uint memAmt = fa.getTotalAllocatedBytes(false); if (fileHashes.ContainsKey(fnameOnly)) { tHashVal thv = fileHashes[fnameOnly]; thv.memAmt += memAmt; thv.heapsUsed += "," + pHeap.getName(); } else { tHashVal th = new tHashVal(); th.heapsUsed = pHeap.getName(); th.memAmt = memAmt; th.tFname = fa.getFilename(); fileHashes.Add(fnameOnly, th); } } } StreamWriter sw = new StreamWriter(filename, true); IDictionaryEnumerator enumerator = fileHashes.GetEnumerator(); while (enumerator.MoveNext()) { tHashVal thv = ((tHashVal)enumerator.Value); sw.WriteLine(thv.tFname + "," + thv.memAmt + "," + thv.heapsUsed); } sw.Close(); sw = null; }
private void button1_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); sfd.Filter = "CSV File *.csv|*.csv"; if (sfd.ShowDialog() == DialogResult.OK) { StreamWriter sw = new StreamWriter(sfd.FileName, true); int numHeaps = AllocStats.getNumHeaps(); for (int i = 0; i < numHeaps; i++) { HeapAlloc pHeap = AllocStats.getHeapFromIndex(i); Hashtable pFiles = pHeap.getFileAllocations(); sw.WriteLine(pHeap.getName() + ", ," + pHeap.getMaxAllocatedBytes()); IDictionaryEnumerator _enumerator = pFiles.GetEnumerator(); while (_enumerator.MoveNext()) { FileAlloc fa = ((FileAlloc)_enumerator.Value); string fnameOnly = Path.GetFileName(fa.getFilename()); uint memAmt = fa.getTotalAllocatedBytes(false); sw.WriteLine(" ," + fa.getFilename() + "," + memAmt); } } sw.Close(); sw = null; } }
//========================================= // onHeapRegister //========================================= public void onHeapRegister(uint mPtr, int flags, string name) { HeapAlloc pHeap = AllocStats.getHeapFromBasePtr(mPtr); fastTimeLine.addNewGraphLine(pHeap.getMemPtr(), pHeap.getName(), pHeap.ColorVal); }
//========================================= // OnPaint //========================================= protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; int[] xTabs = { 5, 100, 170, 250, 330, 420, 510 }; int x = 0; int y = 0; int ySpacing = 12; g.DrawString("allocated", GDIStatic.Font_Console_10, GDIStatic.SolidBrush_DimGray, xTabs[1], y); g.DrawString("blocks", GDIStatic.Font_Console_10, GDIStatic.SolidBrush_DimGray, xTabs[2], y); g.DrawString("N", GDIStatic.Font_Console_10, GDIStatic.SolidBrush_DimGray, xTabs[3], y); g.DrawString("D", GDIStatic.Font_Console_10, GDIStatic.SolidBrush_DimGray, xTabs[4], y); g.DrawString("R", GDIStatic.Font_Console_10, GDIStatic.SolidBrush_DimGray, xTabs[5], y); y += ySpacing + 1; g.DrawLine(GDIStatic.Pen_DimGray, 0, y, Width, y); y += 2; //SORT THE LIST! List <int> sortOrder = new List <int>(); for (int i = 0; i < AllocStats.getNumHeaps(); i++) { sortOrder.Add(i); } //SORT! for (int i = 0; i < AllocStats.getNumHeaps(); i++) { for (int j = 0; j < AllocStats.getNumHeaps(); j++) { uint target = AllocStats.getHeapFromIndex(sortOrder[i]).getTotalAllocatedBytes(); uint next = AllocStats.getHeapFromIndex(sortOrder[j]).getTotalAllocatedBytes(); if (next < target) { int tmp = sortOrder[i]; sortOrder[i] = sortOrder[j]; sortOrder[j] = tmp; } } } uint totalActiveBytes = 0; uint totalActiveBlocks = 0; for (int i = 0; i < AllocStats.getNumHeaps(); i++) { HeapAlloc pHeap = AllocStats.getHeapFromIndex(sortOrder[i]); Brush brush = new SolidBrush(pHeap.ColorVal); uint totalNumBlocks = pHeap.getTotalNumAllocations(); uint totalNumBytes = pHeap.getTotalAllocatedBytes(); g.DrawString(pHeap.getName() + " :", GDIStatic.Font_Console_10, brush, xTabs[0], y); g.DrawString(MemoryNumber.convert(totalNumBytes), GDIStatic.Font_Console_10, brush, xTabs[1], y); g.DrawString(totalNumBlocks.ToString(), GDIStatic.Font_Console_10, brush, xTabs[2], y); g.DrawString(pHeap.getNumNews().ToString(), GDIStatic.Font_Console_10, brush, xTabs[3], y); g.DrawString(pHeap.getNumDeletes().ToString(), GDIStatic.Font_Console_10, brush, xTabs[4], y); g.DrawString(pHeap.getNumResizes().ToString(), GDIStatic.Font_Console_10, brush, xTabs[5], y); g.FillRectangle(brush, x + 0, y + 2, 4, 8); y += ySpacing; totalActiveBlocks += totalNumBlocks; totalActiveBytes += totalNumBytes; } g.DrawString("Total :", GDIStatic.Font_Console_10, GDIStatic.SolidBrush_White, xTabs[0], y + ySpacing); g.DrawString(MemoryNumber.convert(totalActiveBytes), GDIStatic.Font_Console_10, GDIStatic.SolidBrush_White, xTabs[1], y + ySpacing); g.DrawString(totalActiveBlocks.ToString(), GDIStatic.Font_Console_10, GDIStatic.SolidBrush_White, xTabs[2], y + ySpacing); }
//========================================= // update //========================================= public void update() { Hashtable pFiles = mpOwnerAlloc.getFileAllocations(); if (Expanded) { //do a quick pass to determine if we need to remove stuff.. for (int i = 0; i < Nodes.Count; i++) { if (Nodes[i] is FileAllocNode) { FileAllocNode fan = (FileAllocNode)Nodes[i]; if (!pFiles.Contains(fan.mpOwnerAlloc.getFilename())) { Nodes.RemoveAt(i); i--; } } else { Nodes.RemoveAt(i); i--; } } //our local node list should be completly present in the parent container. IDictionaryEnumerator file_enumerator = pFiles.GetEnumerator(); while (file_enumerator.MoveNext()) { FileAlloc fa = ((FileAlloc)file_enumerator.Value); bool found = false; for (int i = 0; i < Nodes.Count; i++) { FileAllocNode fan = (FileAllocNode)Nodes[i]; if (fan.mpOwnerAlloc == fa) { fan.update(); found = true; break; } } if (!found) { if (fa.getTotalAllocatedBytes(false) == 0) { continue; } FileAllocNode fan = new FileAllocNode(fa); addNode(fan); } } } else { Nodes.Clear(); if (pFiles.Count > 0) { Nodes.Add(new GDITreeViewNode()); } } this.Text = mpOwnerAlloc.getName() + " : " + MemoryNumber.convert(mpOwnerAlloc.getTotalAllocatedBytes()); }
//========================================= // HeapAllocStats //========================================= public HeapAllocNode(HeapAlloc ownerAlloc) { mpOwnerAlloc = ownerAlloc; this.Text = mpOwnerAlloc.getName() + " : " + MemoryNumber.convert(mpOwnerAlloc.getTotalAllocatedBytes()); }