Beispiel #1
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;
            }
        }