Ejemplo n.º 1
0
 public Entry(EventDescription desc, long start, long finish) : base(start, finish)
 {
     this.Description = desc;
 }
Ejemplo n.º 2
0
        public static EventDescriptionBoard Read(DataResponse response)
        {
            BinaryReader reader = response.Reader;

            EventDescriptionBoard desc = new EventDescriptionBoard();

            desc.Response   = response;
            desc.BaseStream = reader.BaseStream;
            desc.ID         = reader.ReadInt32();

            desc.TimeSettings              = new TimeSettings();
            desc.TimeSettings.TicksToMs    = 1000.0 / (double)reader.ReadInt64();
            desc.TimeSettings.Origin       = reader.ReadInt64();
            desc.TimeSettings.PrecisionCut = reader.ReadInt32();
            Durable.InitSettings(desc.TimeSettings);

            desc.TimeSlice = new Durable();
            desc.TimeSlice.ReadDurable(reader);

            int threadCount = reader.ReadInt32();

            desc.Threads = new List <ThreadDescription>(threadCount);
            desc.ThreadID2ThreadIndex = new Dictionary <UInt64, int>();

            for (int i = 0; i < threadCount; ++i)
            {
                ThreadDescription threadDesc = ThreadDescription.Read(response);
                desc.Threads.Add(threadDesc);

                if (!desc.ThreadID2ThreadIndex.ContainsKey(threadDesc.ThreadID))
                {
                    desc.ThreadID2ThreadIndex.Add(threadDesc.ThreadID, i);
                }
                else
                {
                    // The old thread was finished and the new thread was started
                    // with the same threadID during one profiling session.
                    // Can't do much here - lets show information for the new thread only.
                    desc.ThreadID2ThreadIndex[threadDesc.ThreadID] = i;
                }
            }

            if (response.ApplicationID == NetworkProtocol.BROFILER_APP_ID)
            {
                int fibersCount = reader.ReadInt32();
                desc.Fibers = new List <FiberDescription>(fibersCount);
                for (int i = 0; i < fibersCount; ++i)
                {
                    FiberDescription fiberDesc = FiberDescription.Read(response);
                    desc.Fibers.Add(fiberDesc);
                }
            }

            desc.MainThreadIndex = reader.ReadInt32();

            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                desc.board.Add(EventDescription.Read(reader, i));
            }

            // TODO: Tags

            // TODO: Run Info

            // TODO: Run Info

            // TODO: Filters

            // TODO: Mode

            // TODO: Thread Descriptions

            return(desc);
        }
Ejemplo n.º 3
0
        public bool Init(String name, Stream stream)
        {
            Durable.InitSettings(Board.TimeSettings);

            String text = new StreamReader(stream).ReadToEnd();

            ChromeTrace trace = JsonConvert.DeserializeObject <ChromeTrace>(text);

            Dictionary <ulong, List <TraceEvent> > threads = new Dictionary <ulong, List <TraceEvent> >();

            foreach (TraceEvent ev in trace.traceEvents)
            {
                // Complete Event
                if (ev.ph == "X")
                {
                    List <TraceEvent> events = null;
                    if (!threads.TryGetValue(ev.tid, out events))
                    {
                        events = new List <TraceEvent>();
                        threads.Add(ev.tid, events);
                    }
                    events.Add(ev);
                }
            }

            Durable range = new Durable(long.MaxValue, long.MinValue);

            Dictionary <string, EventDescription> descriptions = new Dictionary <string, EventDescription>();

            foreach (KeyValuePair <ulong, List <TraceEvent> > pair in threads)
            {
                ulong             tid    = pair.Key;
                List <TraceEvent> events = pair.Value;

                List <Entry> entries = new List <Entry>(events.Count);
                List <Tag>   tags    = new List <Tag>(events.Count);

                foreach (TraceEvent ev in events)
                {
                    String args = ev.args != null?ev.args.ToString().Replace("\n", "").Replace("\r", "") : null;

                    String context   = GenerateShortContext(args);
                    String extraName = GenerateShortName(context);

                    String fullName = ev.name;
                    if (!String.IsNullOrWhiteSpace(extraName))
                    {
                        fullName = String.Format("{0} - {1}", ev.name, extraName);
                    }

                    EventDescription desc = null;
                    if (!descriptions.TryGetValue(fullName, out desc))
                    {
                        desc = new EventDescription(fullName)
                        {
                            Color = EventDescription.GenerateRandomColor(ev.name, RandomColorBrightnessVariance)
                        };
                        descriptions.Add(fullName, desc);
                    }

                    entries.Add(new Entry(desc, (long)ev.ts, (long)(ev.ts + ev.dur)));

                    if (!String.IsNullOrWhiteSpace(context))
                    {
                        tags.Add(new Tag()
                        {
                            Description = new EventDescription(context), Time = new Tick()
                            {
                                Start = (long)ev.ts
                            }
                        });
                    }
                }

                entries.Sort();
                tags.Sort();

                ThreadData threadData = MainGroup.AddThread(new ThreadDescription()
                {
                    Name = String.Format("Thread #{0}", tid), ThreadID = tid, ProcessID = 0, Origin = ThreadDescription.Source.Game
                });
                threadData.TagsPack = new TagsPack(tags);

                EventFrame frame = new EventFrame(new FrameHeader(new Durable(entries.Min(e => e.Start), entries.Max(e => e.Finish)), threadData.Description.ThreadIndex), entries, MainGroup);
                entries.ForEach(e => e.Frame = frame);

                range.Start  = Math.Min(range.Start, frame.Start);
                range.Finish = Math.Max(range.Finish, frame.Finish);

                threadData.Events.Add(frame);
            }

            Board.TimeSlice       = range;
            Board.MainThreadIndex = 0;
            MainFrame             = new EventFrame(new FrameHeader(Board.TimeSlice), new List <Entry> {
            }, MainGroup);

            return(true);
        }
Ejemplo n.º 4
0
        public static EventDescriptionBoard Read(DataResponse response)
        {
            BinaryReader reader = response.Reader;

            EventDescriptionBoard desc = new EventDescriptionBoard();

            desc.Response   = response;
            desc.BaseStream = reader.BaseStream;
            desc.ID         = reader.ReadInt32();

            desc.TimeSettings              = new TimeSettings();
            desc.TimeSettings.TicksToMs    = 1000.0 / (double)reader.ReadInt64();
            desc.TimeSettings.Origin       = reader.ReadInt64();
            desc.TimeSettings.PrecisionCut = reader.ReadInt32();
            Durable.InitSettings(desc.TimeSettings);

            desc.TimeSlice = new Durable();
            desc.TimeSlice.ReadDurable(reader);

            int threadCount = reader.ReadInt32();

            desc.Threads = new List <ThreadDescription>(threadCount);
            desc.ThreadID2ThreadIndex = new Dictionary <UInt64, int>();

            for (int i = 0; i < threadCount; ++i)
            {
                ThreadDescription threadDesc = ThreadDescription.Read(response);
                threadDesc.Origin      = ThreadDescription.Source.Game;
                threadDesc.ThreadIndex = i;
                desc.Threads.Add(threadDesc);

                if (!desc.ThreadID2ThreadIndex.ContainsKey(threadDesc.ThreadID))
                {
                    desc.ThreadID2ThreadIndex.Add(threadDesc.ThreadID, i);
                    desc.ThreadDescriptions.Add(threadDesc.ThreadID, threadDesc);
                }
                else
                {
                    // The old thread was finished and the new thread was started
                    // with the same threadID during one profiling session.
                    // Can't do much here - lets show information for the new thread only.
                    desc.ThreadID2ThreadIndex[threadDesc.ThreadID] = i;
                }
            }

            if (response.ApplicationID == NetworkProtocol.OPTICK_APP_ID)
            {
                int fibersCount = reader.ReadInt32();
                desc.Fibers = new List <FiberDescription>(fibersCount);
                for (int i = 0; i < fibersCount; ++i)
                {
                    FiberDescription fiberDesc = FiberDescription.Read(response);
                    desc.Fibers.Add(fiberDesc);
                }
            }

            desc.MainThreadIndex = reader.ReadInt32();

            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                desc.board.Add(EventDescription.Read(reader, i));
            }

            // TODO: Tags
            reader.ReadUInt32();

            // TODO: Run Info
            reader.ReadUInt32();

            // TODO: Run Info
            reader.ReadUInt32();

            // TODO: Filters
            reader.ReadUInt32();

            // TODO: Mode
            desc.Mode = reader.ReadUInt32();

            // TODO: Thread Descriptions
            int processDescCount = reader.ReadInt32();

            for (int i = 0; i < processDescCount; ++i)
            {
                ProcessDescription process = ProcessDescription.Read(response);
                if (!desc.ProcessDescritpions.ContainsKey(process.ProcessID))
                {
                    desc.ProcessDescritpions.Add(process.ProcessID, process);
                }
            }

            int threadDescCount = reader.ReadInt32();

            for (int i = 0; i < threadDescCount; ++i)
            {
                ThreadDescription thread = ThreadDescription.Read(response);
                thread.Origin = ThreadDescription.Source.GameAuto;
                if (!desc.ThreadDescriptions.ContainsKey(thread.ThreadID))
                {
                    desc.ThreadDescriptions.Add(thread.ThreadID, thread);
                }
                //else if (!String.IsNullOrEmpty(thread.Name))
                //	desc.ThreadDescriptions[thread.ThreadID] = thread;

                ProcessDescription process = null;
                if (desc.ProcessDescritpions.TryGetValue(thread.ProcessID, out process))
                {
                    thread.Process = process;
                }
            }

            desc.ProcessID    = response.Reader.ReadInt32();
            desc.CPUCoreCount = response.Reader.ReadInt32();

            return(desc);
        }
Ejemplo n.º 5
0
 public FunctionStats(FrameGroup group, EventDescription desc)
 {
     Group       = group;
     Description = desc;
 }