コード例 #1
0
ファイル: XMgr.cs プロジェクト: microsoft/DiagManager
        public static String GetSQLScript(List <DiagItem> evtList)
        {
            StringBuilder sbSQL   = new StringBuilder();
            XEventRuntime runtime = new XEventRuntime();

            sbSQL.AppendFormat(string.Format("-- {0}\n", runtime.DropCommand));

            sbSQL.AppendFormat("{0}\n ", "print 'Creating Xevent Session'");
            sbSQL.AppendFormat("{0}\n", runtime.DropCommand);

            sbSQL.Append("\nGO\n");
            sbSQL.AppendFormat("{0}\n ", runtime.CreateCommandPrefix);

            for (int i = 0; i < evtList.Count; i++)
            {
                //sbSQL.Append("ADD EVENT " + evtList[i].ToString());

                Xevent xevt = evtList[i] as Xevent;
                sbSQL.Append(xevt.AddEventActionText());
                if (i != (evtList.Count - 1))
                {
                    sbSQL.Append(",");
                }
                sbSQL.Append(Environment.NewLine);
            }

            // sbSQL.AppendFormat(@" ADD TARGET package0.event_file(SET filename=N'c:\temp\{0}_XEvent.xel') {1}", XMgr.GlobalEventTemplateList.GetNameForXEventFileTarget(),  Environment.NewLine);
            sbSQL.Append(@"WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=10 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)" + Environment.NewLine);

            sbSQL.AppendFormat("--{0}\n", runtime.AlterCommandAddFileTarget);

            sbSQL.AppendFormat("--{0}\n", runtime.StartCommand);
            sbSQL.AppendFormat("--{0}\n", runtime.StopCommand);

            return(sbSQL.ToString());
        }
コード例 #2
0
ファイル: DiagFactory.cs プロジェクト: microsoft/DiagManager
        /// <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);
        }