Пример #1
0
        public static bool ConvertToJson(JsonWriter jsonWriter, IEnumerable<string> inputFiles, Action<string> reportError)
        {
            var list = inputFiles.ToList();
            var deserializer = new Deserializer<EtwJsonWriter>(new EtwJsonWriter(jsonWriter));

            Stopwatch watch = new Stopwatch();
            watch.Start();

            int count = list.Count;
            var fileSessions = new EVENT_TRACE_LOGFILEW[count];
            var handles = new ulong[count];

            for (int i = 0; i < count; ++i)
            {
                unsafe
                {
                    fileSessions[i] = new EVENT_TRACE_LOGFILEW
                    {
                        LogFileName = list[i],
                        EventRecordCallback = deserializer.Deserialize,
                        BufferCallback = deserializer.BufferCallback,
                        LogFileMode = Etw.PROCESS_TRACE_MODE_EVENT_RECORD | Etw.PROCESS_TRACE_MODE_RAW_TIMESTAMP
                    };

                    handles[i] = Etw.OpenTrace(ref fileSessions[i]);
                }
            }

            for (int i = 0; i < handles.Length; ++i)
            {
                unchecked
                {
                    if (handles[i] == (ulong)(~0))
                    {
                        switch (Marshal.GetLastWin32Error())
                        {
                        case 0x57:
                            reportError("ERROR: For file: " + list[i] + " Windows returned 0x57 -- The Logfile parameter is NULL.");
                            return false;
                        case 0xA1:
                            reportError("ERROR: For file: " + list[i] + " Windows returned 0xA1 -- The specified path is invalid.");
                            return false;
                        case 0x5:
                            reportError("ERROR: For file: " + list[i] + " Windows returned 0x5 -- Access is denied.");
                            return false;
                        default:
                            reportError("ERROR: For file: " + list[i] + " Windows returned an unknown error.");
                            return false;
                        }
                    }
                }
            }

            jsonWriter.WriteStartObject();
            jsonWriter.WritePropertyName("Events");

            jsonWriter.WriteStartArray();
            Etw.ProcessTrace(handles, (uint)handles.Length, IntPtr.Zero, IntPtr.Zero);
            jsonWriter.WriteEndArray();

            jsonWriter.WriteEndObject();

            GC.KeepAlive(fileSessions);
            return true;
        }
Пример #2
0
        public static bool ConvertToJson(JsonWriter jsonWriter, IEnumerable <string> inputFiles, Action <string> reportError)
        {
            var list         = inputFiles.ToList();
            var deserializer = new Deserializer <EtwJsonWriter>(new EtwJsonWriter(jsonWriter));

            Stopwatch watch = new Stopwatch();

            watch.Start();

            int count        = list.Count;
            var fileSessions = new EVENT_TRACE_LOGFILEW[count];
            var handles      = new ulong[count];

            for (int i = 0; i < count; ++i)
            {
                unsafe
                {
                    fileSessions[i] = new EVENT_TRACE_LOGFILEW
                    {
                        LogFileName         = list[i],
                        EventRecordCallback = deserializer.Deserialize,
                        BufferCallback      = deserializer.BufferCallback,
                        LogFileMode         = Etw.PROCESS_TRACE_MODE_EVENT_RECORD | Etw.PROCESS_TRACE_MODE_RAW_TIMESTAMP
                    };

                    handles[i] = Etw.OpenTrace(ref fileSessions[i]);
                }
            }

            for (int i = 0; i < handles.Length; ++i)
            {
                unchecked
                {
                    if (handles[i] == (ulong)(~0))
                    {
                        switch (Marshal.GetLastWin32Error())
                        {
                        case 0x57:
                            reportError("ERROR: For file: " + list[i] + " Windows returned 0x57 -- The Logfile parameter is NULL.");
                            return(false);

                        case 0xA1:
                            reportError("ERROR: For file: " + list[i] + " Windows returned 0xA1 -- The specified path is invalid.");
                            return(false);

                        case 0x5:
                            reportError("ERROR: For file: " + list[i] + " Windows returned 0x5 -- Access is denied.");
                            return(false);

                        default:
                            reportError("ERROR: For file: " + list[i] + " Windows returned an unknown error.");
                            return(false);
                        }
                    }
                }
            }

            jsonWriter.WriteStartObject();
            jsonWriter.WritePropertyName("Events");

            jsonWriter.WriteStartArray();
            Etw.ProcessTrace(handles, (uint)handles.Length, IntPtr.Zero, IntPtr.Zero);
            jsonWriter.WriteEndArray();

            jsonWriter.WriteEndObject();

            GC.KeepAlive(fileSessions);

            for (int i = 0; i < count; ++i)
            {
                Etw.CloseTrace(handles[i]);
            }

            return(true);
        }
Пример #3
0
 internal static extern UInt64 OpenTrace([In][Out] ref EVENT_TRACE_LOGFILEW Logfile);