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); } } } }
//========================================= // 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()); }