Пример #1
0
        public void Add( ProjectInfo pi )
        {
            if ( pi.Name == null )
                pi.Name = GetNewProjectName();

            _alItems.Add( pi );
            if ( ProjectAdded != null )
                ProjectAdded( this, pi, _alItems.Count - 1 );
        }
Пример #2
0
        /// <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;
        }
Пример #3
0
 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;
 }
Пример #4
0
        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 );
        }
Пример #5
0
        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;
        }
Пример #6
0
 public int IndexOf( ProjectInfo pi )
 {
     return _alItems.IndexOf( pi );
 }
Пример #7
0
        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 );
        }
Пример #8
0
        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;
        }
Пример #9
0
 public bool Contains( ProjectInfo pi )
 {
     return _alItems.Contains(pi);
 }
Пример #10
0
 private void OnProjectAdded( ProjectInfoCollection projects, ProjectInfo pi, int nIndex )
 {
     AddProjectNode( pi );
 }
Пример #11
0
 private void OnRunAdded( ProjectInfo pi, RunCollection runs, Run run, int nIndex )
 {
     foreach ( TreeNode tn in _tvProjects.Nodes )
     {
         if ( tn.Tag == pi )
             AddRunNode( tn, run );
     }
 }
Пример #12
0
        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 );
        }
Пример #13
0
        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 );
            }
        }
Пример #14
0
        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 );
            }
        }
Пример #15
0
 private void OnProjectAdded( ProjectInfoCollection projects, ProjectInfo pi, int nIndex )
 {
     pi.ProjectInfoChanged += new ProjectInfo.ProjectEventHandler( OnProjectChanged );
     AddProjectNode( pi );
 }
Пример #16
0
 private void OnProjectChanged( ProjectInfo pi )
 {
     TreeNode tn = FindProjectNode( pi );
     _tvProjects.Invoke( new TreeNodeUpdate( OnTreeNodeUpdate ), new object[] { tn } );
 }
Пример #17
0
        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();
        }
Пример #18
0
        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" );
        }
Пример #19
0
 public void Remove( ProjectInfo pi )
 {
     this.RemoveAt( this.IndexOf( pi ) );
 }
Пример #20
0
 private void _pt_ProjectDoubleClicked( ProjectInfo pi )
 {
     _cmdProjectOptions_Click( null, null );
 }
Пример #21
0
        public int Add( ProjectInfo pi )
        {
            int index = _alItems.Count;

            this.Insert( index, pi );

            return index;
        }
Пример #22
0
 public void SelectProject( ProjectInfo pi )
 {
     _tvProjects.SelectedNode = FindProjectNode( pi );
 }
Пример #23
0
        private TreeNode FindProjectNode( ProjectInfo pi )
        {
            foreach ( TreeNode tn in _tvProjects.Nodes )
                if ( tn.Tag == pi )
                    return tn;

            return null;
        }
Пример #24
0
        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;
        }
Пример #25
0
 private void OnProjectRemoved( ProjectInfoCollection projects, ProjectInfo pi, int nIndex )
 {
     _tvProjects.Invoke( new TreeNodeRemove( OnTreeNodeRemove ), new object[]{ _tvProjects.Nodes[ nIndex ] } );
 }
Пример #26
0
 /// <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;
 }
Пример #27
0
 private void OnRunRemoved( ProjectInfo pi, RunCollection runs, Run run, int nIndex )
 {
     //_tvProjects.Nodes.RemoveAt( nIndex );
 }
Пример #28
0
 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 ] } );
 }
Пример #29
0
 public RunCollection( ProjectInfo pi )
 {
     _pi = pi;
     _alItems = new ArrayList();
 }
Пример #30
0
        /// <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 );
        }