public XMgr(string XEventText) { OriginalXeventText = XEventText; TextReader reader = new StringReader(XEventText); XPathDocument doc = new XPathDocument(reader); XPathNavigator rootnav = doc.CreateNavigator(); XPathNodeIterator iterCat = rootnav.Select("DiagMgr/events/category"); while (iterCat.MoveNext()) { string name = iterCat.Current.GetAttribute("name", "").ToString(); DiagCategory cat = new DiagCategory("category", name); XPathNavigator eventNav = iterCat.Current.CreateNavigator(); XPathNodeIterator iterEvent = eventNav.Select("event"); while (iterEvent.MoveNext()) { /*Xevent evt = new Xevent(); * evt.Name = iterEvent.Current.GetAttribute("name", ""); * * evt.Package = iterEvent.Current.GetAttribute("package", ""); * evt.General = Convert.ToBoolean(iterEvent.Current.GetAttribute("general", "")); * evt.Detailed = Convert.ToBoolean(iterEvent.Current.GetAttribute("detail", "")); * evt.Replay = Convert.ToBoolean(iterEvent.Current.GetAttribute("replay", "")); */ cat.XEventList_DONOTUSE.Add(new Xevent(iterEvent.Current.OuterXml)); //Xevent xevt2 = ObjectCopier.Clone<Xevent>(new Xevent(iterEvent.Current.OuterXml)); //MessageBox.Show(xevt2.Name); } CategoryList.Add(cat); } // PrintInfo(); }
public TraceEvent(DiagCategory cat, string xmltag, string name, string id) { this.XmlTagName = xmltag; Name = name; this.Id = id; this.Category = cat; }
static List <DiagCategory> GetCustomDiagnostics() { List <DiagCategory> customList = new List <DiagCategory>(); //string CustomDiag = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().FullName) + @"\CustomDiagnostics"; string CustomDiag = Globals.ExePath + @"\CustomDiagnostics"; DirectoryInfo dInfo = new DirectoryInfo(CustomDiag); DirectoryInfo[] subdirs = dInfo.GetDirectories(); foreach (DirectoryInfo dirinfo in subdirs) { // Logger.LogInfo(dirinfo.Name); //DiagCategory cat = new DiagCategory("CustomGroup", dirinfo.Name); DiagCategory cat = GetCustomGroup(dirinfo.Name, dirinfo.FullName + @"\CustomDiag.xml"); //donit' want ot deal with empty folder if (null != cat && cat.DiagEventList.Count > 0) { customList.Add(cat); } } return(customList); }
public CustomTask(DiagCategory cat, string xmltag, string taskename, string type, string point, string wait, string cmd, Int32 pollinginterval) : base(cat, xmltag, taskename) { this.Type = type; this.Point = point; this.Cmd = cmd; this.Wait = wait; this.PollingInterval = pollinginterval; }
void SetCustomDiag(XmlNode node) { // if SQL Xevent needs to be captured if (m_Setting[Res.CollectXEvent] == "true") { DiagCategory XEventGroup = DiagFactory.GetCustomGroup(null, @"Templates\CustomDiagnostics_Xevent.xml"); //need to manuall handle taskname "Add File Target" for file size and file count DiagItem taskItem = XEventGroup.DiagEventList.Find(x => x.Name == "Add File Target"); // for CustomTask Name is the same as TaskName CustomTask task = taskItem as CustomTask; task.Cmd = task.Cmd.Replace("1024x", m_Setting[Res.XEventMaxFileSize]).Replace("5x", m_Setting[Res.XEventFileCount]); //manually check events for special handling XEventGroup.CheckEvents(true); m_Setting.CustomDiagCategoryList.Add(XEventGroup); } //speical handling Analysis Service (A_S) string customDiagxml = m_Setting.CustomDiagCategoryList.GetCategoryXml(); if (m_Setting[Res.Feature] == "AS") { string ServerInstance = string.Empty; string instance = string.Empty; string InstanceName = m_Setting[Res.InstanceName]; string MachineName = m_Setting[Res.MachineName]; string ASTraceFileName = string.Empty; if (!(InstanceName.ToUpper() == "MSSQLSERVER")) { ServerInstance = MachineName + @"\" + InstanceName; ASTraceFileName = MachineName + "_" + InstanceName; } else { ServerInstance = MachineName; ASTraceFileName = MachineName; } customDiagxml = customDiagxml.Replace("ASSERVERINSTANCE", ServerInstance); customDiagxml = customDiagxml.Replace("ASTraceFileName", ASTraceFileName); } node.InnerXml = customDiagxml; //CustomDiagnosticsNode.InnerXml = DiagTreeMgr.GetXmlText(tv_CustomDiag); }
private void MakeManualBatchFiles() { if (m_Instance == "*") { return; } StreamWriter ManualStart = File.CreateText(m_tempDirectory + @"\ManualStart.txt"); StreamWriter ManualStop = File.CreateText(m_tempDirectory + @"\ManualStop.txt"); ManualStart.WriteLine("REM PURPOSE: This file is for cases where execution of PSSDIAG does not work for some reason. It allows you to manually collect some base information."); ManualStart.WriteLine("REM This includes Perfmon, Perfstat scripts and some other configuration information for the instance (sp_configure, sys.databses, etc)"); ManualStart.WriteLine("REM INSTRUCTIONS:"); ManualStart.WriteLine("REM 1. Rename the file to ManualStart.cmd (change the extension)"); ManualStart.WriteLine("REM 2. Rename the ManualStop.txt to ManualStop.cmd (change the extension)"); ManualStart.WriteLine("REM 3. Execute from a Command Prompt by running ManualStart.cmd"); ManualStart.WriteLine("REM 4. When ready to stop, execute ManualStop.cmd from another Command Prompt window"); ManualStart.WriteLine("REM 5. Find the collected data in the \\Output folder"); ManualStart.WriteLine(""); ManualStop.WriteLine("REM PURPOSE: This file is for cases where execution of PSSDIAG does not work for some reason. This file stops manual collection of base information."); ManualStop.WriteLine("REM INSTRUCTIONS:"); ManualStop.WriteLine("REM 1. Rename the file to ManualStop.cmd (change the extension)"); ManualStop.WriteLine("REM 2. When ready to stop collection, execute ManualStop.cmd from a new Command Prompt window"); ManualStop.WriteLine("REM 3. Find the collected data in the \\Output folder"); ManualStop.WriteLine(""); ManualStart.WriteLine("setlocal ENABLEEXTENSIONS"); ManualStart.WriteLine("set LaunchDir=%~dp0"); ManualStart.WriteLine("set servername=%computername%"); ManualStop.WriteLine("setlocal ENABLEEXTENSIONS"); ManualStop.WriteLine("set LaunchDir=%~dp0"); ManualStop.WriteLine("set servername=%computername%"); ManualStart.WriteLine("md \"%LaunchDir%\\output\\internal\""); //need to test on a cluster and see if . does anything for VNN //TODO: NEED TO EXCLUDE FROM HASH CALCULATION ManualStart.WriteLine(string.Format(SqlCmdTemplate, m_Server_Instance, m_output_instance_prefix + "_msdiagprocs.out", "-i\"" + m_input_prefix + "msdiagprocs.sql" + "\"")); //make manual profile collector if (m_userchoice[Res.CollectProfiler] == "true") { string strTraceEvents = ""; foreach (DiagItem diagItem in m_userchoice.ProfilerCategoryList.GetCheckedDiagItemList()) { TraceEvent evt = diagItem as TraceEvent; if (!string.IsNullOrEmpty(strTraceEvents)) { strTraceEvents += ","; } strTraceEvents += evt.Id.ToString(); } string MaxFileSize = m_userchoice[Res.ProfilerMaxFileSize]; string FileCount = m_userchoice[Res.ProfilerFileCount]; string strTraceStartQuery = string.Format(StartTraceTemplate, strTraceEvents, m_AppName, m_output_instance_prefix + "_sp_trace", MaxFileSize, FileCount); string strTraceStopQuery = string.Format(StopTraceTemplate, m_AppName); ManualStart.WriteLine("rem starting profiler trace"); string cmd = string.Format(SqlCmdTemplate, m_Server_Instance, m_internal_output_instance_prefix + "_sp_trace_start.out", "-Q\"" + strTraceStartQuery + "\""); ManualStart.WriteLine(cmd); ManualStop.WriteLine("rem stoping profile trace"); cmd = string.Format(SqlCmdTemplate, m_Server_Instance, m_internal_output_instance_prefix + "_sp_trace_stop.out", "-Q\"" + strTraceStopQuery + "\""); ManualStop.WriteLine(cmd); } //make a copy List <DiagCategory> checkedCategories = new List <DiagCategory>(); foreach (DiagCategory cat in m_userchoice.CustomDiagCategoryList.GetCheckedCategoryList()) { checkedCategories.Add(cat); } // if SQL Xevent needs to be captured if (m_userchoice[Res.CollectXEvent] == "true") { DiagCategory XEventGroup = DiagFactory.GetCustomGroup(null, @"Templates\CustomDiagnostics_Xevent.xml"); //need to manuall handle taskname "Add File Target" for file size and file count DiagItem taskItem = XEventGroup.DiagEventList.Find(x => x.Name == "Add File Target"); // for CustomTask Name is the same as TaskName CustomTask task = taskItem as CustomTask; task.Cmd = task.Cmd.Replace("1024x", m_userchoice[Res.XEventMaxFileSize]).Replace("5x", m_userchoice[Res.XEventFileCount]); XEventGroup.Name = "XEvent"; //manually check events for special handling XEventGroup.CheckEvents(true); checkedCategories.Add(XEventGroup); } foreach (DiagCategory cat in checkedCategories) { ManualStart.WriteLine("rem group: " + cat.Name); foreach (DiagItem item in cat.GetCheckedEventList()) { CustomTask task = item as CustomTask; //currently do not handle anything other than TSQL script if (null == task) { continue; } if (task.Type.ToUpper() == "TSQL_SCRIPT") { string cmd = "Start "; if (task.GroupName == "XEvent") { cmd = ""; //make sure xevent is last group } cmd = cmd + string.Format(SqlCmdTemplate, m_Server_Instance, m_output_instance_prefix + "_" + task.Cmd + ".out", "-i\"" + m_input_prefix + task.Cmd + "\""); if (task.Point.ToUpper() == "STARTUP") { ManualStart.WriteLine(cmd); } else { ManualStop.WriteLine(cmd); } } /* * //various issues exists for batch files. * else if (task.Type.ToUpper() =="UTILITY") * { * // working example * //start collecterrorlog.cmd jackli2014\sql16a 1 ^> "c:\temp\pssd\out5.txt" 2>&1 ^&^&exit * // * string cmd = "start " + ReplaceToken(task.Name, task.Cmd); * cmd = cmd.Replace(">", "^>").Replace("2^>&1", "2>&1"); * cmd = cmd + " &exit"; * if (task.Point.ToUpper() == "STARTUP") * { * ManualStart.WriteLine(cmd); * } * else * { * ManualStop.WriteLine(cmd); * } * * * }*/ else if (task.Type.ToUpper() == "TSQL_COMMAND") { string cmd = "Start "; if (task.GroupName == "XEvent") { cmd = ""; // can do this because it's the last event } cmd = cmd + string.Format(SqlCmdTemplate, m_Server_Instance, m_output_instance_prefix + "_" + task.TaskName + ".out", "-Q\"" + task.Cmd + "\""); cmd = cmd.Replace(@"%output_path%%server%_%instance%", m_output_instance_prefix); if (task.Point.ToUpper() == "STARTUP") { ManualStart.WriteLine(cmd); } else { ManualStop.WriteLine(cmd); } } else { Logger.LogInfo("Manual run hasnot been implemented for task type " + task.Type); } //task.Cmd } } ManualStart.WriteLine("rem starting Perfmon"); ManualStart.WriteLine(string.Format("logman stop {0}", LogManName)); ManualStart.WriteLine(string.Format("logman delete {0}", LogManName)); ManualStart.WriteLine(string.Format("logman CREATE COUNTER -n {0} -s {1} -cf {2} -f bin -si 00:00:15 -o {3} -ow ", LogManName, m_userchoice[Res.MachineName], "LogmanConfig.txt", @"output\pssdiag.blg")); ManualStart.WriteLine(string.Format("logman start {0} ", LogManName)); ManualStop.WriteLine(string.Format("logman stop {0}", LogManName)); ManualStop.WriteLine(string.Format(SqlCmdTemplate, m_Server_Instance, m_output_instance_prefix + "_kill.out", "-Q tempdb.dbo.sp_killpssdiagSessions")); //logman CREATE COUNTER -n SQLServer -s AlwaysOnN1 -cf C:\dsefiles\dse_counters.txt -f bin -si 00:00:15 -o C:\dsefiles\SQL.blg ManualStart.Flush(); ManualStart.Close(); ManualStop.Flush(); ManualStop.Close(); }
public static void PopulateTree <T> (TreeView tree, List <T> treelist, UserSetting setting) { TreeNodeCollection tc = tree.Nodes; tree.AfterCheck -= OnCheck; tree.AfterCheck += OnCheck; if (tc.Count > 0) { tree.Nodes.Clear(); } //sort the list for tree display treelist.Sort(); foreach (T obj in treelist) { DiagCategory cat = obj as DiagCategory; TreeNode catNode = new TreeNode(); catNode.Name = cat.TreeNodeName; catNode.Text = cat.TreeNodeText; catNode.Tag = cat; if (cat.DiagEventList.Count <= 0) { continue; } cat.DiagEventList.Sort(); bool anyChildChecked = false; foreach (DiagItem evt in cat.DiagEventList) { TreeNode evtNode = new TreeNode(); evtNode.Name = evt.TreeNodeText; evtNode.Text = evt.TreeNodeText; bool IsVersionEnabled = false; bool IsFeatureEanbled = false; bool IsAnyTemplateEnabled = false; if (null != evt.EnabledVersions.Find(x => x.Name == setting["Version"] && x.Enabled == true)) { IsVersionEnabled = true; } if (null != evt.EnabledFeatures.Find(x => x.Name == setting["Feature"] && x.Enabled == true)) { IsFeatureEanbled = true; } //foreach (string temp in setting.GetDefaultChoiceByFeatureVersion (setting.Feature, setting.Version).ScenarioList) foreach (string temp in setting.UserChosenScenarioList) { if (null != evt.EnabledTemplate.Find(x => x.Name == temp)) { IsAnyTemplateEnabled = true; break; } } if (IsVersionEnabled == true && IsFeatureEanbled == true && IsAnyTemplateEnabled == true) { anyChildChecked = true; evtNode.Checked = true; } evtNode.Tag = evt; if (IsVersionEnabled && IsFeatureEanbled) { catNode.Nodes.Add(evtNode); (evtNode.Tag as DiagItem).IsChecked = evtNode.Checked; } } //don't add if the feature or version doesn't event support any of the events in this event category if (anyChildChecked == true) { catNode.Checked = anyChildChecked; } //only add the node if it's for this feature and version //regardless of template SetCategoryColor(catNode); if (catNode.Nodes.Count > 0) { (catNode.Tag as DiagItem).IsChecked = catNode.Checked; tree.Nodes.Add(catNode); } } tree.Refresh(); }
public DiagItem(DiagCategory cat, string xmltag, string name) { this.Category = cat; this.XmlTagName = xmltag; this.Name = name; }
public static DiagCategory GetCustomGroup(string CustomGroupName, string filename) { //AS currently doesn't support public release if (!string.IsNullOrEmpty(CustomGroupName) && (DiagRuntime.IsPublicVersion == true && CustomGroupName.ToUpper().Contains("ANALYSIS"))) { return(null); } DiagCategory cat; if (CustomGroupName != null) { cat = new DiagCategory("CustomGroup", CustomGroupName); } else { cat = new DiagCategory("CustomGroup", "PlaceHolder"); //will change later } //we need to fake a custom xml file for TSQL Scripts to make it easier to develop XPathDocument doc; string CustomGroupDir = Path.GetDirectoryName(filename); string[] sqlfiles = Directory.GetFiles(CustomGroupDir, "*.sql"); if (File.Exists(filename)) { doc = new XPathDocument(filename); } else if (sqlfiles.Length > 0) { StringBuilder sb = new StringBuilder(); sb.Append("<?xml version=\"1.0\" standalone=\"yes\"?>\n\r"); sb.Append("<CustomTasks>\n\r"); foreach (string file in sqlfiles) { string fileNameOnly = Path.GetFileName(file); string format = "<CustomTask enabled = \"true\" groupname = \"{0}\" taskname = \"{1}\" type = \"TSQL_Script\" point = \"Startup\" wait = \"No\" cmd = \"{2}\" pollinginterval = \"0\" />"; sb.AppendFormat(format, cat.Name, fileNameOnly, fileNameOnly); } sb.Append("</CustomTasks>"); StringReader stream = new StringReader(sb.ToString()); doc = new XPathDocument(stream); } else { throw new Exception("Invalid Custom Diagnostics group: '" + ((CustomGroupName == null) ? "NULL" : CustomGroupName) + "'"); } XPathNavigator rootnav = doc.CreateNavigator(); XPathNodeIterator iter = rootnav.Select("CustomTasks/CustomTask "); while (iter.MoveNext()) { string groupname = iter.Current.GetAttribute("groupname", ""); //reading it from the file if (CustomGroupName == null) { cat.Name = groupname; } string taskname = iter.Current.GetAttribute("taskname", ""); string type = iter.Current.GetAttribute("type", ""); string point = iter.Current.GetAttribute("point", ""); string wait = iter.Current.GetAttribute("wait", ""); string cmd = iter.Current.GetAttribute("cmd", ""); string strpollinginterval = iter.Current.GetAttribute("pollinginterval", ""); Int32 pollinginterval = 0; if (!string.IsNullOrEmpty(strpollinginterval)) { pollinginterval = Convert.ToInt32(iter.Current.GetAttribute("pollinginterval", "")); } /* * if (groupname != cat.Name) * { * throw new ArgumentException(string.Format("The custom diagnotics group name supplied from file directory doesn't match the xml definition. file directory is {0} and the xml group name is {1}", cat.Name, groupname)); * }*/ CustomTask task = new CustomTask(cat, "CustomTask", taskname, type, point, wait, cmd, pollinginterval); cat.DiagEventList.Add(task); //merge file system and config xml files XPathDocument doc2 = new XPathDocument(@"Templates\CustomDiagnostics_Template.xml"); XPathNavigator rootnav2 = doc2.CreateNavigator(); XPathNodeIterator iter2 = rootnav2.Select(string.Format("CustomDiagnostics/CustomGroup[@name=\"{0}\"]/Scenarios/Scenario", cat.Name)); task.EnabledTemplate = GetLocalScenarioList(iter2); XPathNodeIterator iterVersion = rootnav2.Select(string.Format("CustomDiagnostics/CustomGroup[@name=\"{0}\"]/Versions/Version", cat.Name)); task.EnabledVersions = GetLocalVersionList(iterVersion); // GlobalVersionList; XPathNodeIterator iterFeature = rootnav2.Select(string.Format("CustomDiagnostics/CustomGroup[@name=\"{0}\"]/Features/Feature", cat.Name)); task.EnabledFeatures = GetLocalFeatureList(iterFeature); // GlobalFeatureList; } return(cat); }
/// <summary> /// /// </summary> /// <param name="XmlFile"> XML template file</param> /// <param name="CatClause">select clause for Category of the Event such as PerfmonObject, EventType for trace, Category for XEvent</param> /// <param name="EventClause">select clause for the event. eg. PerfmonCounter, Event etc</param> /// <param name="evtType">Enum</param> /// <returns>List of Categories</returns> static List <DiagCategory> GetEventCategoryList(string XmlFile, string CatClause, string EventClause, EventType evtType) { List <DiagCategory> catList = new List <DiagCategory>(); XPathDocument traceDoc = new XPathDocument(XmlFile); //new XPathDocument("TraceEvents.xml"); XPathNavigator rootnav = traceDoc.CreateNavigator(); XPathNodeIterator iter = rootnav.Select(CatClause); //rootnav.Select("TraceEvents/EventType"); while (iter.MoveNext()) { string catname = iter.Current.GetAttribute("name", ""); DiagCategory cat = new DiagCategory(iter.Current.Name, catname); catList.Add(cat); PopulateTemplateFeatureVersion(iter, cat); XPathNodeIterator iterEvents = iter.Current.Select(EventClause); // iter.Current.Select("Event"); while (iterEvents.MoveNext()) { string evtname = iterEvents.Current.GetAttribute("name", ""); DiagItem evt = null; //set to NULL because it will create child event for each type if (evtType == EventType.TraceEvent) { string trcid = iterEvents.Current.GetAttribute("id", ""); TraceEvent trcevt = new TraceEvent(cat, iterEvents.Current.Name, evtname, trcid); evt = trcevt; } else if (evtType == EventType.Perfmon) { evt = new DiagItem(cat, iterEvents.Current.Name, evtname); } else if (evtType == EventType.XEvent) { string evtpackage = iterEvents.Current.GetAttribute("package", ""); evt = new Xevent(cat, iterEvents.Current.Name, evtname, evtpackage); //read field elements from eventfields section XPathNodeIterator iterEventFields = iterEvents.Current.Select("eventfields/field"); while (iterEventFields.MoveNext()) { string name = iterEventFields.Current.GetAttribute("name", ""); bool autoinclude = Convert.ToBoolean(iterEventFields.Current.GetAttribute("AutoInclude", "")); bool isnum = Convert.ToBoolean(iterEventFields.Current.GetAttribute("IsNum", "")); EventField evtField = new EventField(name, autoinclude, isnum); (evt as Xevent).EventFieldList.Add(evtField); } //read action elements from eventactions section XPathNodeIterator iterEventActions = iterEvents.Current.Select("eventactions/action"); while (iterEventActions.MoveNext()) { string package = iterEventActions.Current.GetAttribute("package", ""); string name = iterEventActions.Current.GetAttribute("name", ""); EventAction evtAction = new EventAction(package, name); (evt as Xevent).EventActionList.Add(evtAction); } } else { throw new ArgumentException("GetEventCategoryList doesn't know how to handle this type of event yet"); } PopulateTemplateFeatureVersion(iterEvents, evt); cat.DiagEventList.Add(evt); } } return(catList); }
public Xevent(DiagCategory cat, string xmltag, string name, string package) : base(cat, xmltag, name) { this.Package = package; }