public static List <RuleCounter> CountersFromPath(string Path, bool ShowInChart = true, bool HighlightInChart = false, bool Include_TotalSeriesInWildcard = true, Color?CounterColor = null) { ucASPerfMonAnalyzer HostControl = ((Program.MainForm.tcCollectionAnalysisTabs.TabPages[1].Controls["tcAnalysis"] as TabControl).TabPages["Performance Logs"].Controls[0] as ucASPerfMonAnalyzer); List <RuleCounter> counters = new List <RuleCounter>(); string[] parts = Path.Split('\\'); if (parts.Length > 1) { string counter = parts[0] + "\\" + parts[1]; if (parts.Length > 2) { TreeNode node = HostControl.tvCounters.FindNodeByPath(counter); if (node == null) { parts = ucASPerfMonAnalyzer.FullPathAlternateHierarchy(Path).Split('\\'); counter = parts[0] + "\\" + parts[1]; node = HostControl.tvCounters.FindNodeByPath(counter); } if (node != null) { if (parts[2].Contains("*")) { foreach (TreeNode child in node.Nodes) { if ((parts[2].StartsWith("-") && child.Text != "_Total") || !parts[2].StartsWith("-")) { if (parts.Length > 3) { if (parts[3].Contains("*")) { foreach (TreeNode grandchild in child.Nodes) { if (Include_TotalSeriesInWildcard || parts[3] != "_Total") { counters.Add(new RuleCounter(counter + "\\" + parts[3] + "\\" + grandchild.Name, Path, ShowInChart, HighlightInChart, Include_TotalSeriesInWildcard, CounterColor)); } } } else if (Include_TotalSeriesInWildcard || parts[3] != "_Total") { counters.Add(new RuleCounter(counter + "\\" + parts[3], Path, ShowInChart, HighlightInChart, Include_TotalSeriesInWildcard, CounterColor)); } } if (Include_TotalSeriesInWildcard || child.Name != "_Total") { counters.Add(new RuleCounter(counter + "\\" + child.Name, Path, ShowInChart, HighlightInChart, Include_TotalSeriesInWildcard, CounterColor)); } } } } else if (Include_TotalSeriesInWildcard || parts[2] != "_Total") { counters.Add(new RuleCounter(counter + "\\" + parts[2], Path, ShowInChart, HighlightInChart, Include_TotalSeriesInWildcard, CounterColor)); } } } else if (Include_TotalSeriesInWildcard || Path != "_Total") { counters.Add(new RuleCounter(counter, Path, ShowInChart, HighlightInChart, Include_TotalSeriesInWildcard, CounterColor)); } } return(counters); }
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; }