Esempio n. 1
0
        private void PopulateAnalysisTabs()
        {
            lblInitialAnalysisPrompt.Visible = false;
            if (connSqlDb.State != ConnectionState.Closed)
            {
                connSqlDb.Close();
            }
            if (File.Exists(m_analysisPath))
            {
                if (!m_analysisPath.EndsWith(".zip"))
                {
                    AnalysisTraceID = m_analysisPath.Substring(0, m_analysisPath.LastIndexOf(".")).Substring(m_analysisPath.LastIndexOf("\\") + 1).TrimEnd("0123456789".ToCharArray());
                }
            }
            else
            {
                AnalysisTraceID = GetAnalysisIDFromLog();
            }

            foreach (TabPage t in tcAnalysis.TabPages)
            {
                if (t.Name == "tbProfilerTraces")
                {
                    HiddenTabPages.Add(t);
                }
            }
            tcAnalysis.TabPages.Clear();
            btnImportProfilerTrace.Visible = true;

            string mdfPath = "";

            if (m_analysisPath != null)
            {
                if (m_analysisPath.EndsWith(".zip"))
                {
                    SelectivelyExtractAnalysisDataFromZip();
                }

                if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith("\\msmdsrv.ini")) || File.Exists(m_analysisPath + "\\msmdsrv.ini"))
                {
                    tcAnalysis.TabPages.Add(new TabPage("Configuration")
                    {
                        ImageIndex = 0, Name = "Configuration"
                    });
                    tcAnalysis.TabPages["Configuration"].Controls.Add(GetStatusTextBox("Check back soon for automated analysis of configuration details."));
                }
                if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".mdmp")) ||
                    (!File.Exists(m_analysisPath) && Directory.GetFiles(m_analysisPath, "*.mdmp", SearchOption.AllDirectories).Count() > 0))
                {
                    if (ValidateProfilerTraceDBConnectionStatus())
                    {
                        ucASDumpAnalyzer DumpAnalyzer = new ucASDumpAnalyzer(m_analysisPath, connSqlDb);
                        DumpAnalyzer.Dock = DockStyle.Fill;
                        tcAnalysis.TabPages.Add(new TabPage("Memory Dumps")
                        {
                            ImageIndex = 1, Name = "Memory Dumps"
                        });
                        tcAnalysis.TabPages["Memory Dumps"].Controls.Add(DumpAnalyzer);
                    }
                }
                if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".evtx")) ||
                    File.Exists(m_analysisPath + "\\" + AnalysisTraceID + "_Application.evtx") ||
                    File.Exists(m_analysisPath + "\\" + AnalysisTraceID + "_System.evtx"))
                {
                    tcAnalysis.TabPages.Add(new TabPage("Event Logs")
                    {
                        ImageIndex = 2, Name = "Event Logs"
                    });
                    tcAnalysis.TabPages["Event Logs"].Controls.Add(GetStatusTextBox("Check back soon for automated analysis of event logs."));
                }
                if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".etl")) ||
                    (File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".cap")) ||
                    File.Exists(m_analysisPath + "\\" + AnalysisTraceID + ".etl") ||
                    File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.diag.log"))
                {
                    tcAnalysis.TabPages.Add(new TabPage("Network Trace")
                    {
                        ImageIndex = 3, Name = "Network Trace"
                    });
                    TextBox txtNetworkAnalysis     = GetStatusTextBox();
                    Button  btnAnalyzeNetworkTrace = new Button()
                    {
                        Text = "Analyze Trace", Name = "btnAnalyzeNetworkTrace", Left = tcAnalysis.Width / 2 - 54, Width = 108, Top = 80, Visible = false
                    };
                    tcAnalysis.TabPages["Network Trace"].Controls.Add(btnAnalyzeNetworkTrace);
                    btnAnalyzeNetworkTrace.Click += btnAnalyzeNetworkTrace_Click;
                    tcAnalysis.TabPages["Network Trace"].Controls.Add(txtNetworkAnalysis);

                    if (File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.log"))
                    {
                        txtNetworkAnalysis.Text = File.ReadAllText(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.log");
                        AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.log");
                        AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.diag.log");
                    }
                    else
                    {
                        btnAnalyzeNetworkTrace.Visible = true;
                    }
                }
                if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".blg")) || File.Exists(m_analysisPath + "\\" + AnalysisTraceID + ".blg"))
                {
                    tcAnalysis.TabPages.Add(new TabPage("Performance Logs")
                    {
                        ImageIndex = 4, Name = "Performance Logs"
                    });
                    tcAnalysis.TabPages["Performance Logs"].Controls.Add(GetStatusTextBox("Check back soon for automated analysis of performance logs."));
                }
                if (
                    (File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".trc")) ||
                    (File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".mdf")) ||
                    (
                        !File.Exists(m_analysisPath) &&
                        (Directory.GetFiles(m_analysisPath, AnalysisTraceID + "*.trc").Count() > 0 ||
                         File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".mdf"))
                    )
                    )
                {
                    SetupSQLTextbox();
                    LogFeatureUse("Profiler Analysis", "Initializing analysis tab");
                    splitProfilerAnalysis.Visible   = false;
                    ProfilerTraceStatusTextBox.Text = "";
                    tcAnalysis.TabPages.Add(HiddenTabPages.Where(t => t.Text == "Profiler Traces").First());
                    HiddenTabPages.Remove(HiddenTabPages.Where(t => t.Text == "Profiler Traces").First());
                    if (!Validate2016ManagementComponents())
                    {
                        ProfilerTraceStatusTextBox.Text = "SQL 2016 Management Studio components required.\r\nComplete install from https://go.microsoft.com/fwlink/?LinkID=840946 and then open Profiler Trace Analysis again.";
                        btnImportProfilerTrace.Visible  = false;
                    }
                    else
                    {
                        btnImportProfilerTrace.Visible = true;
                        string sqlForTraces = Properties.Settings.Default["SqlForProfilerTraceAnalysis"] as string;
                        if (m_analysisPath.EndsWith(".trc"))
                        {
                            mdfPath = m_analysisPath.Substring(0, m_analysisPath.LastIndexOf("\\") + 1) + "Analysis" + m_analysisPath.Substring(m_analysisPath.LastIndexOf("\\")).Replace(".trc", "").TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) + ".mdf";
                        }
                        else
                        {
                            mdfPath = m_analysisPath;
                        }
                        if (File.Exists(mdfPath) || File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".mdf"))
                        {
                            AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".mdf");
                            AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".ldf");
                            ProfilerTraceStatusTextBox.AppendText("Using trace data loaded into SQL .mdf at " + m_analysisPath + (m_analysisPath.EndsWith(".mdf") ? ".\r\n" : "\\Analysis\\.\r\n"));
                            new Thread(new ThreadStart(() => AttachProfilerTraceDB())).Start();
                            splitProfilerAnalysis.Visible  = true;
                            btnImportProfilerTrace.Visible = false;
                        }
                        else
                        {
                            ProfilerTraceStatusTextBox.Text = "Trace file is not yet imported to database table for analysis.  Import to perform analysis.";
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 private void frmSSASDiag_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (btnCapture.Image.Tag as string == "Stop" || btnCapture.Image.Tag as string == "Stop Lit" || ((string)btnCapture.Image.Tag as string) == ("Play Half Lit"))
         {
             if (!Environment.UserInteractive || MessageBox.Show("Continue collecting data as a service until SSASDiag runs again to stop manually " + (chkStopTime.Checked ? "or the automatic stop time is reached" : "") + "?\r\n\r\nIf you select No, SSASDiag will close after collection stops immediately.", "Data collection in progress", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
             {
                 btnCapture_Click(null, null);
                 bExitAfterStop = true;
                 e.Cancel       = true;
             }
         }
         else if (((string)btnCapture.Image.Tag as string) == ("Stop Half Lit"))
         {
             if (!Environment.UserInteractive || MessageBox.Show("Disconnect this SSASDiag client from the in-progress shutdown?\r\n\r\nShutdown will continue but may take time to complete.\r\nRerun SSASDiag to monitor shutdown.", "Diagnostic shutdown in progress", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
             {
                 e.Cancel = true;
             }
             else
             {
                 if (Application.OpenForms.Count > 1)
                 {
                     Application.OpenForms["PasswordPrompt"].Invoke(new System.Action(() => Application.OpenForms["PasswordPrompt"].Close()));
                 }
             }
         }
         if (bProfilerTraceDbAttached && chkDettachProfilerAnalysisDBWhenDone.Checked)
         {
             StatusFloater.lblStatus.Text = "Detaching attached profiler trace database...";
             StatusFloater.Left           = Left + Width / 2 - StatusFloater.Width / 2;
             StatusFloater.Top            = Top + Height / 2 - StatusFloater.Height / 2;
             StatusFloater.Show(this);
             Enabled = false;
             BackgroundWorker bgDetachProfilerDB = new BackgroundWorker();
             bgDetachProfilerDB.DoWork             += BgDetachProfilerDB_DoWork;;
             bgDetachProfilerDB.RunWorkerCompleted += BgDetachProfilerDB_RunWorkerCompleted;
             bgDetachProfilerDB.RunWorkerAsync();
             e.Cancel = true;
         }
         if (!e.Cancel)
         {
             if (tcAnalysis.TabPages.ContainsKey("Memory Dumps"))
             {
                 ucASDumpAnalyzer da = (tcAnalysis.TabPages["Memory Dumps"].Controls[0] as ucASDumpAnalyzer);
                 if (da.btnAnalyzeDumps.Text.StartsWith("Cancel"))
                 {
                     da.btnAnalyzeDumps.PerformClick();
                 }
                 while (da.btnAnalyzeDumps.Text.StartsWith("Cancel"))
                 {
                     Thread.Sleep(50);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogException(ex);
         // This should never happen but might if we are summarily killing midway through something.  Don't get hung up just close.
     }
     System.Diagnostics.Trace.WriteLine("SSASDiag form closed, Cancel set to: " + e.Cancel);
 }
Esempio n. 3
0
        void CompleteAnalysisTabsPopulationAfterZipExtraction()
        {
            string mdfPath = "";

            if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith("\\msmdsrv.ini")) || File.Exists(m_analysisPath + "\\msmdsrv.ini"))
            {
                tcAnalysis.TabPages.Add(new TabPage("Configuration")
                {
                    ImageIndex = 0, Name = "Configuration"
                });
                tcAnalysis.TabPages["Configuration"].Controls.Add(GetStatusTextBox(File.ReadAllText(m_analysisPath + "\\msmdsrv.ini")));
            }
            bool dirhasdumps = false;

            if (!File.Exists(m_analysisPath))
            {
                if (Directory.GetFiles(m_analysisPath, "*.mdmp", SearchOption.TopDirectoryOnly).Count() > 0)
                {
                    dirhasdumps = true;
                }
                else
                {
                    foreach (string dir in Directory.EnumerateDirectories(m_analysisPath))
                    {
                        if (!dir.Contains("\\$RECYCLE.BIN") &&
                            !dir.Contains("\\System Volume Information") &&
                            Directory.GetFiles(dir, "*.mdmp", SearchOption.AllDirectories).Count() > 0)
                        {
                            dirhasdumps = true;
                            break;
                        }
                    }
                }
            }
            if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".mdmp")) || dirhasdumps ||
                (Directory.Exists(m_analysisPath + "\\Analysis") && Directory.GetFiles(m_analysisPath + "\\Analysis", "SSASDiag_MemoryDump_Analysis_*.mdf", SearchOption.TopDirectoryOnly).Count() > 0))
            {
                if (ValidateProfilerTraceDBConnectionStatus())
                {
                    ucASDumpAnalyzer DumpAnalyzer = new ucASDumpAnalyzer(m_analysisPath, connSqlDb, StatusFloater);
                    DumpAnalyzer.Dock = DockStyle.Fill;
                    tcAnalysis.TabPages.Add(new TabPage("Memory Dumps")
                    {
                        ImageIndex = 1, Name = "Memory Dumps"
                    });
                    tcAnalysis.TabPages["Memory Dumps"].Controls.Add(DumpAnalyzer);
                }
            }
            if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".evtx")) ||
                File.Exists(m_analysisPath + "\\" + AnalysisTraceID + "_Application.evtx") ||
                File.Exists(m_analysisPath + "\\" + AnalysisTraceID + "_System.evtx"))
            {
                tcAnalysis.TabPages.Add(new TabPage("Event Logs")
                {
                    ImageIndex = 2, Name = "Event Logs"
                });
                RichTextBox eventlogstatus = GetStatusTextBox("Right-click to open captured logs in Event Viewer.  Check back soon for automated analysis of event logs.");
                eventlogstatus.MouseUp += Eventlogstatus_MouseClick;
                tcAnalysis.TabPages["Event Logs"].Controls.Add(eventlogstatus);
            }
            if ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".etl")) ||
                (File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".cap")) ||
                File.Exists(m_analysisPath + "\\" + AnalysisTraceID + ".etl") ||
                File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.diag.log"))
            {
                tcAnalysis.TabPages.Add(new TabPage("Network Trace")
                {
                    ImageIndex = 3, Name = "Network Trace"
                });
                RichTextBox txtNetworkAnalysis     = GetStatusTextBox();
                Button      btnAnalyzeNetworkTrace = new Button()
                {
                    Text = "Analyze Trace", Name = "btnAnalyzeNetworkTrace", Left = tcAnalysis.Width / 2 - 54, Width = 108, Top = 80, Visible = false
                };
                tcAnalysis.TabPages["Network Trace"].Controls.Add(btnAnalyzeNetworkTrace);
                btnAnalyzeNetworkTrace.Click += btnAnalyzeNetworkTrace_Click;
                tcAnalysis.TabPages["Network Trace"].Controls.Add(txtNetworkAnalysis);

                if (File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.log"))
                {
                    txtNetworkAnalysis.Text = File.ReadAllText(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.log");
                    AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.log");
                    AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + "_NetworkAnalysis.diag.log");
                }
                else
                {
                    btnAnalyzeNetworkTrace.Visible = true;
                }
            }

            bool dirhasblgs = false;

            if (!File.Exists(m_analysisPath))
            {
                if (Directory.GetFiles(m_analysisPath, "*.blg", SearchOption.TopDirectoryOnly).Count() > 0)
                {
                    dirhasblgs = true;
                }
                else
                {
                    foreach (string dir in Directory.EnumerateDirectories(m_analysisPath))
                    {
                        if (!dir.Contains("\\$RECYCLE.BIN") &&
                            !dir.Contains("\\System Volume Information") &&
                            Directory.GetFiles(dir, "*.blg", SearchOption.AllDirectories).Count() > 0)
                        {
                            dirhasblgs = true;
                            break;
                        }
                    }
                }
            }
            if (Args.ContainsKey("perfmonanalyzer") && ((File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".blg")) || dirhasblgs ||
                                                        (Directory.Exists(m_analysisPath + "\\Analysis") && Directory.GetFiles(m_analysisPath + "\\Analysis", "SSASDiag_PerfMon_Analysis_*.mdf", SearchOption.TopDirectoryOnly).Count() > 0)))
            {
                if (ValidateProfilerTraceDBConnectionStatus())
                {
                    tcAnalysis.TabPages.Add(new TabPage("Performance Logs")
                    {
                        ImageIndex = 4, Name = "Performance Logs"
                    });
                    ucASPerfMonAnalyzer PerfMonAnalyzer = new ucASPerfMonAnalyzer(m_analysisPath, connSqlDb, StatusFloater);
                    PerfMonAnalyzer.Dock = DockStyle.Fill;
                    tcAnalysis.TabPages["Performance Logs"].Controls.Add(PerfMonAnalyzer);
                }
            }

            if (
                (File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".trc")) ||
                (File.Exists(m_analysisPath) && m_analysisPath.EndsWith(".mdf")) ||
                (
                    !File.Exists(m_analysisPath) &&
                    (Directory.GetFiles(m_analysisPath, AnalysisTraceID + "*.trc").Count() > 0 ||
                     File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".mdf"))
                )
                )
            {
                SetupSQLTextbox();
                LogFeatureUse("Profiler Analysis", "Initializing analysis tab");
                splitProfilerAnalysis.Visible   = false;
                ProfilerTraceStatusTextBox.Text = "";
                tcAnalysis.TabPages.Add(HiddenTabPages.Where(t => t.Text == "Profiler Trace").First());
                HiddenTabPages.Remove(HiddenTabPages.Where(t => t.Text == "Profiler Trace").First());
                if (!Validate2017ManagementComponents())
                {
                    ProfilerTraceStatusTextBox.Text = "SQL 2017 Management Studio components required.\r\nComplete install from https://go.microsoft.com/fwlink/?LinkID=840946 and then open Profiler Trace Analysis again.";
                    btnImportProfilerTrace.Visible  = false;
                }
                else
                {
                    btnImportProfilerTrace.Visible = true;
                    string sqlForTraces = Registry.CurrentUser.CreateSubKey(@"Software\SSASDiag").GetValue("SqlForProfilerTraceAnalysis", "") as string;
                    if (m_analysisPath.EndsWith(".trc"))
                    {
                        mdfPath = m_analysisPath.Substring(0, m_analysisPath.LastIndexOf("\\") + 1) + "Analysis" + m_analysisPath.Substring(m_analysisPath.LastIndexOf("\\")).Replace(".trc", "").TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) + ".mdf";
                    }
                    else
                    {
                        mdfPath = m_analysisPath;
                    }
                    if (File.Exists(mdfPath) || File.Exists(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".mdf"))
                    {
                        AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".mdf");
                        AddFileFromFolderIfAnlyzingZip(m_analysisPath + "\\Analysis\\" + AnalysisTraceID + ".ldf");
                        ProfilerTraceStatusTextBox.AppendText("Using trace data loaded into SQL .mdf at " + m_analysisPath + (m_analysisPath.EndsWith(".mdf") ? ".\r\n" : "\\Analysis\\.\r\n"));
                        new Thread(new ThreadStart(() => AttachProfilerTraceDB())).Start();
                        splitProfilerAnalysis.Visible  = true;
                        btnImportProfilerTrace.Visible = false;
                    }
                    else
                    {
                        ProfilerTraceStatusTextBox.Text = "Trace file is not yet imported to database table for analysis.  Import to perform analysis.";
                    }
                }
            }
            // Prefer loading some tabs before others (Order of pref: Configuration (default if it exists anyway by alpha ordering as first tab), Network, Profiler, Memory Dump, then the others are all just placeholders so ignored.
            if (!tcAnalysis.TabPages.ContainsKey("Configuration"))
            {
                if (tcAnalysis.TabPages.ContainsKey("tbProfilerTraces"))
                {
                    tcAnalysis.SelectedTab = tcAnalysis.TabPages["tbProfilerTraces"];
                }
                else if (tcAnalysis.TabPages.ContainsKey("Network Trace"))
                {
                    tcAnalysis.SelectedTab = tcAnalysis.TabPages["Network Trace"];
                }
                else if (tcAnalysis.TabPages.ContainsKey("Memory Dumps"))
                {
                    tcAnalysis.SelectedTab = tcAnalysis.TabPages["Memory Dumps"];
                }
            }
            tcAnalysis.Visible = true;
        }