Re: Interested in development
[email protected] Thu, 8 Jan 2004 18:22:33 -0500
| Newsgroups | gmane.comp.windows.dotnet.nprof.devel |
|---|---|
| Message-ID | <[email protected]> |
> > - Back/Forward facility when one 'double-clicks' on the > > _lvFunctionInfo list items. That is, when I see details of a > > function and its children, I go down and keep on double-clicking on > > the children to find more information - however, there is no way to > > return back! So I have to remember which function I started with. > > +1 I've wanted this for a while. It actually existed just before I > release 0.0, but I couldn't get it to work well enough to put it in. > It'd be much easier to put it in with the current GUI interface. > > >Let me know what you guys think. > > Sounds great! Did you want to work on the back/forward functionality in > the profiler grid? That would probably be an easy place for you to > start within the code. I have implemented the back/forward functionality. The 'View' menu has two more commands (Back and Forward). Seems to work fine on the TestProfilee. Am attaching the two files I needed to change ProfilerControl.cs and ProfilerForm.cs I don't know how submitting patches works for this project. Let me know of any bugs. Ashwin
ProfilerForm.cs
(text/plain, 24.4 KB)
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using NProf.Glue.Profiler;
using NProf.Glue.Profiler.Info;
using NProf.Glue.Profiler.Project;
using Genghis.Windows.Forms;
namespace NProf.GUI
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class ProfilerForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.StatusBar _sbStatusBar;
private Crownwood.Magic.Menus.MenuCommand _menuFile;
private Crownwood.Magic.Menus.MenuCommand _menuEdit;
private Crownwood.Magic.Menus.MenuCommand _menuHelp;
private Crownwood.Magic.Menus.MenuCommand _cmdNew;
private Crownwood.Magic.Menus.MenuCommand _cmdOpen;
private Crownwood.Magic.Menus.MenuCommand _cmdSave;
private Crownwood.Magic.Menus.MenuCommand _cmdSaveAll;
private Crownwood.Magic.Menus.MenuCommand _cmdExit;
private Crownwood.Magic.Controls.TabControl _tcProfilers;
private Crownwood.Magic.Menus.MenuControl _menuMain;
private Crownwood.Magic.Menus.MenuCommand menuCommand1;
private Crownwood.Magic.Menus.MenuCommand _menuProject;
private Crownwood.Magic.Menus.MenuCommand _cmdProjectRun;
private Crownwood.Magic.Menus.MenuCommand _cmdProjectOptions;
private Crownwood.Magic.Docking.DockingManager _dock;
private Crownwood.Magic.Menus.MenuCommand _menuView;
private Crownwood.Magic.Menus.MenuCommand _cmdProjectView;
private Crownwood.Magic.Menus.MenuCommand _cmdNavBack;
private Crownwood.Magic.Menus.MenuCommand _cmdNavForward;
private Crownwood.Magic.Menus.MenuCommand _sep2;
private Crownwood.Magic.Menus.MenuCommand _sep1;
private Crownwood.Magic.Menus.MenuCommand _cmdHelpAbout;
private Crownwood.Magic.Menus.MenuCommand menuCommand2;
private Crownwood.Magic.Menus.MenuCommand menuCommand3;
private Crownwood.Magic.Menus.MenuCommand menuCommand4;
private System.Windows.Forms.StatusBarPanel _sbpMessage;
private Profiler _p;
private ProjectTree _pt;
private ProjectInfoCollection _pic;
private ProjectInfo _piInitialProject;
private ProjectInfo _piVSNetProject;
private Crownwood.Magic.Menus.MenuCommand _cmdProjectRunViewMessages;
private Crownwood.Magic.Menus.MenuCommand menuCommand5;
private Crownwood.Magic.Menus.MenuCommand menuCommand6;
private Crownwood.Magic.Menus.MenuCommand _cmdProjectRunCopy;
private Crownwood.Magic.Menus.MenuCommand _cmdProjectStop;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ProfilerForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
_p = new Profiler();
//_p.ProcessCompleted += new Profiler.ProcessCompletedHandler( OnProfileComplete );
_p.Error += new Profiler.ErrorHandler( OnError );
_piInitialProject = null;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuItem1 = new System.Windows.Forms.MenuItem();
this._menuMain = new Crownwood.Magic.Menus.MenuControl();
this._menuFile = new Crownwood.Magic.Menus.MenuCommand();
this._cmdNew = new Crownwood.Magic.Menus.MenuCommand();
this._cmdOpen = new Crownwood.Magic.Menus.MenuCommand();
this._sep1 = new Crownwood.Magic.Menus.MenuCommand();
this._cmdSave = new Crownwood.Magic.Menus.MenuCommand();
this._cmdSaveAll = new Crownwood.Magic.Menus.MenuCommand();
this._sep2 = new Crownwood.Magic.Menus.MenuCommand();
this._cmdExit = new Crownwood.Magic.Menus.MenuCommand();
this._menuEdit = new Crownwood.Magic.Menus.MenuCommand();
this._menuProject = new Crownwood.Magic.Menus.MenuCommand();
this._cmdProjectRun = new Crownwood.Magic.Menus.MenuCommand();
this._cmdProjectStop = new Crownwood.Magic.Menus.MenuCommand();
this._cmdProjectOptions = new Crownwood.Magic.Menus.MenuCommand();
this.menuCommand5 = new Crownwood.Magic.Menus.MenuCommand();
this._cmdProjectRunViewMessages = new Crownwood.Magic.Menus.MenuCommand();
this._cmdProjectRunCopy = new Crownwood.Magic.Menus.MenuCommand();
this._menuView = new Crownwood.Magic.Menus.MenuCommand();
this._cmdProjectView = new Crownwood.Magic.Menus.MenuCommand();
this._cmdNavBack = new Crownwood.Magic.Menus.MenuCommand();
this._cmdNavForward = new Crownwood.Magic.Menus.MenuCommand();
this._menuHelp = new Crownwood.Magic.Menus.MenuCommand();
this._cmdHelpAbout = new Crownwood.Magic.Menus.MenuCommand();
this._tcProfilers = new Crownwood.Magic.Controls.TabControl();
this._sbStatusBar = new System.Windows.Forms.StatusBar();
this._sbpMessage = new System.Windows.Forms.StatusBarPanel();
this.menuCommand1 = new Crownwood.Magic.Menus.MenuCommand();
this.menuCommand2 = new Crownwood.Magic.Menus.MenuCommand();
this.menuCommand3 = new Crownwood.Magic.Menus.MenuCommand();
this.menuCommand4 = new Crownwood.Magic.Menus.MenuCommand();
this.menuCommand6 = new Crownwood.Magic.Menus.MenuCommand();
((System.ComponentModel.ISupportInitialize)(this._sbpMessage)).BeginInit();
this.SuspendLayout();
//
// menuItem1
//
this.menuItem1.Index = -1;
this.menuItem1.Text = "Close Tab";
//
// _menuMain
//
this._menuMain.AnimateStyle = Crownwood.Magic.Menus.Animation.System;
this._menuMain.AnimateTime = 100;
this._menuMain.Cursor = System.Windows.Forms.Cursors.Arrow;
this._menuMain.Direction = Crownwood.Magic.Common.Direction.Horizontal;
this._menuMain.Dock = System.Windows.Forms.DockStyle.Top;
this._menuMain.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World, ((System.Byte)(0)));
this._menuMain.HighlightTextColor = System.Drawing.SystemColors.MenuText;
this._menuMain.MenuCommands.AddRange(new Crownwood.Magic.Menus.MenuCommand[] {
this._menuFile,
this._menuEdit,
this._menuProject,
this._menuView,
this._menuHelp});
this._menuMain.Name = "_menuMain";
this._menuMain.Size = new System.Drawing.Size(920, 25);
this._menuMain.Style = Crownwood.Magic.Common.VisualStyle.IDE;
this._menuMain.TabIndex = 0;
this._menuMain.TabStop = false;
this._menuMain.Text = "menuControl1";
//
// _menuFile
//
this._menuFile.Description = "File";
this._menuFile.MenuCommands.AddRange(new Crownwood.Magic.Menus.MenuCommand[] {
this._cmdNew,
this._cmdOpen,
this._sep1,
this._cmdSave,
this._cmdSaveAll,
this._sep2,
this._cmdExit});
this._menuFile.Text = "&File";
//
// _cmdNew
//
this._cmdNew.Description = "New Profiler Project";
this._cmdNew.Text = "New...";
this._cmdNew.Click += new System.EventHandler(this._cmdNew_Click);
//
// _cmdOpen
//
this._cmdOpen.Description = "Open a profile project";
this._cmdOpen.Enabled = false;
this._cmdOpen.Text = "Open";
//
// _sep1
//
this._sep1.Description = "MenuItem";
this._sep1.Text = "-";
//
// _cmdSave
//
this._cmdSave.Description = "Save the active profiler project";
this._cmdSave.Enabled = false;
this._cmdSave.Text = "Save";
//
// _cmdSaveAll
//
this._cmdSaveAll.Description = "Save all open profiler projects";
this._cmdSaveAll.Enabled = false;
this._cmdSaveAll.Text = "Save All";
//
// _sep2
//
this._sep2.Description = "MenuItem";
this._sep2.Text = "-";
//
// _cmdExit
//
this._cmdExit.Description = "Exit the application";
this._cmdExit.Text = "E&xit";
this._cmdExit.Click += new System.EventHandler(this._cmdExit_Click);
//
// _menuEdit
//
this._menuEdit.Description = "Edit";
this._menuEdit.Enabled = false;
this._menuEdit.Text = "&Edit";
//
// _menuProject
//
this._menuProject.Description = "Project commands";
this._menuProject.MenuCommands.AddRange(new Crownwood.Magic.Menus.MenuCommand[] {
this._cmdProjectRun,
this._cmdProjectStop,
this._cmdProjectOptions,
this.menuCommand5,
this._cmdProjectRunViewMessages,
this._cmdProjectRunCopy});
this._menuProject.Text = "&Project";
//
// _cmdProjectRun
//
this._cmdProjectRun.Description = "Run the current project";
this._cmdProjectRun.Text = "Start project run";
this._cmdProjectRun.Click += new System.EventHandler(this._cmdProjectRun_Click);
this._cmdProjectRun.Update += new System.EventHandler(this.UpdateProjectItems);
//
// _cmdProjectStop
//
this._cmdProjectStop.Description = "Stop the running project";
this._cmdProjectStop.Text = "Stop project run";
//
// _cmdProjectOptions
//
this._cmdProjectOptions.Description = "Modify the options for this project";
this._cmdProjectOptions.Text = "Options...";
this._cmdProjectOptions.Click += new System.EventHandler(this._cmdProjectOptions_Click);
this._cmdProjectOptions.Update += new System.EventHandler(this.UpdateProjectItems);
//
// menuCommand5
//
this.menuCommand5.Description = "-";
this.menuCommand5.Text = "-";
//
// _cmdProjectRunViewMessages
//
this._cmdProjectRunViewMessages.Description = "View the Messages from the current profiler run...";
this._cmdProjectRunViewMessages.Text = "View Run Messages...";
this._cmdProjectRunViewMessages.Click += new System.EventHandler(this._cmdProjectRunViewMessages_Click);
//
// _cmdProjectRunCopy
//
this._cmdProjectRunCopy.Description = "Copy the project run data to the clipboard";
this._cmdProjectRunCopy.Text = "Copy Project Run Data";
//
// _menuView
//
this._menuView.Description = "View";
this._menuView.MenuCommands.AddRange(new Crownwood.Magic.Menus.MenuCommand[] {
this._cmdProjectView,
this._cmdNavBack,
this._cmdNavForward
});
this._menuView.Text = "&View";
//
// _cmdProjectView
//
this._cmdProjectView.Description = "Show/hide the project tab";
this._cmdProjectView.Text = "Project tab";
this._cmdProjectView.Click += new System.EventHandler(this._cmdProjectView_Click);
this._cmdProjectView.Update += new System.EventHandler(this._cmdProjectView_Update);
//
// _cmdNavBack
// _cmdNavForward
//
this._cmdNavBack.Description = "Navigate Back"; // should be more detailed! in what context?
this._cmdNavBack.Text = "Back";
this._cmdNavBack.Click += new System.EventHandler(this._cmdNavBack_Click);
this._cmdNavForward.Description = "Navigate Forward"; // should be more detailed! in what context?
this._cmdNavForward.Text = "Forward";
this._cmdNavForward.Click += new System.EventHandler(this._cmdNavForward_Click);
// _menuHelp
//
this._menuHelp.Description = "Help";
this._menuHelp.MenuCommands.AddRange(new Crownwood.Magic.Menus.MenuCommand[] {
this._cmdHelpAbout});
this._menuHelp.Text = "&Help";
//
// _cmdHelpAbout
//
this._cmdHelpAbout.Description = "About nprof";
this._cmdHelpAbout.Text = "About nprof...";
this._cmdHelpAbout.Click += new System.EventHandler(this._cmdHelpAbout_Click);
//
// _tcProfilers
//
this._tcProfilers.Dock = System.Windows.Forms.DockStyle.Fill;
this._tcProfilers.IDEPixelArea = true;
this._tcProfilers.Location = new System.Drawing.Point(0, 25);
this._tcProfilers.Name = "_tcProfilers";
this._tcProfilers.Size = new System.Drawing.Size(920, 630);
this._tcProfilers.TabIndex = 2;
this._tcProfilers.SelectionChanged += new System.EventHandler(this._tcProfilers_SelectionChanged);
this._tcProfilers.ClosePressed += new System.EventHandler(this._tcProfilers_ClosePressed);
//
// _sbStatusBar
//
this._sbStatusBar.Location = new System.Drawing.Point(0, 655);
this._sbStatusBar.Name = "_sbStatusBar";
this._sbStatusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this._sbpMessage});
this._sbStatusBar.ShowPanels = true;
this._sbStatusBar.Size = new System.Drawing.Size(920, 22);
this._sbStatusBar.TabIndex = 3;
//
// _sbpMessage
//
this._sbpMessage.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this._sbpMessage.Text = "Ready.";
this._sbpMessage.Width = 904;
//
// menuCommand1
//
this.menuCommand1.Description = "MenuItem";
//
// menuCommand2
//
this.menuCommand2.Break = true;
this.menuCommand2.Description = "MenuItem";
//
// menuCommand3
//
this.menuCommand3.Break = true;
this.menuCommand3.Description = "MenuItem";
//
// menuCommand4
//
this.menuCommand4.Description = "MenuItem";
//
// menuCommand6
//
this.menuCommand6.Description = "MenuItem";
//
// ProfilerForm
//
this.AllowDrop = true;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(920, 677);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this._tcProfilers,
this._menuMain,
this._sbStatusBar});
this.Name = "ProfilerForm";
this.Text = "nprof Profiling Application - Alpha v0.6";
this.Closing += new System.ComponentModel.CancelEventHandler(this.ProfilerForm_Closing);
this.Load += new System.EventHandler(this.ProfilerForm_Load);
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.ProfilerForm_Layout);
this.Leave += new System.EventHandler(this.ProfilerForm_Leave);
this.Deactivate += new System.EventHandler(this.ProfilerForm_Deactivate);
((System.ComponentModel.ISupportInitialize)(this._sbpMessage)).EndInit();
this.ResumeLayout(false);
}
#endregion
public ProjectInfo InitialProject
{
get { return _piInitialProject; }
set { _piInitialProject = value; }
}
public void EnableAndStart()
{
if ( _piVSNetProject == null )
{
_piVSNetProject = new ProjectInfo( ProjectType.VSNet );
_piVSNetProject.Name = "VS.NET Project";
_pic.Add( _piVSNetProject );
}
// Run the project
_pt.SelectProject( _piVSNetProject );
_cmdProjectRun_Click( null, null );
}
public void Disable()
{
_p.Disable();
}
private void OnError( Exception e )
{
MessageBox.Show( this, "An internal exception occurred:\n\n" + e.ToString(), "Error" );
}
private void OnProfileStateChange( Run run )
{
this.BeginInvoke( new HandleProfileComplete( OnUIThreadProfileComplete ), new object[] { run } );
}
private delegate void HandleProfileComplete( Run run );
private void OnUIThreadProfileComplete( Run run )
{
CreateTabPage( run );
}
private ProjectInfo GetCurrentProject()
{
return _pt.GetSelectedProject();
}
private void CheckAddBlankTab()
{
if ( _tcProfilers.TabPages.Count == 0 )
{
Crownwood.Magic.Controls.TabPage tp = new Crownwood.Magic.Controls.TabPage( "No profiler runs loaded" );
_tcProfilers.TabPages.Add( tp );
NoProfilerRunsLoaded np = new NoProfilerRunsLoaded();
tp.Controls.Add( np );
np.Dock = DockStyle.Fill;
}
}
private void CheckRemoveBlankTab()
{
if ( IsShowingBlankTab() )
_tcProfilers.TabPages.Clear();
}
private bool IsShowingBlankTab()
{
return ( _tcProfilers.TabPages[ 0 ].Title == "No profiler runs loaded" );
}
private Crownwood.Magic.Controls.TabPage CreateTabPage( Run run )
{
CheckRemoveBlankTab();
Crownwood.Magic.Controls.TabPage tpActive = null;
// Does it exist already?
foreach ( Crownwood.Magic.Controls.TabPage tp in _tcProfilers.TabPages )
{
if ( tp.Tag == run )
{
_tcProfilers.SelectedTab = tp;
tpActive = tp;
break;
}
}
if ( tpActive == null )
{
tpActive = new Crownwood.Magic.Controls.TabPage( run.Project.Name + " [" + run.StartTime + "]" );
tpActive.Tag = run;
_tcProfilers.TabPages.Add( tpActive );
_tcProfilers.SelectedTab = tpActive;
}
if ( run.State == Run.RunState.Finished
&& run.Success
&& ( tpActive.Controls.Count == 0 || !( tpActive.Controls[ 0 ] is ProfilerControl ) ) )
{
tpActive.Controls.Clear();
ProfilerControl pc = new ProfilerControl();
pc.Dock = DockStyle.Fill;
tpActive.Controls.Add( pc );
pc.ProfilerRun = run;
}
// Catch non-successful finished runs here too
if ( ( ( run.State == Run.RunState.Finished && !run.Success )
|| run.State == Run.RunState.Running
|| run.State == Run.RunState.Initializing )
&& ( tpActive.Controls.Count == 0 || !( tpActive.Controls[ 0 ] is ProfilerRunControl ) ) )
{
tpActive.Controls.Clear();
ProfilerRunControl pc = new ProfilerRunControl();
pc.Dock = DockStyle.Fill;
tpActive.Controls.Add( pc );
pc.ProfilerRun = run;
}
return tpActive;
}
private void ProfilerForm_Leave(object sender, System.EventArgs e)
{
}
private void ProfilerForm_Deactivate(object sender, System.EventArgs e)
{
}
private void ProfilerForm_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
CheckAddBlankTab();
}
private void _cmdNew_Click(object sender, System.EventArgs e)
{
ProfilerProjectOptionsForm frm = new ProfilerProjectOptionsForm();
frm.Mode = ProfilerProjectOptionsForm.ProfilerProjectMode.CreateProject;
DialogResult dr = frm.ShowDialog( this );
if ( dr == DialogResult.OK )
{
_pic.Add( frm.Project );
_pt.SelectProject( frm.Project );
}
}
private void _cmdProjectRun_Click(object sender, System.EventArgs e)
{
string strMessage;
bool bSuccess = _p.CheckSetup( out strMessage );
if ( !bSuccess )
{
MessageBox.Show( this, strMessage, "Application setup error", MessageBoxButtons.OK, MessageBoxIcon.Error );
return;
}
Run run = GetCurrentProject().CreateRun( _p );
run.StateChanged += new Run.RunStateEventHandler( OnRunStateChanged );
run.Start();
CreateTabPage( run );
_pt.SelectRun( run );
}
private void OnRunStateChanged( Run run, Run.RunState rsOld, Run.RunState rsNew )
{
if ( rsNew == Run.RunState.Running )
{
OnProfileStateChange( run );
}
if ( rsNew == Run.RunState.Finished )
{
OnProfileStateChange( run );
}
}
private void ProfilerForm_Load(object sender, System.EventArgs e)
{
this.Icon = new Icon( this.GetType().Assembly.GetManifestResourceStream( "NProf.GUI.Resources.app-icon.ico" ) );
_pic = new ProjectInfoCollection();
_pt = new ProjectTree();
_pt.Projects = _pic;
_pt.ProjectDoubleClicked += new ProjectTree.ProjectDoubleClickedHandler( _pt_ProjectDoubleClicked );
_pt.RunDoubleClicked += new ProjectTree.RunDoubleClickedHandler( _pt_RunDoubleClicked );
_pt.ExecutablesDropped +=new ProjectTree.ExecutablesDroppedHandler( _pt_ExecutableDropped );
_dock = new Crownwood.Magic.Docking.DockingManager( this, Crownwood.Magic.Common.VisualStyle.IDE );
_dock.OuterControl = _menuMain;
_dock.InnerControl = _tcProfilers;
Crownwood.Magic.Docking.Content c = _dock.Contents.Add( _pt, "Projects" );
Crownwood.Magic.Docking.WindowContent wc = _dock.AddContentWithState( c, Crownwood.Magic.Docking.State.DockLeft );
this.Text = "nprof Profiling Application - v" + Profiler.Version;
_tcProfilers.Appearance = Crownwood.Magic.Controls.TabControl.VisualAppearance.MultiDocument;
if ( _piInitialProject != null )
{
_pic.Add( _piInitialProject );
_pt.SelectProject( _piInitialProject );
_cmdProjectRun_Click( null, null );
}
}
private void _tcProfilers_ClosePressed(object sender, System.EventArgs e)
{
if ( IsShowingBlankTab() )
return;
_tcProfilers.TabPages.Remove( _tcProfilers.SelectedTab );
CheckAddBlankTab();
}
private void _cmdProjectView_Click(object sender, System.EventArgs e)
{
if ( !_cmdProjectView.Checked )
{
_dock.ShowContent( _dock.Contents[ "Projects" ] );
_cmdProjectView.Checked = true;
}
else
{
_dock.HideContent( _dock.Contents[ "Projects" ] );
_cmdProjectView.Checked = false;
}
}
private void _cmdProjectView_Update(object sender, System.EventArgs e)
{
_cmdProjectView.Checked = _dock.Contents[ "Projects" ].Visible;
}
// Ashwin
private void _cmdNavBack_Click(object sender, System.EventArgs e)
{
Crownwood.Magic.Controls.TabPage tpActive = _tcProfilers.SelectedTab;
if (tpActive == null)
return;
if (tpActive.Controls.Count == 0 || !(tpActive.Controls[0] is ProfilerControl))
return;
((ProfilerControl) tpActive.Controls[0]).NavigateBackward();
}
private void _cmdNavForward_Click(object sender, System.EventArgs e)
{
Crownwood.Magic.Controls.TabPage tpActive = _tcProfilers.SelectedTab;
if (tpActive == null)
return;
if (tpActive.Controls.Count == 0 || !(tpActive.Controls[0] is ProfilerControl))
return;
((ProfilerControl) tpActive.Controls[0]).NavigateForward();
}
// Ashwin
private void _cmdExit_Click(object sender, System.EventArgs e)
{
Close();
}
private void ProfilerForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
_p.Stop();
}
private void UpdateProjectItems(object sender, System.EventArgs e)
{
bool bCanRunOrEdit = _pt.GetSelectedProject() != null
&& _pt.GetSelectedProject().ProjectType != ProjectType.VSNet;
Run run = _pt.GetSelectedRun();
_cmdProjectRun.Enabled = bCanRunOrEdit;
_cmdProjectStop.Enabled = bCanRunOrEdit && ( run != null && run.State == Run.RunState.Running );
_cmdProjectOptions.Enabled = bCanRunOrEdit;
_cmdProjectRunViewMessages.Enabled = ( !IsShowingBlankTab() );
}
private void _cmdProjectOptions_Click(object sender, System.EventArgs e)
{
ProfilerProjectOptionsForm frm = new ProfilerProjectOptionsForm();
frm.Project = GetCurrentProject();
frm.Mode = ProfilerProjectOptionsForm.ProfilerProjectMode.ModifyProject;
frm.ShowDialog( this );
}
private void _cmdHelpAbout_Click(object sender, System.EventArgs e)
{
AboutForm frm = new AboutForm();
frm.ShowDialog( this );
}
private void _cmdProjectRunViewMessages_Click(object sender, System.EventArgs e)
{
Run r = ( Run )_tcProfilers.SelectedTab.Tag;
ProfilerRunMessagesForm frm = new ProfilerRunMessagesForm();
frm.ProfilerRun = r;
frm.ShowDialog( this );
}
private void _tcProfilers_SelectionChanged(object sender, System.EventArgs e)
{
}
private void _pt_ProjectDoubleClicked( ProjectInfo pi )
{
_cmdProjectOptions_Click( null, null );
}
private void _pt_RunDoubleClicked( Run run )
{
if ( run.State != Run.RunState.Finished )
{
MessageBox.Show( this, "The run has not completed", "Project Run in Progress", MessageBoxButtons.OK, MessageBoxIcon.Information );
return;
}
CreateTabPage( run );
}
private void _pt_ExecutableDropped( string[] fileNames )
{
foreach ( string fileName in fileNames )
{
ProfilerProjectOptionsForm frm = new ProfilerProjectOptionsForm();
frm.Mode = ProfilerProjectOptionsForm.ProfilerProjectMode.CreateProject;
// prepoulate from drag operation
frm.Project.ApplicationName = fileName;
frm.Project.WorkingDirectory = Path.GetDirectoryName(fileName);
DialogResult dr = frm.ShowDialog( this );
if ( dr == DialogResult.OK )
{
_pic.Add( frm.Project );
_pt.SelectProject( frm.Project );
}
}
}
}
}
ProfilerControl.cs
(text/plain, 19.7 KB)
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using NProf.Glue.Profiler;
using NProf.Glue.Profiler.Info;
using NProf.Glue.Profiler.Project;
using Genghis.Windows.Forms;
namespace NProf.GUI
{
/// <summary>
/// Summary description for ProfilerControl.
/// </summary>
[ProgId( "NProf.ProfilerControl" ),
ClassInterface( ClassInterfaceType.AutoDual ),
Guid( "D34B8507-C286-4d40-83BC-0852E19DEC89" )]
public class ProfilerControl : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Splitter splitter2;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ColumnHeader colID;
private System.Windows.Forms.ColumnHeader colSignature;
private System.Windows.Forms.ColumnHeader colCalls;
private System.Windows.Forms.ColumnHeader colTotalTime;
private System.Windows.Forms.ColumnHeader colTimeInMethod;
private System.Windows.Forms.ColumnHeader colChildrenTime;
private System.Windows.Forms.ColumnHeader colTimeSuspended;
private System.Windows.Forms.ColumnHeader colCalleeID;
private System.Windows.Forms.ColumnHeader colCalleeSignature;
private System.Windows.Forms.ColumnHeader colCalleeCalls;
private System.Windows.Forms.ColumnHeader colCalleeTotalTime;
private System.Windows.Forms.ColumnHeader colCalleeInParent;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ListView _lvFunctionInfo;
private System.Windows.Forms.ListView _lvChildInfo;
private System.Windows.Forms.TreeView _tvNamespaceInfo;
private System.Windows.Forms.ComboBox _cbCurrentThread;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ProfilerControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
_htCheckedItems = new Hashtable();
_bUpdating = false;
_bInCheck = false;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.splitter2 = new System.Windows.Forms.Splitter();
this._lvFunctionInfo = new System.Windows.Forms.ListView();
this.colID = new System.Windows.Forms.ColumnHeader();
this.colSignature = new System.Windows.Forms.ColumnHeader();
this.colCalls = new System.Windows.Forms.ColumnHeader();
this.colTotalTime = new System.Windows.Forms.ColumnHeader();
this.colTimeInMethod = new System.Windows.Forms.ColumnHeader();
this.colChildrenTime = new System.Windows.Forms.ColumnHeader();
this.colTimeSuspended = new System.Windows.Forms.ColumnHeader();
this._lvChildInfo = new System.Windows.Forms.ListView();
this.colCalleeID = new System.Windows.Forms.ColumnHeader();
this.colCalleeSignature = new System.Windows.Forms.ColumnHeader();
this.colCalleeCalls = new System.Windows.Forms.ColumnHeader();
this.colCalleeTotalTime = new System.Windows.Forms.ColumnHeader();
this.colCalleeInParent = new System.Windows.Forms.ColumnHeader();
this.splitter1 = new System.Windows.Forms.Splitter();
this._tvNamespaceInfo = new System.Windows.Forms.TreeView();
this.panel2 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this._cbCurrentThread = new System.Windows.Forms.ComboBox();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.splitter2,
this._lvFunctionInfo,
this._lvChildInfo,
this.splitter1,
this._tvNamespaceInfo,
this.panel2});
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(872, 456);
this.panel1.TabIndex = 10;
//
// splitter2
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(195, 229);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(677, 3);
this.splitter2.TabIndex = 10;
this.splitter2.TabStop = false;
//
// _lvFunctionInfo
//
this._lvFunctionInfo.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colID,
this.colSignature,
this.colCalls,
this.colTotalTime,
this.colTimeInMethod,
this.colChildrenTime,
this.colTimeSuspended});
this._lvFunctionInfo.Dock = System.Windows.Forms.DockStyle.Fill;
this._lvFunctionInfo.FullRowSelect = true;
this._lvFunctionInfo.HideSelection = false;
this._lvFunctionInfo.Location = new System.Drawing.Point(195, 24);
this._lvFunctionInfo.MultiSelect = false;
this._lvFunctionInfo.Name = "_lvFunctionInfo";
this._lvFunctionInfo.Size = new System.Drawing.Size(677, 208);
this._lvFunctionInfo.TabIndex = 3;
this._lvFunctionInfo.View = System.Windows.Forms.View.Details;
this._lvFunctionInfo.SelectedIndexChanged += new System.EventHandler(this._lvFunctionInfo_SelectedIndexChanged);
//
// colID
//
this.colID.Text = "ID";
this.colID.Width = 100;
//
// colSignature
//
this.colSignature.Text = "Signature";
this.colSignature.Width = 350;
//
// colCalls
//
this.colCalls.Text = "# of Calls";
//
// colTotalTime
//
this.colTotalTime.Text = "% of Total";
//
// colTimeInMethod
//
this.colTimeInMethod.Text = "% in Method";
//
// colChildrenTime
//
this.colChildrenTime.Text = "% in Children";
//
// colTimeSuspended
//
this.colTimeSuspended.Text = "% Suspended";
//
// _lvChildInfo
//
this._lvChildInfo.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colCalleeID,
this.colCalleeSignature,
this.colCalleeCalls,
this.colCalleeTotalTime,
this.colCalleeInParent});
this._lvChildInfo.Dock = System.Windows.Forms.DockStyle.Bottom;
this._lvChildInfo.FullRowSelect = true;
this._lvChildInfo.HideSelection = false;
this._lvChildInfo.Location = new System.Drawing.Point(195, 232);
this._lvChildInfo.MultiSelect = false;
this._lvChildInfo.Name = "_lvChildInfo";
this._lvChildInfo.Size = new System.Drawing.Size(677, 224);
this._lvChildInfo.TabIndex = 3;
this._lvChildInfo.View = System.Windows.Forms.View.Details;
this._lvChildInfo.DoubleClick += new System.EventHandler(this._lvChildInfo_DoubleClick);
//
// colCalleeID
//
this.colCalleeID.Text = "ID";
this.colCalleeID.Width = 100;
//
// colCalleeSignature
//
this.colCalleeSignature.Text = "Signature";
this.colCalleeSignature.Width = 400;
//
// colCalleeCalls
//
this.colCalleeCalls.Text = "# of Calls";
//
// colCalleeTotalTime
//
this.colCalleeTotalTime.Text = "% of Total";
//
// colCalleeInParent
//
this.colCalleeInParent.Text = "% of Parent";
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(192, 24);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 432);
this.splitter1.TabIndex = 9;
this.splitter1.TabStop = false;
//
// _tvNamespaceInfo
//
this._tvNamespaceInfo.CheckBoxes = true;
this._tvNamespaceInfo.Dock = System.Windows.Forms.DockStyle.Left;
this._tvNamespaceInfo.ImageIndex = -1;
this._tvNamespaceInfo.Location = new System.Drawing.Point(0, 24);
this._tvNamespaceInfo.Name = "_tvNamespaceInfo";
this._tvNamespaceInfo.SelectedImageIndex = -1;
this._tvNamespaceInfo.Size = new System.Drawing.Size(192, 432);
this._tvNamespaceInfo.TabIndex = 8;
this._tvNamespaceInfo.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this._tvNamespaceInfo_AfterCheck);
this._tvNamespaceInfo.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this._tvNamespaceInfo_AfterSelect);
//
// panel2
//
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this._cbCurrentThread});
this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(872, 24);
this.panel2.TabIndex = 12;
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Left;
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 24);
this.label1.TabIndex = 12;
this.label1.Text = "Thread:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// _cbCurrentThread
//
this._cbCurrentThread.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this._cbCurrentThread.Location = new System.Drawing.Point(48, 0);
this._cbCurrentThread.Name = "_cbCurrentThread";
this._cbCurrentThread.Size = new System.Drawing.Size(136, 21);
this._cbCurrentThread.TabIndex = 11;
this._cbCurrentThread.SelectedIndexChanged += new System.EventHandler(this._cbCurrentThread_SelectedIndexChanged);
//
// ProfilerControl
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1});
this.Name = "ProfilerControl";
this.Size = new System.Drawing.Size(872, 456);
this.Load += new System.EventHandler(this.ProfilerControl_Load);
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.ProfilerControl_Layout);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public Run ProfilerRun
{
set
{
_tic = value.ThreadInfoCollection;
RefreshData();
}
}
private void RefreshData()
{
this.BeginInvoke( new EventHandler( UpdateOnUIThread ), new object[] { null, null } );
}
private void UpdateOnUIThread( object oSender, EventArgs ea )
{
_cbCurrentThread.Items.Clear();
_cbCurrentThread.Sorted = false;
SortedList sl = new SortedList();
// Sort the thread info
foreach ( ThreadInfo ti in _tic )
sl.Add( ti.ID, ti );
// Then add them to the combobox
foreach ( DictionaryEntry de in sl )
_cbCurrentThread.Items.Add( de.Value );
if ( _cbCurrentThread.Items.Count > 0 )
{
_cbCurrentThread.SelectedIndex = 0;
_cbCurrentThread.Enabled = true;
}
else
_cbCurrentThread.Enabled = false;
}
private void _cbCurrentThread_SelectedIndexChanged(object sender, System.EventArgs e)
{
UpdateTree();
UpdateFilters();
}
private void UpdateTree()
{
_tvNamespaceInfo.Nodes.Clear();
_bUpdating = true;
_htCheckedItems = new Hashtable();
try
{
_tvNamespaceInfo.BeginUpdate();
TreeNode tnRoot = _tvNamespaceInfo.Nodes.Add( "All Namespaces" );
tnRoot.Tag = "";
tnRoot.Checked = true;
ThreadInfo tiCurrentThread = _tic[ ( ( ThreadInfo )_cbCurrentThread.SelectedItem ).ID ];
foreach ( FunctionInfo fi in tiCurrentThread.FunctionInfoCollection )
{
TreeNodeCollection tnc = tnRoot.Nodes;
ArrayList alNamespace = new ArrayList();
foreach ( string strNamespacePiece in fi.Signature.Namespace )
{
alNamespace.Add( strNamespacePiece );
TreeNode tnFound = null;
foreach ( TreeNode tn in tnc )
{
if ( tn.Text == strNamespacePiece )
{
tnFound = tn;
break;
}
}
if ( tnFound == null )
{
tnFound = tnc.Add( strNamespacePiece );
tnFound.Tag = String.Join( ".", ( string[] )alNamespace.ToArray( typeof( string ) ) );
tnFound.Checked = true;
}
tnc = tnFound.Nodes;
}
}
tnRoot.Expand();
}
finally
{
_bUpdating = false;
_tvNamespaceInfo.EndUpdate();
}
}
private void UpdateFilters()
{
_lvFunctionInfo.Items.Clear();
_lvChildInfo.Items.Clear();
Hashtable htNamespaces = new Hashtable();
foreach ( TreeNode tn in _htCheckedItems.Keys )
htNamespaces[ tn.Tag ] = null;
IComparer pOldSorter = _lvFunctionInfo.ListViewItemSorter;
try
{
_lvFunctionInfo.BeginUpdate();
_lvFunctionInfo.ListViewItemSorter = null;
ThreadInfo tiCurrentThread = _tic[ ( ( ThreadInfo )_cbCurrentThread.SelectedItem ).ID ];
foreach ( FunctionInfo fi in tiCurrentThread.FunctionInfoCollection )
{
if ( !htNamespaces.Contains( fi.Signature.NamespaceString ) )
continue;
ListViewItem lvi = new ListViewItem( fi.ID.ToString() );
lvi.SubItems.Add( fi.Signature.Signature );
lvi.SubItems.Add( fi.Calls.ToString() );
lvi.SubItems.Add( fi.PercentOfTotalTimeInMethodAndChildren.ToString( "0.00;-0.00;0" ) );
lvi.SubItems.Add( fi.PercentOfTotalTimeInMethod.ToString( "0.00;-0.00;0" ) );
lvi.SubItems.Add( fi.PercentOfTotalTimeInChildren.ToString( "0.00;-0.00;0" ) );
lvi.SubItems.Add( fi.PercentOfTotalTimeSuspended.ToString( "0.00;-0.00;0" ) );
_lvFunctionInfo.Items.Add( lvi );
lvi.Tag = fi;
}
}
finally
{
_lvFunctionInfo.ListViewItemSorter = pOldSorter;
_lvFunctionInfo.EndUpdate();
}
}
private void _tvNamespaceInfo_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
UpdateFilters();
}
private void _tvNamespaceInfo_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
bool bInCheck = _bInCheck;
if ( !bInCheck )
_bInCheck = true;
try
{
if ( e.Node.Checked )
_htCheckedItems[ e.Node ] = null;
else
_htCheckedItems.Remove( e.Node );
if ( _bUpdating )
return;
foreach ( TreeNode tnChild in e.Node.Nodes )
tnChild.Checked = e.Node.Checked;
if ( bInCheck )
return;
}
finally
{
if ( !bInCheck )
_bInCheck = false;
}
UpdateFilters();
}
private Stack _navStackBack = new Stack();
private Stack _navStackForward = new Stack();
private FunctionInfo _navCurrent = null;
private bool _bNavigating = false;
private void UpdateFunctionDisplay(FunctionInfo fi)
{
_lvChildInfo.Items.Clear();
IComparer pOldSorter = _lvChildInfo.ListViewItemSorter;
try
{
_lvChildInfo.BeginUpdate();
_lvChildInfo.ListViewItemSorter = null;
foreach ( CalleeFunctionInfo cfi in fi.CalleeInfo )
{
ListViewItem lvi = new ListViewItem( cfi.ID.ToString() );
lvi.SubItems.Add( cfi.Signature );
lvi.SubItems.Add( cfi.Calls.ToString() );
lvi.SubItems.Add( cfi.PercentOfTotalTimeInMethod.ToString( "0.00;-0.00;0" ) );
lvi.SubItems.Add( cfi.PercentOfParentTimeInMethod.ToString( "0.00;-0.00;0" ) );
lvi.Tag = cfi;
_lvChildInfo.Items.Add( lvi );
}
if ( fi.TotalSuspendedTicks > 0 )
{
ListViewItem lviSuspend = new ListViewItem( "(suspend)" );
lviSuspend.SubItems.Add( "(thread suspended)" );
lviSuspend.SubItems.Add( "-" );
lviSuspend.SubItems.Add( fi.PercentOfTotalTimeSuspended.ToString( "0.00;-0.00;0" ) );
lviSuspend.SubItems.Add( fi.PercentOfMethodTimeSuspended.ToString( "0.00;-0.00;0" ) );
_lvChildInfo.Items.Add( lviSuspend );
}
}
finally
{
_lvChildInfo.ListViewItemSorter = pOldSorter;
_lvChildInfo.EndUpdate();
}
}
private void _lvFunctionInfo_SelectedIndexChanged(object sender, System.EventArgs e)
{
if ( _lvFunctionInfo.SelectedItems.Count == 0 )
{
_lvChildInfo.Items.Clear();
return;
}
FunctionInfo fi = ( FunctionInfo )_lvFunctionInfo.SelectedItems[ 0 ].Tag;
// somebody clicked! empty the forward stack and push this click on the "Back" stack.
if (!_bNavigating)
{
_navStackForward.Clear();
if (_navCurrent != null)
_navStackBack.Push(_navCurrent);
_navCurrent = fi;
}
UpdateFunctionDisplay(fi);
}
public void NavigateBackward()
{
if (_navStackBack.Count == 0)
return;
_navStackForward.Push(_navCurrent);
_navCurrent = (FunctionInfo) _navStackBack.Pop();
_bNavigating = true;
JumpToID(_navCurrent.ID);
_bNavigating = false;
}
public void NavigateForward()
{
if (_navStackForward.Count == 0)
return;
_navStackBack.Push(_navCurrent);
_navCurrent = (FunctionInfo) _navStackForward.Pop();
_bNavigating = true;
JumpToID(_navCurrent.ID);
_bNavigating = false;
}
private void ProfilerControl_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
}
private void ProfilerControl_Load(object sender, System.EventArgs e)
{
_lvsFunction = new ListViewSorter();
_lvsFunction.SetColumns( new ListViewCompareType[] {
ListViewCompareType.Float,
ListViewCompareType.String,
ListViewCompareType.Float,
ListViewCompareType.Float,
ListViewCompareType.Float,
ListViewCompareType.Float,
ListViewCompareType.Float,
} );
_lvsFunction.SortColumn( _lvFunctionInfo, 1 );
_lvFunctionInfo.ListViewItemSorter = _lvsFunction;
_lvFunctionInfo.ColumnClick += new ColumnClickEventHandler( _lvsFunction.OnListViewColumnClick );
_lvsCalleeFunction = new ListViewSorter();
_lvsCalleeFunction.SetColumns( new ListViewCompareType[] {
ListViewCompareType.Float,
ListViewCompareType.String,
ListViewCompareType.Float,
ListViewCompareType.Float,
ListViewCompareType.Float,
} );
_lvsCalleeFunction.SortColumn( _lvChildInfo, 1 );
_lvChildInfo.ListViewItemSorter = _lvsCalleeFunction;
_lvChildInfo.ColumnClick += new ColumnClickEventHandler( _lvsCalleeFunction.OnListViewColumnClick );
}
private void _lvChildInfo_DoubleClick(object sender, System.EventArgs e)
{
if ( _lvChildInfo.SelectedItems.Count == 0 )
return;
CalleeFunctionInfo cfi = ( CalleeFunctionInfo )_lvChildInfo.SelectedItems[ 0 ].Tag;
if ( cfi == null )
MessageBox.Show( "No information available for this item" );
else
JumpToID( cfi.ID );
}
private void JumpToID( int nID )
{
foreach ( ListViewItem lvi in _lvFunctionInfo.Items )
{
FunctionInfo fi = ( FunctionInfo )lvi.Tag;
if ( fi.ID == nID )
{
_lvFunctionInfo.SelectedItems.Clear();
_lvFunctionInfo.Refresh();
lvi.Selected = true;
lvi.EnsureVisible();
_lvFunctionInfo.Refresh();
break;
}
}
}
private int GetSelectedID()
{
if ( _lvChildInfo.SelectedItems.Count == 0 )
return -1;
return ( ( FunctionInfo )_lvFunctionInfo.SelectedItems[ 0 ].Tag ).ID;
}
private ThreadInfoCollection _tic;
private bool _bUpdating, _bInCheck;
private Hashtable _htCheckedItems;
private ListViewSorter _lvsFunction;
private ListViewSorter _lvsCalleeFunction;
}
}