public void Add( ProjectInfo pi ) { if ( pi.Name == null ) pi.Name = GetNewProjectName(); _alItems.Add( pi ); if ( ProjectAdded != null ) ProjectAdded( this, pi, _alItems.Count - 1 ); }
/// <summary> /// Create a <see cref="ProjectInfo"/> from the given arguments. /// </summary> /// <param name="args">The arguments</param> /// <returns>A <see cref="ProjectInfo"/> structure, or null if it could not be created</returns> static ProjectInfo CreateProjectInfo( string[] args ) { ProjectInfo pInfo = new ProjectInfo( ProjectType.File ); pInfo.Arguments = pInfo.WorkingDirectory = pInfo.ApplicationName = String.Empty; foreach ( string arg in args ) { string upperArg = arg.ToUpper(); if ( upperArg.StartsWith( "/R:" ) ) { pInfo.ApplicationName = Path.GetFullPath( arg.Substring( 3 ) ); Console.WriteLine( "Application: " + pInfo.ApplicationName ); } else if ( upperArg.StartsWith( "/W:" ) ) { pInfo.WorkingDirectory = arg.Substring( 3 ); Console.WriteLine( "Working Directory: " + pInfo.WorkingDirectory ); } else if ( upperArg.StartsWith( "/A:" ) ) { pInfo.Arguments = arg.Substring( 3 ); Console.WriteLine( "Arguments: " + pInfo.Arguments ); } else if ( upperArg.Equals( "/V" ) ) { PrintVersion(); return null; } else if ( upperArg.Equals( "/HELP" ) || upperArg.Equals( "/H" ) || upperArg.Equals( "/?" ) || upperArg.Equals( "-H" ) || upperArg.Equals( "-HELP" ) || upperArg.Equals( "--HELP" ) ) { PrintUsage(); return null; } else { Console.WriteLine( @"Error: Unrecognized argument ""{0}"". Use /help for usage details.", arg ); return null; } } // Check if the user has specified an application to run if ( pInfo.ApplicationName.Length == 0 ) { Console.WriteLine( "Error: You need to specify an application to run." ); return null; } // Set the working directory, if not specified if ( pInfo.WorkingDirectory.Length == 0 ) { // Note: if the pInfo.Name is rooted, it will override the app startup path pInfo.WorkingDirectory = Path.Combine( Directory.GetCurrentDirectory(), Path.GetDirectoryName( pInfo.ApplicationName ) ); } return pInfo; }
public Run( Profiler p, ProjectInfo pi ) { _p = p; _dtStart = DateTime.Now; _dtEnd = DateTime.MaxValue; _rs = RunState.Initializing; _tic = new ThreadInfoCollection(); _pi = pi; _rmcMessages = new RunMessageCollection(); _bSuccess = false; }
public ProfilerProjectOptionsForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // _ppm = ProfilerProjectMode.CreateProject; _p = new ProjectInfo( ProjectType.File ); }
public ProfilerForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // _stackBack = new Stack(); _stackForward = new Stack(); _p = new Profiler(); //_p.ProcessCompleted += new Profiler.ProcessCompletedHandler( OnProfileComplete ); _p.Error += new Profiler.ErrorHandler( OnError ); _piInitialProject = null; }
public int IndexOf( ProjectInfo pi ) { return _alItems.IndexOf( pi ); }
public void Insert( int index, ProjectInfo pi ) { if ( pi.Name == null ) pi.Name = GetNewProjectName(); _alItems.Insert( index, pi ); if ( ProjectAdded != null ) ProjectAdded( this, pi, index ); }
private bool SaveProject( ProjectInfo project, bool forceSaveDialog ) { if ( project == null ) return true; MessageBox.Show( this, "NOTE: You might not be able to load the data you're saving. Please keep this in mind.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Warning ); string filename = SerializationHandler.GetFilename( project ); if( forceSaveDialog || filename == string.Empty ) { SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.DefaultExt = "nprof"; saveDlg.FileName = SerializationHandler.GetFilename( project );; saveDlg.Filter = "NProf projects (*.nprof)|*.nprof|All files (*.*)|*.*"; // saveDlg.InitialDirectory = TODO: store the most recently used direcotry somewhere and go there saveDlg.Title = "Save a NProf project file"; if( saveDlg.ShowDialog( this ) != DialogResult.OK ) return false; project.Name = Path.GetFileNameWithoutExtension( saveDlg.FileName ); filename = saveDlg.FileName; } SerializationHandler.SaveProjectInfo( project, filename ); return true; }
public bool Contains( ProjectInfo pi ) { return _alItems.Contains(pi); }
private void OnProjectAdded( ProjectInfoCollection projects, ProjectInfo pi, int nIndex ) { AddProjectNode( pi ); }
private void OnRunAdded( ProjectInfo pi, RunCollection runs, Run run, int nIndex ) { foreach ( TreeNode tn in _tvProjects.Nodes ) { if ( tn.Tag == pi ) AddRunNode( tn, run ); } }
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 ); }
private void AddProjectNode( ProjectInfo pi ) { TreeNode tn = ( TreeNode )_tvProjects.Invoke( new TreeNodeAdd( OnTreeNodeAdd ), new object[]{ _tvProjects.Nodes, pi.Name, 0, pi } ); tn.ImageIndex = 0; pi.Runs.RunAdded += new RunCollection.RunEventHandler( OnRunAdded ); pi.Runs.RunRemoved += new RunCollection.RunEventHandler( OnRunRemoved ); foreach ( Run run in pi.Runs ) { AddRunNode( tn, run ); } }
public bool Start( ProjectInfo pi, Run run, ProcessCompletedHandler pch ) { _dtStart = DateTime.Now; _pi = pi; _pch = pch; _run = run; _run.State = Run.RunState.Initializing; _pss = new ProfilerSocketServer( pi.Options, run ); _pss.Start(); _pss.Exited += new EventHandler( OnProcessExited ); _pss.Error += new ProfilerSocketServer.ErrorHandler( OnError ); _pss.Message += new ProfilerSocketServer.MessageHandler( OnMessage ); switch ( pi.ProjectType ) { case ProjectType.File: { _p = new Process(); _p.StartInfo = new ProcessStartInfo( pi.ApplicationName, pi.Arguments ); _p.StartInfo.EnvironmentVariables[ "COR_ENABLE_PROFILING" ] = "0x1"; _p.StartInfo.EnvironmentVariables[ "COR_PROFILER" ] = PROFILER_GUID; _p.StartInfo.EnvironmentVariables[ "NPROF_PROFILING_SOCKET" ] = _pss.Port.ToString(); _p.StartInfo.UseShellExecute = false; _p.StartInfo.Arguments = pi.Arguments; _p.StartInfo.WorkingDirectory = pi.WorkingDirectory; _p.EnableRaisingEvents = true; _p.Exited += new EventHandler( OnProcessExited ); return _p.Start(); } case ProjectType.AspNet: { using ( RegistryKey rk = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\W3SVC", true ) ) { if ( rk != null ) SetRegistryKeys( rk, true ); } using ( RegistryKey rk = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\IISADMIN", true ) ) { if ( rk != null ) SetRegistryKeys( rk, true ); } Process p = Process.Start( "iisreset.exe", "" ); p.WaitForExit(); _run.Messages.AddMessage( "Navigate to your project and ASP.NET will connect to the profiler" ); _run.Messages.AddMessage( "NOTE: ASP.NET must be set to run under the SYSTEM account in machine.config" ); _run.Messages.AddMessage( @"If ASP.NET cannot be profiled, ensure that the userName=""SYSTEM"" in the <processModel> section of machine.config." ); return true; } case ProjectType.VSNet: { SetEnvironmentVariable( "COR_ENABLE_PROFILING", "0x1" ); SetEnvironmentVariable( "COR_PROFILER", PROFILER_GUID ); SetEnvironmentVariable( "NPROF_PROFILING_SOCKET", _pss.Port.ToString() ); return true; } default: throw new InvalidOperationException( "Unknown project type: " + pi.ProjectType ); } }
private void OnProjectAdded( ProjectInfoCollection projects, ProjectInfo pi, int nIndex ) { pi.ProjectInfoChanged += new ProjectInfo.ProjectEventHandler( OnProjectChanged ); AddProjectNode( pi ); }
private void OnProjectChanged( ProjectInfo pi ) { TreeNode tn = FindProjectNode( pi ); _tvProjects.Invoke( new TreeNodeUpdate( OnTreeNodeUpdate ), new object[] { tn } ); }
private void _pic_ProjectRemoved(ProjectInfoCollection projects, ProjectInfo project, int nIndex) { foreach ( Run run in project.Runs ) { foreach ( Crownwood.Magic.Controls.TabPage tp in _tcProfilers.TabPages ) { if ( tp.Tag == run ) { _tcProfilers.TabPages.Remove ( tp ); break; } } } CheckAddBlankTab(); }
public ProfilerForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // _stackBack = new Stack(); _stackForward = new Stack(); _p = new Profiler(); //_p.ProcessCompleted += new Profiler.ProcessCompletedHandler( OnProfileComplete ); _p.Error += new Profiler.ErrorHandler( OnError ); _piInitialProject = null; string strDirectory = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ); string strDLL = Path.Combine( strDirectory, "msvcr70.dll" ); if ( LoadLibrary( strDLL ) == 0 ) throw new Win32Exception( Marshal.GetLastWin32Error(), "Failed to load msvcr10.dll" ); }
public void Remove( ProjectInfo pi ) { this.RemoveAt( this.IndexOf( pi ) ); }
private void _pt_ProjectDoubleClicked( ProjectInfo pi ) { _cmdProjectOptions_Click( null, null ); }
public int Add( ProjectInfo pi ) { int index = _alItems.Count; this.Insert( index, pi ); return index; }
public void SelectProject( ProjectInfo pi ) { _tvProjects.SelectedNode = FindProjectNode( pi ); }
private TreeNode FindProjectNode( ProjectInfo pi ) { foreach ( TreeNode tn in _tvProjects.Nodes ) if ( tn.Tag == pi ) return tn; return null; }
private static void MakeRecentlyUsed( ProjectInfo project, string fileName ) { UsedFile[] usedFiles = ProjectsHistory; bool found = false; foreach( UsedFile usedFile in usedFiles ) { if( usedFile.FileName == fileName ) { usedFile.LastUsed = DateTime.Now; usedFile.ProjectName = project.Name; found = true; break; } } if( !found ) { UsedFile[] temp = usedFiles; usedFiles = new UsedFile[ usedFiles.Length + 1]; Array.Copy( temp, usedFiles, temp.Length ); UsedFile uf = new UsedFile( fileName, project.Name, DateTime.Now ); usedFiles[ temp.Length ] = uf; } InternalProjectsHistory = usedFiles; }
private void OnProjectRemoved( ProjectInfoCollection projects, ProjectInfo pi, int nIndex ) { _tvProjects.Invoke( new TreeNodeRemove( OnTreeNodeRemove ), new object[]{ _tvProjects.Nodes[ nIndex ] } ); }
/// <summary> /// Will return the filename of a ProjectInfo /// </summary> /// <param name="info">The ProjectInfo to lookup the filename for</param> /// <returns>The filename of the ProjectInfo or empty string if not known</returns> public static string GetFilename( ProjectInfo info ) { return ( ( string )_projectInfoToFileNameMap[ info ] ) + string.Empty; }
private void OnRunRemoved( ProjectInfo pi, RunCollection runs, Run run, int nIndex ) { //_tvProjects.Nodes.RemoveAt( nIndex ); }
private void OnProjectRemoved( ProjectInfoCollection projects, ProjectInfo pi, int nIndex ) { pi.ProjectInfoChanged -= new ProjectInfo.ProjectEventHandler( OnProjectChanged ); _tvProjects.Invoke( new TreeNodeRemove( OnTreeNodeRemove ), new object[]{ _tvProjects.Nodes[ nIndex ] } ); }
public RunCollection( ProjectInfo pi ) { _pi = pi; _alItems = new ArrayList(); }
/// <summary> /// Saves a ProjectInfo into the specified filename /// </summary> /// <param name="info">The ProjectInfo to save</param> /// <param name="fileName">The file to save it in</param> public static void SaveProjectInfo( ProjectInfo info, string fileName ) { ZipOutputStream zos = new ZipOutputStream( File.Create( fileName ) ); zos.SetLevel( 7 ); // Set the file format version FileFormat ff = new FileFormat(); ff.Version = 0; ff.Program = "NProf v0.8"; AddFileToZip( zos, "NProfFileFormat.xml" ); XmlSerializer sff = new XmlSerializer( typeof( FileFormat ) ); sff.Serialize( zos, ff ); // put that buffer as a file into a zip file AddFileToZip( zos, "ProjectInfo.xml" ); XmlSerializer s = new XmlSerializer( typeof( ProjectInfo ) ); s.Serialize( zos, info ); XmlSerializer xsRun = new XmlSerializer( typeof( Run ) ); int nIndex = 0; foreach ( Run r in info.Runs ) { string strFilename = String.Format( "Run-{0:00000000}.xml", nIndex ); AddFileToZip( zos, strFilename ); xsRun.Serialize( zos, r ); nIndex++; } zos.Close(); // remember for later _projectInfoToFileNameMap[ info ] = fileName; // make it recently used MakeRecentlyUsed( info, fileName ); }