示例#1
0
        private void EnsureLogStatus()
        {
            string path = GetStatusFilePath();

            if (chkLogEnabled.Checked)
            {
                ProfilerUtils.CreateFile(path);
            }
            else
            {
                ProfilerUtils.DeleteFile(path);
            }
        }
示例#2
0
        private void ProfilerStopped()
        {
            timer1.Enabled           = false;
            btnStart.Enabled         = true;
            btnStop.Enabled          = false;
            btnDeleteLogFile.Enabled = true;

            try
            {
                string path = GetStatusFilePath();
                ProfilerUtils.DeleteFile(path);
            }
            catch { }
        }
示例#3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txtLogPath.Text) && !Directory.Exists(txtLogPath.Text))
            {
                SimpleMessage.ShowError("Invalid log path!");
                return;
            }

            if (_inStarting)
            {
                return;
            }

            try
            {
                _inStarting = true;

                // save config
                Config.ProfilerASPNetFilter  = txtFilter.Text;
                Config.ProfilerASPNetLogPath = txtLogPath.Text;

                Config.ProfilerASPNetTraceEvent     = chkTraceEvent.Checked;
                Config.ProfilerASPNetTraceParameter = chkTraceParam.Checked;
                Config.ProfilerASPNetIncludeSystem  = chkIncludeSystem.Checked;


                //register profiler
                ProfilerUtils.RegisterProfiler();

                //stop iis
                StopIIS();

                //get log file
                string logDir = txtLogPath.Text;
                if (String.IsNullOrEmpty(logDir) || !Directory.Exists(logDir))
                {
                    logDir = PathUtils.GetTempDir();
                }
                _logFile        = Path.Combine(logDir, ProfilerUtils.PROFILER_LOG);
                txtLogFile.Text = _logFile;

                if (File.Exists(_logFile))
                {
                    File.Delete(_logFile);
                }

                EnsureLogStatus();

                // set environment variables
                string[] profilerEnvironment = new string[]
                {
                    "COR_ENABLE_PROFILING=0x1",
                    "COR_PROFILER=" + Consts.ProfilerGuid,
                    "SP_LOG_PATH=" + logDir,
                    "SP_FILTER=" + txtFilter.Text.Trim(),
                    "SP_INCLUDE_SYSTEM=" + (chkIncludeSystem.Checked?"1":"0"),
                    "SP_TRACE_PARAMETER=" + (chkTraceParam.Checked ? "1" : "0"),
                    "SP_TRACE_EVENT=" + (chkTraceEvent.Checked ? "1" : "0")
                };

                string[] baseEnvironment = ProfilerUtils.GetServicesEnvironment();
                baseEnvironment = ProfilerUtils.ReplaceTempDir(baseEnvironment, PathUtils.GetTempDir());
                string[] combinedEnvironment = ProfilerUtils.CombineEnvironmentVariables(baseEnvironment, profilerEnvironment);
                ProfilerUtils.SetEnvironmentVariables("IISADMIN", combinedEnvironment);
                ProfilerUtils.SetEnvironmentVariables("W3SVC", combinedEnvironment);
                ProfilerUtils.SetEnvironmentVariables("WAS", combinedEnvironment);

                string asp_netAccountName = GetASPNetAccountName();
                string asp_netAccountSid  = null;
                if (asp_netAccountName != null)
                {
                    asp_netAccountSid = ProfilerUtils.LookupAccountSid(asp_netAccountName);
                    if (asp_netAccountSid != null)
                    {
                        ProfilerUtils.SetAccountEnvironment(asp_netAccountSid, profilerEnvironment);
                    }
                }

                if (StartIIS())
                {
                    //_mainForm.SetStatusText("It's time to load your ASP.Net page.");
                    lblLogSize.Text = "It's time to load your ASP.Net page.";

                    Thread.Sleep(1000);

                    timer1.Enabled           = true;
                    btnStart.Enabled         = false;
                    btnStop.Enabled          = true;
                    btnDeleteLogFile.Enabled = false;
                }

                /* Delete the environment variables as early as possible, so that even if CLRProfiler crashes, the user's machine
                 * won't be screwed up.
                 * */

                ProfilerUtils.DeleteEnvironmentVariables("IISADMIN");
                ProfilerUtils.DeleteEnvironmentVariables("W3SVC");
                ProfilerUtils.DeleteEnvironmentVariables("WAS");

                if (asp_netAccountSid != null)
                {
                    ProfilerUtils.ResetAccountEnvironment(asp_netAccountSid, profilerEnvironment);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                _inStarting = false;
            }
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            string appFile = txtApp.Text;

            if (String.IsNullOrEmpty(appFile) || !File.Exists(appFile))
            {
                SimpleMessage.ShowError("Cannot find application!");
                return;
            }
            if (!String.IsNullOrEmpty(txtLogPath.Text) && !Directory.Exists(txtLogPath.Text))
            {
                SimpleMessage.ShowError("Invalid log path!");
                return;
            }

            if (_inStarting)
            {
                return;
            }

            try
            {
                _inStarting = true;

                Config.ProfilerAppFile     = txtApp.Text;
                Config.ProfilerAppArgument = txtArg.Text;
                Config.ProfilerAppFilter   = txtFilter.Text;
                Config.ProfilerAppLogPath  = txtLogPath.Text;

                Config.ProfilerAppTraceEvent     = chkTraceEvent.Checked;
                Config.ProfilerAppTraceParameter = chkTraceParam.Checked;
                Config.ProfilerAppIncludeSystem  = chkIncludeSystem.Checked;

                ProfilerUtils.RegisterProfiler();

                if (profiledProcess == null || ProfiledProcessHasExited())
                {
                    ProcessStartInfo processStartInfo = new ProcessStartInfo(appFile);
                    processStartInfo.EnvironmentVariables["COR_ENABLE_PROFILING"] = "0x1";
                    processStartInfo.EnvironmentVariables["COR_PROFILER"]         = Consts.ProfilerGuid;
                    if (!String.IsNullOrEmpty(txtArg.Text))
                    {
                        processStartInfo.Arguments = txtArg.Text;
                    }

                    processStartInfo.WorkingDirectory = Path.GetDirectoryName(appFile);

                    if (!String.IsNullOrEmpty(txtLogPath.Text) && Directory.Exists(txtLogPath.Text))
                    {
                        _logFile = Path.Combine(txtLogPath.Text, ProfilerUtils.PROFILER_LOG);
                    }
                    else
                    {
                        _logFile = Path.Combine(processStartInfo.WorkingDirectory, ProfilerUtils.PROFILER_LOG);
                    }
                    txtLogFile.Text = _logFile;
                    processStartInfo.EnvironmentVariables["SP_LOG_PATH"] = Path.GetDirectoryName(txtLogFile.Text);

                    if (File.Exists(_logFile))
                    {
                        File.Delete(_logFile);
                    }

                    EnsureLogStatus();

                    if (!String.IsNullOrEmpty(txtFilter.Text))
                    {
                        processStartInfo.EnvironmentVariables["SP_FILTER"] = txtFilter.Text.Trim();
                    }

                    processStartInfo.EnvironmentVariables["SP_INCLUDE_SYSTEM"]  = (chkIncludeSystem.Checked ? "1" : "0");
                    processStartInfo.EnvironmentVariables["SP_TRACE_PARAMETER"] = (chkTraceParam.Checked ? "1" : "0");
                    processStartInfo.EnvironmentVariables["SP_TRACE_EVENT"]     = (chkTraceEvent.Checked ? "1" : "0");

                    processStartInfo.UseShellExecute = false;
                    profiledProcess = Process.Start(processStartInfo);

                    timer1.Enabled           = true;
                    btnStart.Enabled         = false;
                    btnStop.Enabled          = true;
                    btnDeleteLogFile.Enabled = false;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                _inStarting = false;
            }
        }