示例#1
0
        public Run CreateRun( Profiler p )
        {
            Run run = new Run( p, this );
            _rc.Add( run );

            return run;
        }
示例#2
0
        public ProfilerSocketServer( Project.Options po, Run run )
        {
            _run = run;
            _nStopFlag = 0;
            _po = po;
            _bHasStopped = false;
            _nCurrentApplicationID = 0;
            _nProfileCount = 0;

            _run.Messages.AddMessage( "Waiting for application..." );
        }
示例#3
0
        public ProfilerSocketServer( Project.Options po, Run run )
        {
            _fsm = new FunctionSignatureMap();
            _run = run;
            _tic = run.ThreadInfoCollection;
            _nStopFlag = 0;
            _po = po;
            _bHasStopped = false;

            _run.Messages.AddMessage( "Waiting for application..." );
        }
示例#4
0
        private void AddRunNode( TreeNode tnProject, Run run )
        {
            _tvProjects.Invoke( new TreeNodeAdd( OnTreeNodeAdd ), new object[]{ tnProject.Nodes, run.StartTime.ToString(), GetRunStateImage( run ), run } );

            run.StateChanged += new Run.RunStateEventHandler( OnRunStateChanged );
        }
示例#5
0
 public void SelectRun( Run run )
 {
     _tvProjects.SelectedNode = FindRunNode( run );
 }
示例#6
0
文件: Run.cs 项目: ilya11211/nprof
 private void OnProfileComplete( Run run )
 {
     State = RunState.Finished;
     _dtEnd = DateTime.Now;
 }
示例#7
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 );
            }
        }
示例#8
0
 private void OnRunStateChanged( Run run, Run.RunState rsOld, Run.RunState rsNew )
 {
     TreeNode tn = FindRunNode( run );
     _tvProjects.Invoke( new TreeNodeSetState( OnTreeNodeSetState ), new object[]{ tn, run.StartTime.ToString(), GetRunStateImage( run ) } );
 }
示例#9
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 );
     }
 }
示例#10
0
        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 );
            }
        }
示例#11
0
 private void OnProfileStateChange( Run run )
 {
     this.BeginInvoke( new HandleProfileComplete( OnUIThreadProfileComplete ), new object[] { run } );
 }
示例#12
0
        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;
        }
示例#13
0
 private void OnRunStateChangedUIThread( Run run, Run.RunState rsOld, Run.RunState rsNew )
 {
     _lblState.Text = "Current state: " + rsNew.ToString();
     if ( rsNew == Run.RunState.Finished )
         _lblState.Text += ( run.Success ) ? " successfully" : " unsuccessfully";
     _btnStop.Enabled = _r.CanStop;
 }
示例#14
0
 private void OnRunStateChanged( Run run, Run.RunState rsOld, Run.RunState rsNew )
 {
     _lvMessages.Invoke( new Run.RunStateEventHandler( OnRunStateChangedUIThread ), new object[] { run, rsOld, rsNew } );
 }
示例#15
0
        private void OnProcessExited( object oSender, EventArgs ea )
        {
            // This gets called twice for file projects - FIXME
            if ( _run == null )
                return;

            if ( !_pss.HasStoppedGracefully )
            {
                if ( _run.State == Run.RunState.Initializing )
                {
                    _run.Messages.AddMessage( "No connection made with profiled application." );
                    _run.Messages.AddMessage( "Application might not support .NET." );
                }
                else
                {
                    _run.Messages.AddMessage( "Application stopped before profiler information could be retrieved." );
                }

                _run.Success = false;
                _run.State = Run.RunState.Finished;
                _run.Messages.AddMessage( "Profiler run did not complete successfully." );
            }
            else
            {
                _run.Success = true;
            }

            _dtEnd = DateTime.Now;
            _run.Messages.AddMessage( "Stopping profiler listener..." );
            _pss.Stop();
            //			if ( ProcessCompleted != null )
            //				ProcessCompleted( _pss.ThreadInfoCollection );

            _run.EndTime = _dtEnd;
            _run.ThreadInfoCollection = _pss.ThreadInfoCollection;

            _pch( _run );
            _run = null;
        }
示例#16
0
        private TreeNode FindRunNode( Run run )
        {
            TreeNode tnProject = FindProjectNode( run.Project );
            if ( tnProject == null )
                return null;

            foreach ( TreeNode tnRun in tnProject.Nodes )
                if ( tnRun.Tag == run )
                    return tnRun;

            return null;
        }
示例#17
0
        private int GetRunStateImage( Run r )
        {
            switch ( r.State )
            {
                case Run.RunState.Initializing:
                    return 1;
                case Run.RunState.Running:
                    return 2;
                case Run.RunState.Finished:
                    return r.Success ? 3 : 4;
            }

            return 0;
        }
示例#18
0
 private void OnUIThreadProfileComplete( Run run )
 {
     CreateTabPage( run );
 }
示例#19
0
 private void OnRunRemoved( ProjectInfo pi, RunCollection runs, Run run, int nIndex )
 {
     //_tvProjects.Nodes.RemoveAt( nIndex );
 }
示例#20
0
        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 );
        }
示例#21
0
 public void Add( Run run )
 {
     _alItems.Add( run );
     if ( RunAdded != null )
         RunAdded( _pi, this, run, _alItems.Count - 1 );
 }
示例#22
0
        public void Stop()
        {
            Run run;

            lock ( _oRunLock )
            {
                run = _run;

                // Is there anything to stop?
                if ( _run == null )
                    return;

                _run = null;
            }

            // Stop the profiler socket server if profilee hasn't connected
            if ( run.State == Run.RunState.Initializing )
            {
                run.Messages.AddMessage( "Shutting down profiler..." );
                _pss.Stop();
                run.State = Run.RunState.Finished;
                run.Success = false;
            }

            if ( _pi.ProjectType == ProjectType.AspNet )
            {
                using ( RegistryKey rk = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\W3SVC", true ) )
                {
                    if ( rk != null )
                        SetRegistryKeys( rk, false );
                }

                using ( RegistryKey rk = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\IISADMIN", true ) )
                {
                    if ( rk != null )
                        SetRegistryKeys( rk, false );
                }

                run.Messages.AddMessage( "Terminating ASP.NET..." );
                Process.Start( "iisreset.exe", "/stop" ).WaitForExit();
            }
        }