示例#1
0
        private bool PassesFilter(GenericEventRecord eventRecord)
        {
            if (eventRecord.TimeStampRelatveMSec < StartTimeRelativeMSec)
            {
                return(false);
            }
            if (EndTimeRelativeMSec < eventRecord.TimeStampRelatveMSec)
            {
                return(false);
            }

            if (!m_processFilter[eventRecord.ProcessName])
            {
                return(false);
            }

            if (!m_selectedAllEvents && !m_selectedEvents.ContainsKey(eventRecord.EventName))
            {
                return(false);
            }

            if (m_textFilter != null && !m_textFilter(eventRecord))
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        private void EventCallback(GenericEventRecord eventRecord)
        {
            if (!m_processFilter.ContainsKey(eventRecord.ProcessName))
            {
                bool isSelected            = true;
                var  processFilterRegexStr = ProcessFilterRegex;
                if (!string.IsNullOrWhiteSpace(processFilterRegexStr))
                {
                    isSelected = Regex.IsMatch(eventRecord.ProcessName, processFilterRegexStr);
                }
                m_processFilter[eventRecord.ProcessName] = isSelected;
            }

            string[] fieldNames;
            if (!m_eventFieldNames.TryGetValue(eventRecord.EventName, out fieldNames))
            {
                m_eventFieldNames[eventRecord.EventName] = eventRecord.FieldNames;
                if (OnEventNamesChanged != null)
                {
                    OnEventNamesChanged();
                }
            }

            m_allEventRecords.Add(eventRecord);

            if (PassesFilter(eventRecord))
            {
                OnEvent(eventRecord);
            }
        }
示例#3
0
 public void AddRecord(GenericEventRecord eventRecord)
 {
     Records.Add(eventRecord);
     if (OnNewRecord != null)
     {
         OnNewRecord(eventRecord);
     }
 }
示例#4
0
        public static void X()
        {
            // Create a new session, turn on some events, and get the stream of events
            var session = new TraceEventSession("MySession");

            session.EnableProvider(TraceEventProviders.GetEventSourceGuidFromName("MyEventSource"));
            var eventStream = session.Source;

            // Create an in memory GENERIC list of parsed (basically string) records that can hold the results
            GenericEventSource eventSource = new GenericEventSource();

            // Hook up the ETW eventStream to the generic in memory event source.
            var dynamicParser = new DynamicTraceEventParser(eventStream);
            Action <TraceEvent> sendToEventStore = delegate(TraceEvent data)
            {
                var processName = data.ProcessName;
                if (!processName.StartsWith("("))
                {
                    processName += " (" + data.ProcessID + ")";
                }

                var fieldNames = data.PayloadNames;
                var fields     = new string[fieldNames.Length];
                for (int i = 0; i < fields.Length; i++)
                {
                    fields[i] = data.PayloadString(i);
                }

                var genericRecord = new GenericEventRecord(data.EventName, data.ProcessName, data.TimeStampRelativeMSec, fieldNames, fields);
                eventSource.Records.AddRecord(genericRecord);
            };

            dynamicParser.All += sendToEventStore;
            var registeredParser = new RegisteredTraceEventParser(eventStream);

            registeredParser.All        += sendToEventStore;
            eventStream.UnhandledEvents += sendToEventStore;

            // Start processing ETW events and filling the in-memory list (which the GUI is observing).
            var thread = new Thread(delegate()
            {
                session.Source.Process();
            });

            thread.Start();

            var window = new EventWindow(GuiApp.MainWindow, eventSource);

            window.Show();
        }