internal static void AddTraceArgument(MemoryTraceBuilder builder, object argument)
        {
            if (argument == null)
            {
                builder.AddArgument(string.Empty);
                return;
            }
            if (argument is int)
            {
                builder.AddArgument((int)argument);
                return;
            }
            if (argument is long)
            {
                builder.AddArgument((long)argument);
                return;
            }
            if (argument is Guid)
            {
                builder.AddArgument((Guid)argument);
                return;
            }
            ITraceable traceable = argument as ITraceable;

            if (traceable != null)
            {
                builder.AddArgument <ITraceable>(traceable);
                return;
            }
            builder.AddArgument <object>(argument);
        }
        public static void TraceInMemory <T0, T1, T2>(int lid, TraceType traceType, Guid componentGuid, int traceTag, long id, string format, T0 argument0, T1 argument1, T2 argument2)
        {
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();
            bool flag = false;

            try
            {
                if (!memoryTraceBuilder.InsideTraceCall)
                {
                    memoryTraceBuilder.BeginEntry(traceType, componentGuid, traceTag, id, format);
                    memoryTraceBuilder.AddArgument <T0>(argument0);
                    memoryTraceBuilder.AddArgument <T1>(argument1);
                    memoryTraceBuilder.AddArgument <T2>(argument2);
                    memoryTraceBuilder.EndEntry();
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    memoryTraceBuilder.Reset();
                }
            }
        }
        public static void TraceInMemory(int lid, TraceType traceType, Guid componentGuid, int traceTag, long id, string format, object[] arguments)
        {
            if (arguments == null)
            {
                return;
            }
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();
            bool flag = false;

            try
            {
                if (!memoryTraceBuilder.InsideTraceCall)
                {
                    memoryTraceBuilder.BeginEntry(traceType, componentGuid, traceTag, id, format);
                    for (int i = 0; i < arguments.Length; i++)
                    {
                        ExTraceInternal.AddTraceArgument(memoryTraceBuilder, arguments[i]);
                    }
                    memoryTraceBuilder.EndEntry();
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    memoryTraceBuilder.Reset();
                }
            }
        }
 public void CopyTo(MemoryTraceBuilder destination, int startIndex)
 {
     if ((this.startEntry < this.freeEntry && (startIndex < this.startEntry || startIndex >= this.freeEntry)) || (this.startEntry > this.freeEntry && startIndex < this.startEntry && startIndex >= this.freeEntry))
     {
         throw new ArgumentOutOfRangeException("startIndex");
     }
     int num = startIndex;
     while (num != this.freeEntry)
     {
         TraceEntry traceEntry = this.entries[num];
         destination.BeginEntry(traceEntry);
         if (destination.ReserveSpace(traceEntry.Length))
         {
             int startIndex2 = traceEntry.StartIndex;
             for (int i = traceEntry.Length; i > 0; i--)
             {
                 char nextCharInTraceBuffer = MemoryTraceBuilder.GetNextCharInTraceBuffer(this.traceBuffer, ref startIndex2);
                 destination.AppendWithoutCheck(nextCharInTraceBuffer);
             }
         }
         destination.EndEntry();
         if (++num == this.entryArrayLength)
         {
             num = 0;
         }
     }
 }
Exemple #5
0
        public IEnumerable <TraceEntry> GetTraces()
        {
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();

            if (memoryTraceBuilder == null)
            {
                return(new TraceEntry[0]);
            }
            return(memoryTraceBuilder.GetTraces());
        }
 internal List<KeyValuePair<TraceEntry, List<object>>> GetTraceEntries()
 {
     List<KeyValuePair<TraceEntry, List<object>>> list = new List<KeyValuePair<TraceEntry, List<object>>>();
     for (int num = this.startEntry; num != this.freeEntry; num = (num + 1) % this.entryArrayLength)
     {
         List<object> traceArguments = MemoryTraceBuilder.GetTraceArguments(this.traceBuffer, this.entries[num].StartIndex, this.entries[num].Length);
         list.Add(new KeyValuePair<TraceEntry, List<object>>(this.entries[num], traceArguments));
     }
     return list;
 }
        internal static MemoryTraceBuilder GetMemoryTraceBuilder()
        {
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.memoryTraceBuilder;

            if (memoryTraceBuilder != null)
            {
                return(memoryTraceBuilder);
            }
            return(ExTraceInternal.CreateMemoryTraceBuilder());
        }
        public static List <KeyValuePair <TraceEntry, List <object> > > GetMemoryTrace()
        {
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();

            if (memoryTraceBuilder != null)
            {
                return(memoryTraceBuilder.GetTraceEntries());
            }
            return(null);
        }
 public static List<object> GetTraceArguments(char[] buffer, int startIndex, int length)
 {
     List<object> list = new List<object>();
     int i = length;
     int num = startIndex;
     while (i > 0)
     {
         i -= MemoryTraceBuilder.GetTraceArgument(list, buffer, ref num);
     }
     return list;
 }
        private static MemoryTraceBuilder CreateMemoryTraceBuilder()
        {
            MemoryTraceBuilder memoryTraceBuilder = new MemoryTraceBuilder(1000, 64000);

            lock (ExTraceInternal.traceBuilderList)
            {
                ExTraceInternal.traceBuilderList.RemoveAll((WeakReference reference) => reference.Target == null);
                ExTraceInternal.traceBuilderList.Add(new WeakReference(memoryTraceBuilder));
            }
            ExTraceInternal.memoryTraceBuilder = memoryTraceBuilder;
            return(memoryTraceBuilder);
        }
 private static int GetTraceArgument(List<object> arguments, char[] buffer, ref int startIndex)
 {
     int result = 0;
     int nextCharInTraceBuffer = (int)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex);
     if (nextCharInTraceBuffer == 0)
     {
         int num = (int)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex);
         num += (int)((int)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex) << 16);
         result = 3;
         arguments.Add(num);
     }
     else if (nextCharInTraceBuffer == 1)
     {
         long num2 = (long)((ulong)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex));
         num2 += (long)((long)((ulong)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex)) << 16);
         num2 += (long)((long)((ulong)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex)) << 32);
         num2 += (long)((long)((ulong)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex)) << 48);
         result = 5;
         arguments.Add(num2);
     }
     else if (nextCharInTraceBuffer == 2)
     {
         byte[] array = new byte[16];
         for (int i = 0; i < 16; i += 2)
         {
             char nextCharInTraceBuffer2 = MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex);
             array[i] = (byte)nextCharInTraceBuffer2;
             array[i + 1] = (byte)(nextCharInTraceBuffer2 >> 8);
         }
         Guid guid = new Guid(array);
         arguments.Add(guid);
         result = 9;
     }
     else if (nextCharInTraceBuffer == 3)
     {
         int nextCharInTraceBuffer3 = (int)MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex);
         StringBuilder stringBuilder = new StringBuilder();
         for (int j = 0; j < nextCharInTraceBuffer3; j++)
         {
             stringBuilder.Append(MemoryTraceBuilder.GetNextCharInTraceBuffer(buffer, ref startIndex));
         }
         result = nextCharInTraceBuffer3 + 2;
         arguments.Add(stringBuilder.ToString());
     }
     return result;
 }
Exemple #12
0
        public void TraceOperationCompletedAndUpdateContext(long id)
        {
            if (!ExTraceConfiguration.Instance.InMemoryTracingEnabled)
            {
                return;
            }
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();

            this.AddOperationCompletedMarker(memoryTraceBuilder, id);
            int startIndex = memoryTraceBuilder.FindLastEntryIndex(2, TroubleshootingContext.markerEntry.TraceType, TroubleshootingContext.markerEntry.TraceTag, TroubleshootingContext.markerEntry.ComponentGuid, TroubleshootingContext.markerEntry.FormatString);

            lock (this)
            {
                if (this.memoryTraceBuilder == null)
                {
                    this.memoryTraceBuilder = new MemoryTraceBuilder(1000, 128000);
                }
                memoryTraceBuilder.CopyTo(this.memoryTraceBuilder, startIndex);
            }
        }
        public static void DumpMemoryTrace(TextWriter writer)
        {
            if (writer == null)
            {
                return;
            }
            bool addHeader = true;

            lock (ExTraceInternal.traceBuilderList)
            {
                writer.WriteLine("ThreadId;ComponentGuid;Instance ID;TraceTag;TraceType;TimeStamp;Message;");
                foreach (WeakReference weakReference in ExTraceInternal.traceBuilderList)
                {
                    MemoryTraceBuilder memoryTraceBuilder = weakReference.Target as MemoryTraceBuilder;
                    if (memoryTraceBuilder != null)
                    {
                        memoryTraceBuilder.Dump(writer, addHeader, true);
                        addHeader = false;
                    }
                }
            }
        }
        public static void TraceInMemory(int lid, TraceType traceType, Guid componentGuid, int traceTag, long id, string message)
        {
            MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();
            bool flag = false;

            try
            {
                if (!memoryTraceBuilder.InsideTraceCall)
                {
                    memoryTraceBuilder.BeginEntry(traceType, componentGuid, traceTag, id, message);
                    memoryTraceBuilder.EndEntry();
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    memoryTraceBuilder.Reset();
                }
            }
        }
Exemple #15
0
 private void ReportProblem(MemoryTraceBuilder contextTraceBuilder, Exception exception, string functionName, bool isExceptionReport, bool isExceptionReportTerminating)
 {
     this.ReportProblem(contextTraceBuilder, exception, functionName, isExceptionReport, isExceptionReportTerminating, false);
 }
Exemple #16
0
 private void AddOperationCompletedMarker(MemoryTraceBuilder memoryTraceBuilder, long id)
 {
     memoryTraceBuilder.BeginEntry(TroubleshootingContext.markerEntry.TraceType, TroubleshootingContext.markerEntry.ComponentGuid, TroubleshootingContext.markerEntry.TraceTag, id, TroubleshootingContext.markerEntry.FormatString);
     memoryTraceBuilder.EndEntry();
 }
Exemple #17
0
        private void ReportProblem(MemoryTraceBuilder contextTraceBuilder, Exception exception, string functionName, bool isExceptionReport, bool isExceptionReportTerminating, bool verbose)
        {
            using (TempFileStream tempFileStream = TempFileStream.CreateInstance("Traces_", false))
            {
                using (StreamWriter streamWriter = new StreamWriter(tempFileStream))
                {
                    bool addHeader = true;
                    if (contextTraceBuilder != null)
                    {
                        lock (this)
                        {
                            contextTraceBuilder.Dump(streamWriter, addHeader, verbose);
                        }
                        addHeader = false;
                    }
                    MemoryTraceBuilder memoryTraceBuilder = ExTraceInternal.GetMemoryTraceBuilder();
                    if (memoryTraceBuilder != null)
                    {
                        memoryTraceBuilder.Dump(streamWriter, addHeader, verbose);
                    }
                    streamWriter.Flush();
                }
                StringBuilder stringBuilder = new StringBuilder(1024);
                TroubleshootingContext.DumpExceptionInfo(exception, stringBuilder);
                if (TroubleshootingContext.IsTestTopology())
                {
                    string path = ExWatson.AppName + "_" + DateTime.UtcNow.ToString("yyyyMMdd_hhmmss") + ".trace";
                    try
                    {
                        File.Copy(tempFileStream.FilePath, Path.Combine(Path.Combine(Environment.GetEnvironmentVariable("SystemDrive"), "\\dumps"), path));
                    }
                    catch
                    {
                    }
                }
                if (exception != TroubleshootingContext.FaultInjectionInvalidOperationException)
                {
                    if (isExceptionReport)
                    {
                        WatsonExtraFileReportAction watsonExtraFileReportAction = null;
                        try
                        {
                            watsonExtraFileReportAction = new WatsonExtraFileReportAction(tempFileStream.FilePath);
                            ExWatson.RegisterReportAction(watsonExtraFileReportAction, WatsonActionScope.Thread);
                            ExWatson.SendReport(exception, isExceptionReportTerminating ? ReportOptions.ReportTerminateAfterSend : ReportOptions.None, null);
                            goto IL_152;
                        }
                        finally
                        {
                            if (watsonExtraFileReportAction != null)
                            {
                                ExWatson.UnregisterReportAction(watsonExtraFileReportAction, WatsonActionScope.Thread);
                            }
                        }
                    }
                    ExWatson.SendTroubleshootingWatsonReport("15.00.1497.012", this.location, "UnexpectedCondition:" + exception.GetType().Name, exception.StackTrace, functionName, stringBuilder.ToString(), tempFileStream.FilePath);
IL_152:
                    File.Delete(tempFileStream.FilePath);
                }
            }
        }