Exemple #1
0
 public EpochResident(
     TopProxy topProxy,
     long envelopeTick,
     long frameBase,
     int frameCount,
     long basis,
     long phase0Start,
     long phase1Start,
     long phase2Start,
     long phase3Start,
     bool level2,
     Datum[] data)
 {
     this.topProxy     = topProxy;
     this.envelopeTick = envelopeTick;
     this.frameBase    = frameBase;
     this.frameCount   = frameCount;
     this.phase0Start  = (int)(phase0Start - basis);
     this.phase1Start  = (int)(phase1Start - basis);
     this.phase2Start  = (int)(phase2Start - basis);
     this.phase3Start  = (int)(phase3Start - basis);
     this.basis        = basis;
     this.level2       = level2;
     this.data         = data;
 }
Exemple #2
0
        public static Definition ReadAccelerator(BinaryReader reader, TopProxy topProxy)
        {
            int    id        = reader.ReadInt32();
            string name      = reader.ReadString();
            Kind   kind      = (Kind)reader.ReadInt32();
            int    sectionId = reader.ReadInt32();

            return(new Definition(topProxy, id, name, kind, sectionId));
        }
Exemple #3
0
        public EpochVirtualList(
            TopProxy topProxy,
            int count,
            BitVector level2)
        {
            this.topProxy = topProxy;

            this.count  = count;
            this.level2 = level2;
        }
Exemple #4
0
        private readonly int sectionId; // valid only for Kind.Track

        public Definition(
            TopProxy topProxy,
            int id,
            string name,
            Kind kind,
            int sectionId)
        {
            this.topProxy = topProxy;
            if ((name.Length >= 2) && name.StartsWith("\"") && name.EndsWith("\""))
            {
                name        = name.Substring(1, name.Length - 2);
                this.quoted = true;
            }
            this.id        = id;
            this.name      = name;
            this.kind      = kind;
            this.sectionId = sectionId;
        }
Exemple #5
0
        public static EpochResident Read(TextReader reader, TopProxy topProxy, int count, bool level2)
        {
            string line;

            string[] parts;

            if (level2)
            {
                line = reader.ReadLine();
                if (!String.Equals(line, "l2"))
                {
                    level2 = false;
                    goto Skip;
                }
            }

            line = reader.ReadLine();
Skip:
            parts = line.Split('\t');
            Debug.Assert((parts[0] == "t") && (parts.Length == 2));
            long envelopeTick = Int64.Parse(parts[1]);

            line  = reader.ReadLine();
            parts = line.Split('\t');
            Debug.Assert((parts[0] == "b") && (parts.Length == 2));
            long basis = Int64.Parse(parts[1]);

            line  = reader.ReadLine();
            parts = line.Split('\t');
            Debug.Assert((parts[0] == "fr") && (parts.Length == 3));
            long frameBase  = Int64.Parse(parts[1]);
            int  frameCount = Int32.Parse(parts[2]);

            line  = reader.ReadLine();
            parts = line.Split('\t');
            Debug.Assert((parts[0] == "ph") && (parts.Length == 5));
            long phase0Start = Int64.Parse(parts[1]);
            long phase1Start = Int64.Parse(parts[2]);
            long phase2Start = Int64.Parse(parts[3]);
            long phase3Start = Int64.Parse(parts[4]);

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

            Datum[] data = Datum.ReadArray(reader, count, basis, level2);

            line = reader.ReadLine();
            Debug.Assert(String.IsNullOrEmpty(line));

            EpochResident epoch = new EpochResident(
                topProxy,
                envelopeTick,
                frameBase,
                frameCount,
                basis,
                phase0Start + basis,
                phase1Start + basis,
                phase2Start + basis,
                phase3Start + basis,
                level2,
                data);

            return(epoch);
        }
Exemple #6
0
 public EpochSecondaryStorage(TopProxy topProxy, long offset, bool level2)
 {
     this.topProxy = topProxy;
     this.offset   = offset;
     this.level2   = level2;
 }
Exemple #7
0
        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);
        }