예제 #1
0
        private void ProcessEvent(TraceEvent e)
        {
            int sizeIndex = e.PayloadIndex("size");

            if (sizeIndex >= 0)
            {
                try
                {
                    int pidIndex = e.PayloadIndex("PID");
                    int pid      = (int)e.PayloadValue(pidIndex);
                    int bytes    = (int)e.PayloadValue(sizeIndex);
                    lock (sessionData)
                    {
                        if (sessionData.TryGetValue(pid, out DownloadSession info))
                        {
                            info.AddTotal(bytes);
                        }
                        else
                        {
                            sessionData[pid] = new DownloadSession(pid, (int)e.PayloadValue(sizeIndex));
                        }
                    }
                }
                catch { }
            }
        }
예제 #2
0
        public void addNewTableData(TraceEvent data, string PID)
        {
            try
            {
                DataRow dr      = dt.NewRow();
                Process process = Process.GetProcessById(Int32.Parse(PID));

                string processName = process.ProcessName;
                dr[0] = processName;
                dr[1] = PID;
                if (data.EventName.Contains("Send") || data.EventName.Contains("Reconnect") || data.EventName.Contains("Copy"))
                {
                    dr[2] = data.PayloadValue(1);
                }
                else if (data.EventName.Contains("Recv"))
                {
                    dr[3] = data.PayloadValue(1);
                }
                dr[4] = 0;
                int port = Int32.Parse(data.PayloadValue(5).ToString());
                if (port < 0)
                {
                    port = port * -1;
                }
                dr[5] = port;
                dt.Rows.Add(dr);
            }
            catch (ArgumentException e)
            {
                //Process has been removed
            }
        }
예제 #3
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
        void OnDxgkrnlDmaPacketStop(TraceEvent obj)
        {
            Debug.Assert(obj.EventName == "DmaPacket/Stop");

            Debug.Assert(obj.PayloadNames[0] == "hContext");
            ulong hContext = (ulong)obj.PayloadValue(0);

            Debug.Assert(obj.PayloadNames[1] == "PacketType");
            int packetType = (int)obj.PayloadValue(1);

            Debug.Assert(obj.PayloadNames[2] == "uliCompletionId");
            long submissionId = (long)obj.PayloadValue(2);

            Debug.Assert(obj.PayloadNames[3] == "ulQueueSubmitSequence");
            int queueSubmitSequence = (int)obj.PayloadValue(3);

            ContextInfo context = FindOrCreateContext(hContext);

            DmaPacket packet = null;

            if (!context.DmaLookup.ContainsKey(submissionId))
            {
                // End packet for something we don't about, drop it
                return;
            }

            packet     = context.DmaLookup[submissionId];
            packet.End = obj.TimeStamp;
        }
예제 #4
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
 void OnDxgkrnlVSyncInterrupt(TraceEvent obj)
 {
     Debug.Assert(obj.EventName == "VSyncInterrupt" && obj.PayloadNames.Length == 3);
     ulong pDxgiAdapter           = (ulong)obj.PayloadValue(0);
     int   vidPnTargetId          = (int)obj.PayloadValue(1);
     long  scannedPhysicalAddress = (long)obj.PayloadValue(2);
 }
예제 #5
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
        void OnDxgkrnlDeviceStart(TraceEvent obj)
        {
            Debug.Assert(obj.EventName == "Device/DC_Start" && obj.PayloadNames.Length == 6);

            Debug.Assert(obj.PayloadNames[0] == "hProcessId");
            int processId = (int)(UInt64)obj.PayloadValue(0);

            Debug.Assert(obj.PayloadNames[1] == "pDxgAdapter");
            ulong pDxgAdapter = (ulong)obj.PayloadValue(1);

            Debug.Assert(obj.PayloadNames[3] == "hDevice");
            ulong hDevice = (ulong)obj.PayloadValue(3);

            // Make sure the device doesn't already exist (error if it does)
            if (deviceLookup.ContainsKey(hDevice))
            {
                Debug.Assert(false);
                return;
            }

            DeviceInfo device = new DeviceInfo();

            AllDevices.Add(device);
            deviceLookup.Add(hDevice, device);

            device.hDevice = hDevice;
            device.Adapter = FindOrCreateAdapter(pDxgAdapter);
            device.Process = FindOrCreateProcess(processId);
        }
예제 #6
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
        void OnDxgkrnlAdapterStart(TraceEvent obj)
        {
            Debug.Assert(obj.EventName == "Adapter/DC_Start" && obj.PayloadNames.Length == 27);

            Debug.Assert(obj.PayloadNames[1] == "pDxgAdapter");
            ulong pDxgAdapter = (ulong)obj.PayloadValue(1);

            if (adapterLookup.ContainsKey(pDxgAdapter))
            {
                Debug.Assert(false);
                return;
            }

            AdapterInfo adapter = new AdapterInfo();

            AllAdapters.Add(adapter);
            adapterLookup.Add(pDxgAdapter, adapter);

            adapter.pDxgiAdapter = pDxgAdapter;

            Debug.Assert(obj.PayloadNames[2] == "NbVidPnSources");
            adapter.NumVidPnSources = (int)obj.PayloadValue(2);

            Debug.Assert(obj.PayloadNames[22] == "PagingNode");
            adapter.PagingNode = (int)obj.PayloadValue(22);

            Debug.Assert(obj.PayloadNames[25] == "AdapterType");
            adapter.AdapterType = (AdapterType)(int)obj.PayloadValue(25);
        }
예제 #7
0
 public LockAcquisition(TraceEvent ev, LockAcquisitionType type)
 {
     // Old thread id & process id
     this.Lock            = (long)ev.PayloadValue(0);
     this.Flag            = (long)ev.PayloadValue(1);
     this.Type            = this.Flag == -1 ? LockAcquisitionType.Release : type;
     this.ThreadId        = ev.ThreadID;
     this.ProcessId       = ev.ProcessID;
     this.ProcessorNumber = ev.ProcessorNumber;
     this.TimeStamp       = ev.TimeStamp;
     this.TimeStamp100ns  = ev.TimeStamp100ns;
 }
예제 #8
0
 public CSwitch(TraceEvent sw)
 {
     // Old thread id & process id
     this.OldThreadId     = (int)sw.PayloadValue(0);
     this.OldProcessId    = (int)sw.PayloadValue(1);
     this.NewThreadId     = (int)sw.PayloadValue(3);
     this.NewProcessId    = (int)sw.PayloadValue(4);
     this.State           = (ThreadState)sw.PayloadValue(13);
     this.ProcessorNumber = sw.ProcessorNumber;
     this.TimeStamp       = sw.TimeStamp;
     this.TimeStamp100ns  = sw.TimeStamp100ns;
 }
예제 #9
0
        private void HandleBeginInstrumentReporting(TraceEvent obj)
        {
            string sessionId      = (string)obj.PayloadValue(0);
            string meterName      = (string)obj.PayloadValue(1);
            string instrumentName = (string)obj.PayloadValue(3);

            if (sessionId != _metricsEventSourceSessionId)
            {
                return;
            }
            MeterInstrumentEventObserved(meterName, instrumentName, obj.TimeStamp);
        }
예제 #10
0
        private void HandleObservableInstrumentCallbackError(TraceEvent obj)
        {
            string sessionId = (string)obj.PayloadValue(0);
            string error     = (string)obj.PayloadValue(1);

            if (sessionId != _metricsEventSourceSessionId)
            {
                return;
            }
            _renderer.SetErrorText(
                "Exception thrown from an observable instrument callback in the target process:" + Environment.NewLine +
                error
                );
        }
예제 #11
0
        private void HandleError(TraceEvent obj)
        {
            string sessionId = (string)obj.PayloadValue(0);
            string error     = (string)obj.PayloadValue(1);

            if (sessionId != _metricsEventSourceSessionId)
            {
                return;
            }
            _renderer.SetErrorText(
                "Error reported from target process:" + Environment.NewLine +
                error
                );
            _shouldExit.TrySetResult(ReturnCode.TracingError);
        }
예제 #12
0
        private void ServiceFabricTraceEvent(TraceEvent data)
        {
            var eventId         = (ushort)data.ID;
            var eventIsRelevant =
                (
                    (data.Level <= TraceEventLevel.Error && data.Level >= TraceEventLevel.Critical) ||
                    (
                        ServiceFabricEtw.Operational.ClusterEventsFilter(eventId, data) ||
                        ServiceFabricEtw.Operational.NodeEventsFilter(eventId, data)
                    ));

            if (!eventIsRelevant)
            {
                return;
            }

            var properties = data.PayloadNames
                             .Select((name, index) =>
            {
                if (data.PayloadValue(index) is DateTime dateTimeValue)
                {
                    return(new KeyValuePair <string, string>(name, dateTimeValue.ToString("o")));
                }
                return(new KeyValuePair <string, string>(name, data.PayloadString(index, Culture)));
            })
                             .ToDictionary(x => x.Key, x => x.Value);

            properties.Add("eventID", data.ID.ToString());
            properties.Add("name", data.EventName);
            properties.Add("timeStamp", data.TimeStamp.ToString("o"));

            AppInsightsClient.TrackTrace(data.FormattedMessage, data.ToSeverityLevel(), properties);
        }
예제 #13
0
        public static bool ValidateSimpleEvent(TraceEvent traceEvent, int eventCounter)
        {
            if (traceEvent.EventName != "SimpleEvent")
            {
                Console.WriteLine("Got an event that didn't match while parsing SimpleEvent");
                return(false);
            }


            if ((int)traceEvent.ID != 2)
            {
                Console.WriteLine("SimpleEvent ID != 2");
                return(false);
            }

            const int expectedPayload = 1;

            string[] payloadNames = traceEvent.PayloadNames;
            if (payloadNames.Length != expectedPayload)
            {
                Console.WriteLine($"SimpleEvent payloadNames.Length={payloadNames.Length} instead of {expectedPayload} as expected...");
                return(false);
            }

            int eventValue = (int)traceEvent.PayloadValue(0);

            if (eventValue != eventCounter)
            {
                Console.WriteLine($"SimpleEvent got an out of order event expected={eventCounter} actual={eventValue}.");
                return(false);
            }

            return(true);
        }
예제 #14
0
        static ETWEvent FromTraceEvent(TraceEvent item, Dictionary <string, string> additionalProperties)
        {
            var data = new Dictionary <string, object>();

            for (var i = 0; i < item.PayloadNames.Length; i++)
            {
                data.Add(item.PayloadNames[i], item.PayloadValue(i));
            }

            if (additionalProperties != null)
            {
                foreach (var property in additionalProperties)
                {
                    if (!data.ContainsKey(property.Key))
                    {
                        data.Add(property.Key, property.Value);
                    }
                }
            }

            return(new ETWEvent
            {
                Provider = item.ProviderName,
                EventName = item.EventName,
                EventId = (ushort)item.ID,
                Message = item.FormattedMessage ?? "none",
                Level = item.Level.ToString(),
                ActivityId = item.ActivityID,
                Timestamp = item.TimeStamp.ToUniversalTime(),
                Fields = data
            });
        }
예제 #15
0
            public QueuePacketWdatEntry(TraceEvent data) : base(data)
            {
                AddField("opcode", data.Opcode.ToString("d"));
                AddField("ctx", NormalizeBase(data.PayloadString(0)));
                AddField("ptype", data.PayloadString(1));
                AddField("seq", NormalizeBase(data.PayloadString(2)));

                switch (data.Opcode)
                {
                case Microsoft.Diagnostics.Tracing.TraceEventOpcode.Start:
                    int type = (int)data.PayloadValue(1);
                    // not all events have these fields ?
                    if (type == 100)
                    {
                        AddField("dmabufsize", NormalizeBase(data.PayloadString(3)));
                        AddField("alloclistsize", NormalizeBase(data.PayloadString(4)));
                        AddField("patchloclistsize", NormalizeBase(data.PayloadString(5)));
                        AddField("present", data.PayloadString(6));
                        AddField("dmabuf", NormalizeBase(data.PayloadString(7)));
                        AddField("packet", NormalizeBase(data.PayloadString(8)));
                        AddField("afence", NormalizeBase(data.PayloadString(9)));
                    }
                    break;

                case Microsoft.Diagnostics.Tracing.TraceEventOpcode.Info:
                    // No extra fields
                    break;

                case Microsoft.Diagnostics.Tracing.TraceEventOpcode.Stop:
                    AddField("preempted", data.PayloadString(3));
                    AddField("timedout", data.PayloadString(4));
                    AddField("packet", NormalizeBase(data.PayloadString(5)));
                    break;
                }
            }
예제 #16
0
 private static void WriteEventData(JsonTextWriter writer, TraceEvent traceEvent)
 {
     String[] names = traceEvent.PayloadNames;
     for (int i = 0; i < names.Length; i++)
     {
         writer.WritePropertyName("event_" + names[i].ToLower());
         writer.WriteValue(traceEvent.PayloadValue(i));
     }
 }
예제 #17
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
        void OnDxgkrnlDmaPacketInfo(TraceEvent obj)
        {
            Debug.Assert(obj.EventName == "DmaPacket" && (int)obj.Opcode == 0);

            Debug.Assert(obj.PayloadNames[0] == "hContext");
            ulong hContext = (ulong)obj.PayloadValue(0);

            ContextInfo context = FindOrCreateContext(hContext);
        }
예제 #18
0
파일: Program.cs 프로젝트: tddstud10/VS
        private static object GetValue(this TraceEvent data, string payLoadName)
        {
            var index = data.PayloadIndex(payLoadName);

            if (index < 0)
            {
                return(string.Format("Value with name '{0}' not found.", payLoadName));
            }

            return(data.PayloadValue(index));
        }
예제 #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="traceEvent"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static object GetPayloadValue(TraceEvent traceEvent, string name)
        {
            int index = traceEvent.PayloadIndex(name);

            if (index < 0)
            {
                return(null);
            }

            return(traceEvent.PayloadValue(index));
        }
        private ReadOnlyCollection <object> CreatePayload(TraceEvent traceEvent)
        {
            var payloadValues = new List <object>();

            for (int i = 0; i < traceEvent.PayloadNames.Length; i++)
            {
                payloadValues.Add(traceEvent.PayloadValue(i));
            }

            return(new ReadOnlyCollection <object>(payloadValues));
        }
예제 #21
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
        void OnDxgkrnlDpiReportAdapter(TraceEvent obj)
        {
            Debug.Assert(obj.EventName == "DpiReportAdapter" && obj.PayloadNames.Length == 12);

            Debug.Assert(obj.PayloadNames[0] == "pDxgAdapter");
            ulong pDxgiAdapter = (ulong)obj.PayloadValue(0);

            if (!adapterLookup.ContainsKey(pDxgiAdapter))
            {
                Debug.Assert(false);
                return;
            }

            AdapterInfo adapter = adapterLookup[pDxgiAdapter];

            Debug.Assert(obj.PayloadNames[6] == "VendorID");
            adapter.VendorID = (int)obj.PayloadValue(6);

            Debug.Assert(obj.PayloadNames[11] == "AdapterLuid");
            adapter.AdapterLuid = (long)obj.PayloadValue(11);
        }
예제 #22
0
        public void updateTableRow(TraceEvent data, string PID)
        {
            DataRow row = dt.Select("PID = '" + PID + "'").FirstOrDefault();
            int     total;

            try
            {
                Process pname = Process.GetProcessById(Int32.Parse(PID));
                if (data.EventName.Contains("Send") || data.EventName.Contains("Reconnect") || data.EventName.Contains("Copy"))
                {
                    row[2] = data.PayloadValue(1);
                }
                else if (data.EventName.Contains("Recv"))
                {
                    row[3] = data.PayloadValue(1);
                }
                String bytesSent = row[2].ToString();
                String bytesRec  = row[3].ToString();
                if (bytesRec.Equals(""))
                {
                    bytesRec = "0";
                }
                if (bytesSent.Equals(""))
                {
                    bytesSent = "0";
                }
                total  = Int32.Parse(bytesSent) + Int32.Parse(bytesRec);
                row[4] = total;
                int port = Int32.Parse(data.PayloadValue(5).ToString());
                if (port < 0)
                {
                    port = port * -1;
                }
                row[5] = port;
            }
            catch (ArgumentException e)
            {
                dt.Rows.Remove(row);
            }
        }
예제 #23
0
        private void HandleTimeSeriesLimitReached(TraceEvent obj)
        {
            string sessionId = (string)obj.PayloadValue(0);

            if (sessionId != _metricsEventSourceSessionId)
            {
                return;
            }
            _renderer.SetErrorText(
                $"Warning: Time series tracking limit ({_maxTimeSeries}) reached. Not all data is being shown." + Environment.NewLine +
                "The limit can be changed with --maxTimeSeries but will use more memory in the target process."
                );
        }
예제 #24
0
        // Create 1 line that embodies the data in event 'data'

        internal static string Parse(TraceEvent data)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("EVENT ");
            sb.Append(data.TimeStampRelativeMSec.ToString("n3")).Append(": ");
            sb.Append(data.ProviderName).Append("/").Append(data.EventName).Append(" ");

            sb.Append("PID=").Append(data.ProcessID).Append("; ");
            sb.Append("TID=").Append(data.ThreadID).Append("; ");
            sb.Append("PName=").Append(data.ProcessName).Append("; ");
            sb.Append("ProceNum=").Append(data.ProcessorNumber).Append("; ");
            sb.Append("DataLen=").Append(data.EventDataLength).Append("; ");

            string[] payloadNames = data.PayloadNames;
            for (int i = 0; i < payloadNames.Length; i++)
            {
                // Normalize DateTime to UTC so tests work in any timezone.
                object value = data.PayloadValue(i);
                string valueStr;
                if (value is DateTime)
                {
                    valueStr = ((DateTime)value).ToUniversalTime().ToString("yy/MM/dd HH:mm:ss.ffffff");
                }
                else
                {
                    valueStr = (data.PayloadString(i));
                }

                // To debug this set first chance exeption handing before calling PayloadString above.
                Assert.False(valueStr.Contains("EXCEPTION_DURING_VALUE_LOOKUP"), "Exception during event Payload Processing");

                // Keep the value size under control and remove newlines.
                if (valueStr.Length > 20)
                {
                    valueStr = valueStr.Substring(0, 20) + "...";
                }

                valueStr = valueStr.Replace("\n", "\\n").Replace("\r", "\\r");

                sb.Append(payloadNames[i]).Append('=').Append(valueStr).Append("; ");
            }

            if (data.ContainerID != null)
            {
                sb.Append("ContainerID=").Append(data.ContainerID).Append("; ");
            }

            return(sb.ToString());
        }
예제 #25
0
        private void HandleMultipleSessionsNotSupportedError(TraceEvent obj)
        {
            string runningSessionId = (string)obj.PayloadValue(0);

            if (runningSessionId == _metricsEventSourceSessionId)
            {
                // If our session is the one that is running then the error is not for us,
                // it is for some other session that came later
                return;
            }
            _renderer.SetErrorText(
                "Error: Another metrics collection session is already in progress for the target process, perhaps from another tool?" + Environment.NewLine +
                "Concurrent sessions are not supported.");
            _shouldExit.TrySetResult(ReturnCode.SessionCreationError);
        }
예제 #26
0
파일: GPUTrace.cs 프로젝트: rezanour/GPerf
        void OnDxgkrnlDmaPacketStart(TraceEvent obj)
        {
            Debug.Assert(obj.EventName == "DmaPacket/Start" && obj.PayloadNames.Length == 7);

            Debug.Assert(obj.PayloadNames[0] == "hContext");
            ulong hContext = (ulong)obj.PayloadValue(0);

            Debug.Assert(obj.PayloadNames[2] == "PacketType");
            int packetType = (int)obj.PayloadValue(2);

            Debug.Assert(obj.PayloadNames[3] == "uliSubmissionId");
            long submissionId = (long)obj.PayloadValue(3);

            Debug.Assert(obj.PayloadNames[4] == "ulQueueSubmitSequence");
            int queueSubmitSequence = (int)obj.PayloadValue(4);

            ContextInfo context = FindOrCreateContext(hContext);

            DmaPacket packet = null;

            if (context.DmaLookup.ContainsKey(submissionId))
            {
                packet = context.DmaLookup[submissionId];
            }
            else
            {
                packet = new DmaPacket();
                packet.SubmissionId        = submissionId;
                packet.QueueSubmitSequence = queueSubmitSequence;
                packet.PacketType          = packetType;
                context.DmaPackets.Add(packet);
                context.DmaLookup.Add(submissionId, packet);
            }

            packet.Start = obj.TimeStamp;
        }
예제 #27
0
        public EtwEvent(TraceEvent traceData)
        {
            EventName        = traceData.EventName;
            ProviderName     = traceData.ProviderName;
            FormattedMessage = traceData.FormattedMessage;

            ProcessID = traceData.ProcessID;

            MachineName = GetFQDN();


            for (int i = 0; i < traceData.PayloadNames.Length; i++)
            {
                Payload.Add(traceData.PayloadNames[i], traceData.PayloadValue(i));
            }
        }
        internal static ICounterPayload GetCounter(this TraceEvent traceEvent)
        {
            var             payloadVal    = (IDictionary <string, object>)(traceEvent.PayloadValue(0));
            var             payloadFields = (IDictionary <string, object>)(payloadVal["Payload"]);
            ICounterPayload payload;

            if (payloadFields.ContainsKey("CounterType"))
            {
                payload = payloadFields["CounterType"].Equals("Sum") ? (ICounterPayload) new IncrementingCounterPayload(payloadFields) : (ICounterPayload) new CounterPayload(payloadFields);
            }
            else
            {
                payload = payloadFields.Count == 6 ? (ICounterPayload) new IncrementingCounterPayload(payloadFields) : (ICounterPayload) new CounterPayload(payloadFields);
            }
            return(payload);
        }
예제 #29
0
        private void ProcessEvents(TraceEvent data)
        {
            if (data.EventName.Equals("EventCounters"))
            {
                // the TraceEvent implementation throws not implemented exception if you try
                // to get the list of the dictionary keys: it is needed to iterate on the dictionary
                // and get each key/value pair.

                IDictionary <string, object> countersPayload = null;
                IDictionary <string, object> kvPairs         = null;
                object payloadValue = null;

                try
                {
                    payloadValue = data.PayloadValue(0);

                    countersPayload = (IDictionary <string, object>)payloadValue;

                    object x = countersPayload["Payload"];
                    kvPairs = (IDictionary <string, object>)x;
                }
                catch (Exception ex)
                {
                    ExceptionLogger.LogExceptionThrottled(ex, "DotNetCounters", 1, $"Casting issue. {payloadValue.ToString()}");
                    return;
                }

                var name        = string.Intern(kvPairs["Name"].ToString());
                var displayName = string.Intern(kvPairs["DisplayName"].ToString());

                var counterType = kvPairs["CounterType"];
                if (counterType.Equals("Sum"))
                {
                    OnSumCounter(data.ProviderName, name, displayName, kvPairs);
                }
                else
                if (counterType.Equals("Mean"))
                {
                    OnMeanCounter(data.ProviderName, name, displayName, kvPairs);
                }
                else
                {
                    throw new InvalidOperationException($"Unsupported counter type '{counterType}'");
                }
            }
        }
예제 #30
0
파일: Extensions.cs 프로젝트: zdzhjx/etrace
        public static string AsRawString(this TraceEvent e)
        {
            var sb = new StringBuilder();

            sb.Append($"{e.EventName} [PID={e.ProcessID} TID={e.ThreadID} TIME={e.TimeStamp}]");
            for (int i = 0; i < e.PayloadNames.Length; ++i)
            {
                try
                {
                    sb.AppendFormat("\n  {0,-20} = {1}", e.PayloadNames[i], e.PayloadValue(i));
                }
                catch (ArgumentOutOfRangeException)
                {
                    // TraceEvent sometimes throws this exception from PayloadValue(i).
                }
            }
            return(sb.ToString());
        }
예제 #31
0
        private ReadOnlyCollection<object> CreatePayload(TraceEvent traceEvent)
        {
            List<object> payloadValues = new List<object>();

            for (int i = 0; i < traceEvent.PayloadNames.Length; i++)
            {
                payloadValues.Add(traceEvent.PayloadValue(i));
            }

            return new ReadOnlyCollection<object>(payloadValues);
        }