示例#1
0
        //ADD EVENT sqlserver.sql_batch_completed(SET collect_batch_text=(1)     ACTION(package0.collect_current_thread_id,package0.event_sequence,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.client_pid,sqlserver.database_id,sqlserver.database_name,sqlserver.is_system,sqlserver.nt_username,sqlserver.query_hash,sqlserver.request_id,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.session_server_principal_name,sqlserver.sql_text,sqlserver.transaction_id,sqlserver.username)     WHERE ([cpu_time]>(99)))
        public string AddEventActionText()
        {
            string setPrivateFields = string.Empty;
            string setGlobalActions = string.Empty;
            string setLocalActions  = string.Empty;
            string setWhereClause   = string.Empty;

            //if it's auto included, don't set
            if (EventFieldList != null && EventFieldList.Count() > 0)
            {
                int    counter = 0;
                string prefix  = "";
                setPrivateFields = "SET ";
                foreach (EventField evtfield in EventFieldList)
                {
                    if (evtfield.AutoInclude == false)
                    {
                        if (counter > 0)
                        {
                            prefix = " , ";
                        }

                        setPrivateFields += prefix + string.Format("{0}=(1)  ", evtfield.Name);
                        counter++;
                    }
                }
            }
            //if event requests specific actions capture them (we will not append to global actions since you can get into situations where you get too many actions error)
            if (this.EventActionList.Count() > 0)
            {
                setLocalActions = " ACTION (";
                for (int a = 0; a < this.EventActionList.Count(); a++)
                {
                    setLocalActions += this.EventActionList[a].FullName;
                    if (a != this.EventActionList.Count() - 1)
                    {
                        setLocalActions += ", ";
                    }
                    else
                    {
                        setLocalActions += ") ";
                    }
                }
                setGlobalActions = String.Copy(setLocalActions);
            }
            //otherwise go with global sction list (we will not append to event specific actions since you can get into situations where you get too many actions error)
            else if (XMgr.GlobalActionList != null && XMgr.GlobalActionList.Count() > 0)
            {
                setGlobalActions = " ACTION (";
                for (int i = 0; i < XMgr.GlobalActionList.Count(); i++)
                {
                    setGlobalActions += XMgr.GlobalActionList[i].FullName;
                    if (i != XMgr.GlobalActionList.Count() - 1)
                    {
                        setGlobalActions += ", ";
                    }
                    else
                    {
                        setGlobalActions += ") ";
                    }
                }
            }

            EventFilterCollection MyUserFilters = new EventFilterCollection();

            foreach (EventFilter evtFilter in XMgr.UserFilterList)
            {
                EventAction act   = XMgr.GlobalActionList.FindByNameIgnoreCase(evtFilter.Name);
                EventField  field = this.EventFieldList.Find(x => x.Name == evtFilter.Name);
                if (act != null || field != null)
                {
                    MyUserFilters.Add(evtFilter);
                }
            }
            //remove logical operator from last one
            if (MyUserFilters.Count > 0)
            {
                EventFilter evtFilter = MyUserFilters.Last <EventFilter>();
                evtFilter.LogicalOperator = string.Empty;
            }

            if (MyUserFilters != null && MyUserFilters.Count() > 0)
            {
                setWhereClause += " WHERE ( ";
                for (int i = 0; i < MyUserFilters.Count(); i++)
                {
                    EventFilter filt = MyUserFilters[i];
                    setWhereClause += filt.WhereClause + " ";
                }
                setWhereClause += ") ";
            }
            return(string.Format(AddEventTextTemplate, this.FullName, setPrivateFields, setGlobalActions, setWhereClause));
        }
示例#2
0
        /// <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);
        }
示例#3
0
        //ADD EVENT sqlserver.sql_batch_completed(SET collect_batch_text=(1)     ACTION(package0.collect_current_thread_id,package0.event_sequence,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.client_pid,sqlserver.database_id,sqlserver.database_name,sqlserver.is_system,sqlserver.nt_username,sqlserver.query_hash,sqlserver.request_id,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.session_server_principal_name,sqlserver.sql_text,sqlserver.transaction_id,sqlserver.username)     WHERE ([cpu_time]>(99)))

        public string AddEventActionText()
        {
            string setPrivateFields = string.Empty;
            string setGlobalActions = string.Empty;
            string setWhereClause   = string.Empty;


            //if it's auto included, don't set
            if (EventFieldList != null && EventFieldList.Count() > 0)
            {
                int    counter = 0;
                string prefix  = "";
                setPrivateFields = "SET ";
                foreach (EventField evtfield in EventFieldList)
                {
                    if (evtfield.AutoInclude == false)
                    {
                        if (counter > 0)
                        {
                            prefix = " , ";
                        }

                        setPrivateFields += prefix + string.Format("{0}=(1)  ", evtfield.Name);
                        counter++;
                    }
                }
            }
            if (XMgr.GlobalActionList != null && XMgr.GlobalActionList.Count() > 0)
            {
                setGlobalActions = " ACTION (";
                for (int i = 0; i < XMgr.GlobalActionList.Count(); i++)
                {
                    setGlobalActions += XMgr.GlobalActionList[i].FullName;
                    if (i != XMgr.GlobalActionList.Count() - 1)
                    {
                        setGlobalActions += ", ";
                    }
                    else
                    {
                        setGlobalActions += ") ";
                    }
                }
            }


            EventFilterCollection MyUserFilters = new EventFilterCollection();

            foreach (EventFilter evtFilter in XMgr.UserFilterList)
            {
                EventAction act   = XMgr.GlobalActionList.FindByNameIgnoreCase(evtFilter.Name);
                EventField  field = this.EventFieldList.Find(x => x.Name == evtFilter.Name);

                if (act != null || field != null)
                {
                    MyUserFilters.Add(evtFilter);
                }
            }



            //remove logical operator from laste one

            if (MyUserFilters.Count > 0)
            {
                EventFilter evtFilter = MyUserFilters.Last <EventFilter>();
                evtFilter.LogicalOperator = string.Empty;
            }

            if (MyUserFilters != null && MyUserFilters.Count() > 0)
            {
                setWhereClause += " WHERE ( ";
                for (int i = 0; i < MyUserFilters.Count(); i++)
                {
                    EventFilter filt = MyUserFilters[i];

                    setWhereClause += filt.WhereClause + " ";
                }

                setWhereClause += ") ";
            }


            return(string.Format(AddEventTextTemplate, this.FullName, setPrivateFields, setGlobalActions, setWhereClause));
        }