コード例 #1
0
            private void ThreadMain()
            {
                int       epochCount   = 0;
                int       l2EpochCount = 0;
                const int ChunkSize    = 4096;
                const int Overlap      = 3;

                byte[] buffer = new byte[ChunkSize + Overlap];
                int    c      = -1;

                while (true)
                {
                    int o = c == -1 ? 0 : Overlap;
                    int a = (int)Math.Min(end - logStream1.Position, buffer.Length - o);
                    if (a == 0)
                    {
                        break;
                    }
                    while ((a != 0) && (c = logStream1.Read(buffer, o, a)) != 0)
                    {
                        o += c;
                        a -= c;
                    }

                    int i = 0;
                    while (i < Math.Min(o, ChunkSize + 1 /*extra lf*/) - 1)
                    {
                        i = Array.IndexOf(buffer, (byte)'\r', i, Math.Min(o, ChunkSize + 1 /*extra lf*/) - i - 1);
                        if (i < 0)
                        {
                            break;
                        }
                        if (buffer[i + 1] == (byte)'\r')
                        {
                            EpochVirtualList.AppendEpochAcceleratorRecord(
                                offsetsWriter1,
                                logStream1.Position - o + i + 2 /*first char after break*/);
                            if (i + 3 < o)
                            {
                                bool l2 = buffer[i + 2] == 'l' && buffer[i + 3] == '2';
                                level2[epochCount] = l2;
                                epochCount++;
                                if (l2)
                                {
                                    l2EpochCount++;
                                }
                            }
                            i++;
                        }
                        i++;
                    }

                    Array.Copy(buffer, o - Overlap, buffer, 0, Overlap);
                }

                finished.Set();
            }
コード例 #2
0
ファイル: Data.cs プロジェクト: programmatom/OutOfPhase
        public static Top Read(string logPath, Stream logStream)
        {
            TopProxy topProxy = new TopProxy();

            List <Definition> definitions = new List <Definition>();

            bool level2;
            long timerBasis;
            int  samplingRate;
            int  envelopeRate;
            int  concurrency;

            string acceleratorPath       = Accelerators.Schedule.QueryAcceleratorPath(logPath, logStream, AcceleratorVersion);
            string level2AcceleratorPath = Accelerators.Events.QueryAcceleratorPath(logPath, logStream, AcceleratorVersion);

            using (TextReader reader = new StreamReader2(logStream))
            {
                // always read header from log file

                string   line;
                string[] parts;

                line  = reader.ReadLine();
                parts = line.Split('\t');
                Debug.Assert(parts[0] == "version");
                int version = Int32.Parse(parts[1]);
                Debug.Assert(version == 1);

                line  = reader.ReadLine();
                parts = line.Split('\t');
                Debug.Assert(parts[0] == "level");
                level2 = Int64.Parse(parts[1]) > 1;

                line  = reader.ReadLine();
                parts = line.Split('\t');
                Debug.Assert(parts[0] == "tres");
                timerBasis = Int64.Parse(parts[1]);

                line  = reader.ReadLine();
                parts = line.Split('\t');
                Debug.Assert(parts[0] == "srate");
                samplingRate = Int32.Parse(parts[1]);

                line  = reader.ReadLine();
                parts = line.Split('\t');
                Debug.Assert(parts[0] == "erate");
                envelopeRate = Int32.Parse(parts[1]);

                line  = reader.ReadLine();
                parts = line.Split('\t');
                Debug.Assert(parts[0] == "threads");
                concurrency = Int32.Parse(parts[1]);

                line = reader.ReadLine();
                if (!String.Equals(line, ":"))
                {
                    Debug.Assert(false);
                }

                while (!String.IsNullOrEmpty(line = reader.ReadLine()))
                {
                    parts = line.Split('\t');
                    switch (parts[1])
                    {
                    default:
                        Debug.Assert(false);
                        throw new ArgumentException();

                    case "section":
                        definitions.Add(
                            new Definition(
                                topProxy,
                                Int32.Parse(parts[0]),
                                parts[2],
                                Kind.Effect,
                                -1));
                        break;

                    case "track":
                        definitions.Add(
                            new Definition(
                                topProxy,
                                Int32.Parse(parts[0]),
                                parts[3],
                                Kind.Track,
                                Int32.Parse(parts[2])));
                        break;
                    }
                }
            }

            // create offsets table for epoch records

            if (acceleratorPath == null)
            {
                acceleratorPath       = Path.GetTempFileName();
                level2AcceleratorPath = Path.GetTempFileName();

#if false
                long end = stream.Length;
                using (Stream acceleratorStream = new FileStream(acceleratorPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, Constants.BufferSize))
                {
                    using (BinaryWriter acceleratorWriter = new BinaryWriter(acceleratorStream, Encoding.UTF8))
                    {
                        while (((StreamReader2)reader).Position < end)
                        {
                            acceleratorWriter.Write((long)((StreamReader2)reader).Position);
                            EpochResident.Read(reader, topProxy, definitions.Count);
                        }
                    }
                }
#else
                using (Stream acceleratorStream = new FileStream(acceleratorPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, Constants.BufferSize))
                {
                    using (Stream level2Stream = new FileStream(level2AcceleratorPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, Constants.BufferSize))
                    {
                        FindBoundariesHelper.FindBoundaries(logPath, logStream, acceleratorStream, level2Stream);
                    }
                }
#endif

                Accelerators.Schedule.RecordAcceleratorPath(logPath, logStream, acceleratorPath, AcceleratorVersion);
                Accelerators.Events.RecordAcceleratorPath(logPath, logStream, level2AcceleratorPath, AcceleratorVersion);
            }

            Stream       acceleratorStream2 = new FileStream(acceleratorPath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.BufferSize);
            BinaryReader acceleratorReader2 = new BinaryReader(acceleratorStream2, Encoding.UTF8);
            BitVector    level2Bits;
            using (Stream level2Stream = new FileStream(level2AcceleratorPath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.BufferSize))
            {
                level2Bits = BitVector.Load(level2Stream);
            }

            IList <Epoch> epochs = new EpochVirtualList(
                topProxy,
                (int)(acceleratorStream2.Length / EpochVirtualList.OffsetRecordLength),
                level2Bits);
            //System.Windows.Forms.MessageBox.Show("Number of epochs: " + epochs.Count.ToString());

            Top top = new Top(
                logStream,
                level2,
                timerBasis,
                samplingRate,
                envelopeRate,
                concurrency,
                definitions,
                acceleratorStream2,
                acceleratorReader2,
                epochs);

            topProxy.Top = top;

            return(top);
        }