public ThreadLogSnapshot GetSnapshot()
            {
                int currentBufferCount;
                int currentCount;

                ThreadLogEntry[] currentBuffer;

                lock (ThisLock)
                {
                    currentBufferCount = this.bufferCount;
                    currentCount       = this.count;
                    currentBuffer      = this.buffer;
                }

                ThreadLogEntry[] entries = new ThreadLogEntry[currentBufferCount * bufferSize + currentCount];
                int index = 0;

                for (int i = 0; i < currentBufferCount; i++)
                {
                    Array.Copy(buffers[i], 0, entries, index, bufferSize);
                    index += bufferSize;
                }
                Array.Copy(currentBuffer, 0, entries, index, currentCount);
                return(new ThreadLogSnapshot(entries));
            }
Пример #2
0
            public ThreadLogSnapshot GetSnapshot()
            {
                int currentBufferCount;
                int currentCount;
                ThreadLogEntry[] currentBuffer;

                lock (ThisLock)
                {
                    currentBufferCount = this.bufferCount;
                    currentCount = this.count;
                    currentBuffer = this.buffer;
                }

                ThreadLogEntry[] entries = new ThreadLogEntry[currentBufferCount * bufferSize + currentCount];
                int index = 0;
                for (int i = 0; i < currentBufferCount; i++)
                {
                    Array.Copy(buffers[i], 0, entries, index, bufferSize);
                    index += bufferSize;
                }
                Array.Copy(currentBuffer, 0, entries, index, currentCount);
                return new ThreadLogSnapshot(entries);
            }
Пример #3
0
 public ThreadLogSnapshot(ThreadLogEntry[] entries)
 {
     this.entries = entries;
 }
        static void WriteLogFile()
        {
            Trace("ThreadTrace.Save");
            TextWriter writer = File.CreateText(logFileName);

            using (writer)
            {
                ThreadLogSnapshot[] logSnapshots = new ThreadLogSnapshot[logs.Count];
                writer.Write("Time");
                for (int i = 0; i < logs.Count; i++)
                {
                    logSnapshots[i] = logs[i].GetSnapshot();
                    writer.Write(", Thread ");
                    writer.Write(i.ToString());
                }
                writer.WriteLine();
                writer.Write("(Ms)");
                foreach (ThreadLog log in logs)
                {
                    if (log.IsThreadPoolThread)
                    {
                        writer.Write(", (ThreadPool)");
                    }
                    else if (log.IsBackgroundThread)
                    {
                        writer.Write(", (Background)");
                    }
                    else
                    {
                        writer.Write(", (Main)");
                    }
                }
                writer.WriteLine();
                int[] indices = new int[logs.Count];
                int   count   = 0;
                for (int i = 0; i < logs.Count; i++)
                {
                    count += logSnapshots[i].Count;
                }
                for (int j = 0; j < count; j++)
                {
                    int  earliestIndex = -1;
                    long earliestTime  = long.MaxValue;
                    for (int i = 0; i < logs.Count; i++)
                    {
                        ThreadLogSnapshot logSnapshot = logSnapshots[i];
                        int index = indices[i];
                        if (index >= logSnapshot.Count)
                        {
                            continue;
                        }
                        long time = logSnapshot[index].time;
                        if (time < earliestTime)
                        {
                            earliestIndex = i;
                            earliestTime  = time;
                        }
                    }
                    ThreadLogEntry entry = logSnapshots[earliestIndex][indices[earliestIndex]];
                    double         timeInMilliseconds = (entry.time * 1000) / (double)frequency;
                    writer.Write(timeInMilliseconds);
                    for (int i = 0; i < logs.Count; i++)
                    {
                        writer.Write(", ");
                        if (i == earliestIndex)
                        {
                            writer.Write('\"');
                            writer.Write(entry.operation);
                            writer.Write('\"');
                        }
                    }
                    writer.WriteLine();
                    indices[earliestIndex]++;
                }
            }
        }