//========================================= // timer1_Tick //========================================= private void timer1_Tick(object sender, EventArgs e) { int numHeaps = AllocStats.getNumHeaps(); //ask the manager what our heap sizes are. for (int i = 0; i < numHeaps; i++) { HeapAlloc pHeap = AllocStats.getHeapFromIndex(i); uint allocSize = pHeap.getTotalAllocatedBytes(); //covert the Y value to megabytes for graphing. int yMB = (int)(allocSize / (1024 * 1024)); fastTimeLine.addPointToLine(pHeap.getMemPtr(), (int)yMB); } //elapsed time TimeSpan deltaTime = DateTime.Now - mStartTime; label2.Text = "Time Line [" + deltaTime.Hours + ":" + deltaTime.Minutes + ":" + deltaTime.Seconds + "]"; if (mScrollerStuck) { fastTimeLine.setScrollPercent(1); } fastTimeLine.Refresh(); }
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; }
//========================================= // update //========================================= public uint update() { uint totalBytes = 0; int numheaps = AllocStats.getNumHeaps(); for (int i = 0; i < numheaps; i++) { HeapAlloc pHeap = AllocStats.getHeapFromIndex(i); IDictionaryEnumerator _enumerator = pHeap.getFileAllocations().GetEnumerator(); while (_enumerator.MoveNext()) { FileAlloc fa = ((FileAlloc)_enumerator.Value); string longFName = fa.getFilename(); if (longFName.Contains("xbox\\code")) { string trimedFName = giveTrimmedString(longFName); if (trimedFName.ToLower() == mFilename.ToLower()) { totalBytes += fa.getTotalAllocatedBytes(false); } } else { if (longFName.ToLower() == mFilename.ToLower()) { totalBytes += fa.getTotalAllocatedBytes(false); } } } } if (totalBytes > mMaxAllocatedBytes) { mMaxAllocatedBytes = totalBytes; } mCurrAllocatedBytes = totalBytes; this.Text = Path.GetFileName(mFilename) + ", curr : " + MemoryNumber.convert(totalBytes) + " , max : " + MemoryNumber.convert(mMaxAllocatedBytes); return(totalBytes); }
//========================================= // timer1_Tick //========================================= private void timer1_Tick(object sender, EventArgs e) { uint mTotalAllocatedBytesI = 0; uint mTotalAllocatedBytesE = 0; int numHeaps = AllocStats.getNumHeaps(); for (int i = 0; i < numHeaps; i++) { HeapAlloc pHeap = AllocStats.getHeapFromIndex(i); Hashtable pHeapFiles = pHeap.getFileAllocations(); IDictionaryEnumerator file_enumerator = pHeapFiles.GetEnumerator(); while (file_enumerator.MoveNext()) { FileAlloc fa = ((FileAlloc)file_enumerator.Value); string trFName = giveTrimmedString(fa.getFilename()); if (trFName.ToLower() == mTruncatedFilePath.ToLower()) { mTotalAllocatedBytesE += fa.getTotalAllocatedBytes(false); mTotalAllocatedBytesI += fa.getTotalAllocatedBytes(true); } } } //covert the Y value to megabytes for graphing. uint allocSize = mTotalAllocatedBytesE; int yMB = (int)(allocSize / (1024 * 1024)); mTimeline.addPointToLine(0xBEEFCAD0, (int)yMB); if (mScrollerStuck) { mTimeline.setScrollPercent(1); } mTimeline.Refresh(); FilenameLabel.Text = mFilenameOnly + " i(" + MemoryNumber.convert(mTotalAllocatedBytesI) + ")" + " e(" + MemoryNumber.convert(mTotalAllocatedBytesE) + ")"; }
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; } }
//========================================= // onUpdate //========================================= void onUpdate() { ///////////////////////////////////// //find our sorting order.. mLastSortedKeys.Clear(); //this has changed a bit.. //walk each heap, and get all the files per heap //get each file's memory, and use insertion sort to handle it. 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); uint memAmt = fa.getTotalAllocatedBytes(false); //search the other heaps for this same file.. for (int j = 0; j < numHeaps; j++) { if (i == j) { continue; } HeapAlloc pHeap2 = AllocStats.getHeapFromIndex(j); Hashtable pFiles2 = pHeap2.getFileAllocations(); if (pFiles2.Contains(fa.getFilename())) { FileAlloc fa2 = ((FileAlloc)pFiles2[fa.getFilename()]); memAmt += fa2.getTotalAllocatedBytes(false); } } //use insertion sort bool inserted = false; for (int j = 0; j < mLastSortedKeys.Count; j++) { if (mLastSortedKeys[j].mFilenameOnly == Path.GetFileName(fa.getFilename())) { inserted = true; break; } if (memAmt < mLastSortedKeys[j].mTotalAllocatedBytes) { SortedFileStats sfs = new SortedFileStats(); sfs.mTotalAllocatedBytes = memAmt; sfs.mFilenameOnly = Path.GetFileName(fa.getFilename()); mLastSortedKeys.Insert(j, sfs); if (mLastSortedKeys.Count >= cMaxNumBars) { mLastSortedKeys.RemoveAt(0); } inserted = true; break; } } if (!inserted) { SortedFileStats sfs = new SortedFileStats(); sfs.mTotalAllocatedBytes = memAmt; sfs.mFilenameOnly = Path.GetFileName(fa.getFilename()); mLastSortedKeys.Add(sfs); } } } }
//========================================= // 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); }