Esempio n. 1
0
        public RetentionTreeViewer(ClrRuntime runtime, List <String> managedObjects)
        {
            this.runtime = runtime;
            InitializeComponent();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));

            if (runtime != null)
            {
                Cursor.Current = Cursors.WaitCursor;
                List <ClrTypeHelper> c = new List <ClrTypeHelper>();
                foreach (String s in managedObjects)
                {
                    c.AddRange(ClrMdHelper.GetPtrsForObjectName(runtime, s));
                }

                comboBoxClrMdTypes.Items.AddRange(c.ToArray());

                Cursor.Current = Cursors.Default;
            }
            else
            {
                openFileDialog();
            }
        }
        private void FilterNodes()
        {
            Cursor.Current = Cursors.WaitCursor;
            TreeNode foundNode = null;

            richTextBoxInfo.Clear();
            foreach (ClrTypeHelper c in globalSearchList)
            {
                if (c.ObjectInfo == null)
                {
                    c.ObjectInfo = ClrMdHelper.GetInfoOfObject(runtime, c.Ptr, null);
                }

                if (c.ObjectInfo.Contains(textBoxFilter.Text))
                {
                    if (foundNode == null)
                    {
                        foundNode = c.TreeNode;
                    }
                    c.TreeNode.BackColor = Color.LightGreen;
                    richTextBoxInfo.AppendText(c.ObjectInfo + System.Environment.NewLine);
                }
                else
                {
                    c.TreeNode.BackColor = Color.White;
                }
            }
            if (foundNode != null)
            {
                foundNode.EnsureVisible();
            }
            Cursor.Current = Cursors.Default;
        }
        public ObjectInspector(ClrRuntime runtime, List <String> managedObjects)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.runtime   = runtime;
            InitializeComponent();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));


            List <ClrTypeHelper> typeList = new List <ClrTypeHelper>();

            foreach (String s in managedObjects.OrderBy(x => x))
            {
                typeList.AddRange(ClrMdHelper.GetPtrsForObjectName(runtime, s));
            }

            this.treeViewObjects.Nodes.Clear();

            foreach (ClrTypeHelper c in typeList)
            {
                TreeNode node = new TreeNode(c.Name)
                {
                    Tag = c
                };
                c.TreeNode = node;
                node.Nodes.Add(new TreeNode());
                treeViewObjects.Nodes.Add(node);
                globalSearchList.Add(c);
            }
            Cursor.Current = Cursors.Default;
        }
Esempio n. 4
0
        //https://github.com/Microsoft/dotnet-samples/tree/master/Microsoft.Diagnostics.Runtime/CLRMD
        private void objectOverviewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Process == null)
            {
                return;
            }

            saveFileDialogObjects.FileName = String.Format("clrmd_{0:yyyyMMdd_HHmmss}_FieldInfo", DateTime.Now);
            if (saveFileDialogObjects.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (File.Exists(saveFileDialogObjects.FileName))
            {
                File.Delete(saveFileDialogObjects.FileName);
            }

            Cursor.Current = Cursors.WaitCursor;

            using (DataTarget dataTarget = DataTarget.AttachToProcess(Process.Id, dataTargetTimeOut, dataTargetAttachFlag))
            {
                ClrInfo    clrVersion = dataTarget.ClrVersions.First();
                ClrRuntime runtime    = clrVersion.CreateRuntime();
                if (runtime.Heap.CanWalkHeap)
                {
                    using (StreamWriter writer = new StreamWriter(saveFileDialogObjects.FileName, true, Encoding.UTF8))
                    {
                        foreach (DataGridViewRow row in dataGridViewMain.SelectedRows)
                        {
                            int           cnt = 0;
                            ManagedObject m   = row.DataBoundItem as ManagedObject;

                            writer.WriteLine("*********************** {0} ************************", m.ObjectName);
                            writer.WriteLine();

                            foreach (ulong ptr in runtime.Heap.EnumerateObjectAddresses())
                            {
                                ClrType type = runtime.Heap.GetObjectType(ptr);

                                if (type == null || type.Name != m.ObjectName)
                                {
                                    continue;
                                }

                                writer.WriteLine(ClrMdHelper.GetInfoOfObject(runtime, ptr, type));
                                writer.WriteLine();
                                cnt++;
                            }
                            writer.WriteLine("{0}x found in Heap {1}", cnt, m.ObjectName);
                            writer.WriteLine();
                            writer.WriteLine();
                        }
                    }
                }
            }
            Cursor.Current = Cursors.Default;
        }
        private void treeViewObjects_AfterSelect(object sender, TreeViewEventArgs e)
        {
            ClrTypeHelper c = e.Node.Tag as ClrTypeHelper;

            if (c.ObjectInfo == null)
            {
                c.ObjectInfo = ClrMdHelper.GetInfoOfObject(runtime, c.Ptr, null);
            }

            richTextBoxInfo.Text = c.ObjectInfo;
        }
Esempio n. 6
0
        private void comboBoxClrMdTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            ClrTypeHelper clrTypeHelper = comboBoxClrMdTypes.SelectedItem as ClrTypeHelper;

            if (clrTypeHelper.Parents.Count == 0)
            {
                ClrMdHelper.BuildFullRetentionTree(runtime, clrTypeHelper);
            }

            this.treeViewRetention.Nodes.Clear();
            AddNodesRecursive(clrTypeHelper, this.treeViewRetention.Nodes);
            Cursor.Current = Cursors.Default;
        }