Example #1
0
        private NProf()
        {
            Icon     = new Icon(this.GetType().Assembly.GetManifestResourceStream("NProf.Resources.app-icon.ico"));
            Text     = "NProf - v" + Profiler.Version;
            profiler = new Profiler();

            runs = new ContainerListView();
            ContainerListViewColumnHeader header = new ContainerListViewColumnHeader("Runs", 90);

            runs.Columns.Add(header);
            runs.SizeChanged += delegate
            {
                header.Width = runs.Size.Width - 5;
            };
            runs.Dock         = DockStyle.Left;
            runs.Width        = 100;
            runs.DoubleClick += delegate
            {
                if (runs.SelectedItems.Count != 0)
                {
                    ShowRun((Run)runs.SelectedItems[0].Tag);
                }
            };

            callers           = new MethodView("Callers");
            callers.Size      = new Size(100, 200);
            callers.Dock      = DockStyle.Bottom;
            callers.GotFocus += delegate
            {
                callees.SelectedItems.Clear();
            };
            callers.DoubleClick += delegate
            {
                if (callers.SelectedItems.Count != 0)
                {
                    callees.MoveTo(((FunctionInfo)callers.SelectedItems[0].Tag).ID);
                }
            };

            callees           = new MethodView("Callees");
            callees.Size      = new Size(100, 100);
            callees.Dock      = DockStyle.Fill;
            callees.GotFocus += delegate
            {
                callers.SelectedItems.Clear();
            };
            callees.DoubleClick += delegate
            {
                if (callees.SelectedItems.Count != 0)
                {
                    callers.MoveTo(((FunctionInfo)callees.SelectedItems[0].Tag).ID);
                }
            };
            callees.SelectedItemsChanged += delegate {
                if (callees.SelectedItems.Count != 0)
                {
                    ContainerListViewItem item = callees.SelectedItems[0];
                    if (item.Items.Count == 0)
                    {
                        foreach (FunctionInfo f in ((FunctionInfo)item.Tag).Children.Values)
                        {
                            callees.AddFunctionItem(item.Items, f);
                        }
                    }
                }
            };
            findText              = new TextBox();
            findText.TextChanged += delegate
            {
                Find(true, false);
            };
            findText.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    Find(true, true);
                    e.Handled = true;
                }
            };
            Menu = new MainMenu(new MenuItem[]
            {
                new MenuItem(
                    "File",
                    new MenuItem[]
                {
                    new MenuItem(
                        "&New",
                        delegate
                    {
                        runs.Items.Clear();
                        NProf.arguments.Text   = "";
                        NProf.application.Text = "";
                        callees.Items.Clear();
                        callers.Items.Clear();
                    },
                        Shortcut.CtrlN),
                    new MenuItem("-"),
                    new MenuItem("E&xit", delegate { Close(); })
                }),
                new MenuItem(
                    "Project",
                    new MenuItem[]
                {
                    new MenuItem(
                        "Start",
                        delegate { StartRun(); },
                        Shortcut.F5),
                    new MenuItem("-"),
                    new MenuItem("Find", delegate { ShowSearch(); }, Shortcut.CtrlF)
                })
            });
            Controls.AddRange(new Control[]
            {
                With(new Panel(), delegate(Panel panel)
                {
                    panel.Dock = DockStyle.Fill;
                    panel.Controls.AddRange(new Control[] {
                        With(new Panel(), delegate(Panel methodPanel)
                        {
                            methodPanel.Size = new Size(100, 100);
                            methodPanel.Dock = DockStyle.Fill;

                            methodPanel.Controls.AddRange(new Control[] {
                                callees,
                                With(new Splitter(), delegate(Splitter splitter)
                                {
                                    splitter.Dock = DockStyle.Bottom;
                                }),
                                callers,
                                With(new FlowLayoutPanel(), delegate(FlowLayoutPanel p)
                                {
                                    findPanel             = p;
                                    findPanel.BorderStyle = BorderStyle.FixedSingle;
                                    p.Visible             = false;
                                    p.WrapContents        = false;
                                    p.AutoSize            = true;
                                    p.Dock          = DockStyle.Top;
                                    Button close    = new Button();
                                    close.Text      = "x";
                                    close.Width     = 17;
                                    close.Height    = 20;
                                    close.TextAlign = ContentAlignment.BottomLeft;
                                    close.Click    += delegate
                                    {
                                        findPanel.Visible = false;
                                    };
                                    p.Controls.Add(close);
                                    p.Controls.AddRange(new Control[] {
                                        With(new Label(), delegate(Label label)
                                        {
                                            label.Text      = "Find:";
                                            label.Dock      = DockStyle.Fill;
                                            label.TextAlign = ContentAlignment.MiddleLeft;
                                            label.AutoSize  = true;
                                        }),
                                        findText,
                                        With(new Button(), delegate(Button button)
                                        {
                                            button.AutoSize = true;
                                            button.Text     = "Find next";
                                            button.Click   += new EventHandler(findNext_Click);
                                        }),
                                        With(new Button(), delegate(Button button)
                                        {
                                            button.AutoSize = true;
                                            button.FlatAppearance.BorderSize = 0;
                                            button.Click += new EventHandler(findPrevious_Click);
                                            button.Text   = "Find previous";
                                        })
                                    });
                                }
                                     )
                            });
                        }),
                        With(new Splitter(), delegate(Splitter splitter)
                        {
                            splitter.Dock = DockStyle.Left;
                        }),
                        runs
                    });
                }),
                With(new Splitter(), delegate(Splitter splitter)
                {
                    splitter.Dock = DockStyle.Top;
                }),
                With(new TableLayoutPanel(), delegate(TableLayoutPanel panel)
                {
                    application = With(new TextBox(), delegate(TextBox textBox)
                    {
                        textBox.Width = 300;
                    });
                    arguments = With(new TextBox(), delegate(TextBox textBox)
                    {
                        textBox.Width = 300;
                    });
                    panel.Height   = 100;
                    panel.AutoSize = true;
                    panel.Dock     = DockStyle.Top;
                    panel.Controls.Add(With(new Label(), delegate(Label label)
                    {
                        label.Text      = "Application:";
                        label.Dock      = DockStyle.Fill;
                        label.TextAlign = ContentAlignment.MiddleLeft;
                        label.AutoSize  = true;
                    }), 0, 0);
                    panel.Controls.Add(application, 1, 0);
                    panel.Controls.Add(With(new Button(), delegate(Button button)
                    {
                        button.Text     = "Browse...";
                        button.TabIndex = 0;
                        button.Focus();
                        button.Click += delegate
                        {
                            OpenFileDialog dialog = new OpenFileDialog();
                            dialog.Filter         = "Executable files (*.exe)|*.exe";
                            DialogResult dr       = dialog.ShowDialog();
                            if (dr == DialogResult.OK)
                            {
                                application.Text = dialog.FileName;
                                application.Focus();
                                application.SelectAll();
                            }
                        };
                    }), 2, 0);
                    panel.Controls.Add(With(new Label(), delegate(Label label)
                    {
                        label.Text      = "Arguments:";
                        label.Dock      = DockStyle.Fill;
                        label.TextAlign = ContentAlignment.MiddleLeft;
                        label.AutoSize  = true;
                    }), 0, 1);
                    panel.Controls.Add(arguments, 1, 1);
                }),
            });
            //Size = new Size(800, 600);
            //this.Validating+=delegate {
            //    Size = new Size(800, 600);
            //};
            this.Load += delegate {
                Size = new Size(800, 600);
            };
        }
Example #2
0
 public Run(Profiler p)
 {
     this.profiler = p;
     this.start    = DateTime.Now;
     this.end      = DateTime.MaxValue;
 }