Ejemplo n.º 1
0
        private void MergeTracesAndProcess()
        {
            int error;

            _handles = new ulong[_logFiles.Length];
            IntPtr startTime = ConvertDateTime(_startTime);
            IntPtr endTime   = ConvertDateTime(_endTime);

            for (int i = 0; i < _logFiles.Length; i++)
            {
                _handles[i] = EtwNativeMethods.OpenTrace(ref _logFiles[i]);

                if (_handles[i] == EtwNativeMethods.InvalidHandle)
                {
                    error = Marshal.GetLastWin32Error();
                    if (error == EtwNativeMethods.ErrorNotFound)
                    {
                        _observer.OnError(new FileNotFoundException("Could not find file " + _logFiles[i].LogFileName));
                        return;
                    }

                    _observer.OnError(new Win32Exception(error));
                    return;
                }
            }

            try
            {
                error = EtwNativeMethods.ProcessTrace(_handles, (uint)_handles.Length, startTime, endTime);
            }
            catch (Exception ex)
            {
                _observer.OnError(ex);
                return;
            }
            finally
            {
                if (startTime != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(startTime);
                    startTime = IntPtr.Zero;
                }

                if (endTime != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(endTime);
                    endTime = IntPtr.Zero;
                }
            }

            if (error != 0)
            {
                _observer.OnError(new Win32Exception(error));
                return;
            }

            _observer.OnCompleted();
        }
Ejemplo n.º 2
0
        private void ThreadProc()
        {
            int error;

            _handles = new ulong[_logFiles.Length];
            for (int i = 0; i < _logFiles.Length; i++)
            {
                _handles[i] = EtwNativeMethods.OpenTrace(ref _logFiles[i]);

                if (_handles[i] == EtwNativeMethods.InvalidHandle)
                {
                    error = Marshal.GetLastWin32Error();
                    if (error == EtwNativeMethods.ErrorNotFound)
                    {
                        _observer.OnError(new FileNotFoundException("Could not find file " + _logFiles[i].LogFileName));
                        return;
                    }

                    _observer.OnError(new Win32Exception(error));
                    return;
                }
            }

            try
            {
                error = EtwNativeMethods.ProcessTrace(_handles, (uint)_handles.Length, IntPtr.Zero, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                _observer.OnError(ex);
                return;
            }
            if (error != 0)
            {
                _observer.OnError(new Win32Exception(error));
                return;
            }

            _observer.OnCompleted();
        }
Ejemplo n.º 3
0
        private void ThreadProc()
        {
            int error;

            _handle = EtwNativeMethods.OpenTrace(ref _logFile);

            if (_handle == EtwNativeMethods.InvalidHandle)
            {
                error = Marshal.GetLastWin32Error();
                if (error == EtwNativeMethods.ErrorNotFound)
                {
                    _observer.OnError(new Exception("Could not find ETW real-time session " + _logFile.LoggerName));
                    return;
                }
                else
                {
                    _observer.OnError(new Win32Exception(error));
                    return;
                }
            }

            try
            {
                error = EtwNativeMethods.ProcessTrace(new[] { _handle }, 1, IntPtr.Zero, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                _observer.OnError(ex);
                return;
            }
            if (error != 0)
            {
                _observer.OnError(new Win32Exception(error));
                return;
            }

            _observer.OnCompleted();
        }