131 lines
4.4 KiB
C#
131 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using Excel = Microsoft.Office.Interop.Excel;
|
|
|
|
|
|
namespace MemoryViewer
|
|
{
|
|
public partial class AllocationViewer : Form
|
|
{
|
|
public AllocationViewer()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void releaseObject(object obj)
|
|
{
|
|
try
|
|
{
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
|
|
obj = null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
obj = null;
|
|
MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
GC.Collect();
|
|
}
|
|
}
|
|
|
|
|
|
private void btnDumpToFile_Click(object sender, EventArgs e)
|
|
{
|
|
SaveFileDialog savefileDialog = new SaveFileDialog();
|
|
savefileDialog.Filter = "Excel files|*.xls";
|
|
savefileDialog.Title = "Choose filename for XLS memory dump";
|
|
|
|
if (savefileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
Excel.Application xlApp;
|
|
Excel.Workbook xlWorkBook;
|
|
Excel.Worksheet xlWorkSheet;
|
|
object misValue = System.Reflection.Missing.Value;
|
|
|
|
xlApp = new Excel.ApplicationClass();
|
|
xlWorkBook = xlApp.Workbooks.Add(misValue);
|
|
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
|
|
int i = 0;
|
|
int j = 0;
|
|
|
|
//add the row information
|
|
int columnCounter = 1;
|
|
foreach (DataGridViewColumn column in dataGridViewAllocation.Columns)
|
|
{
|
|
xlWorkSheet.Cells[1, columnCounter] = column.HeaderText;
|
|
columnCounter++;
|
|
}
|
|
|
|
//parse the data
|
|
for (i = 0; i <= dataGridViewAllocation.RowCount - 1; i++)
|
|
{
|
|
for (j = 0; j <= dataGridViewAllocation.ColumnCount - 1; j++)
|
|
{
|
|
DataGridViewCell cell = dataGridViewAllocation[j, i];
|
|
xlWorkSheet.Cells[i + 2, j + 1] = cell.Value;
|
|
}
|
|
}
|
|
|
|
|
|
xlWorkBook.SaveAs(savefileDialog.FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
|
|
xlWorkBook.Close(true, misValue, misValue);
|
|
xlApp.Quit();
|
|
|
|
releaseObject(xlWorkSheet);
|
|
releaseObject(xlWorkBook);
|
|
releaseObject(xlApp);
|
|
}
|
|
}
|
|
|
|
private void btnAnalyze_Click(object sender, EventArgs e)
|
|
{
|
|
//get the allocation id you want to analyze
|
|
//send to the engine and wait the result
|
|
//result is full callstack of the different allocation
|
|
//grouped by size / count -- callstack
|
|
|
|
DataGridViewSelectedRowCollection rowCollection = dataGridViewAllocation.SelectedRows;
|
|
if (rowCollection != null && rowCollection.Count > 0)
|
|
{
|
|
DataGridViewRow cell = rowCollection[0];
|
|
|
|
DataGridViewTextBoxCell element = (DataGridViewTextBoxCell)dataGridViewAllocation.Rows[cell.Index].Cells[0];
|
|
|
|
|
|
Int32 filter = MemoryUtils.findAllocatorId(element.Value.ToString());
|
|
|
|
if (filter != -1)
|
|
{
|
|
((FormMemoryViewer) Parent).Plugin.SendIdCommand(filter);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dataGridViewAllocation_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
int rowIndex = e.RowIndex;
|
|
|
|
if (e.ColumnIndex == 6) //button
|
|
{
|
|
DataGridViewTextBoxCell element = (DataGridViewTextBoxCell)dataGridViewAllocation.Rows[rowIndex].Cells[0];
|
|
|
|
Int32 filter = MemoryUtils.findAllocatorId(element.Value.ToString());
|
|
|
|
if (filter != -1)
|
|
{
|
|
((FormMemoryViewer) Parent).Plugin.SendIdCommand(filter);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|