Exemplo n.º 1
0
        public SynchronizationMap(DataResponse response, FrameGroup group)
        {
            Response = response;
            SyncMap  = new Dictionary <UInt64, Synchronization>();

            int count = response.Reader.ReadInt32();
            List <SyncEvent> events = new List <SyncEvent>(count);

            for (int i = 0; i < count; ++i)
            {
                events.Add(new SyncEvent(response.Reader));
            }

            events.Sort();

            for (int i = 0; i < count; ++i)
            {
                SyncEvent scEvent = events[i];

                if (scEvent.OldThreadID != 0)
                {
                    Synchronization oldSync = null;
                    if (!SyncMap.TryGetValue(scEvent.OldThreadID, out oldSync))
                    {
                        oldSync = new Synchronization();
                        SyncMap.Add(scEvent.OldThreadID, oldSync);
                    }

                    if (oldSync.Count > 0)
                    {
                        SyncInterval interval = oldSync[oldSync.Count - 1];
                        interval.Reason      = scEvent.Reason;
                        interval.Finish      = scEvent.Timestamp.Start;
                        interval.NewThreadId = scEvent.NewThreadID;
                    }
                }

                if (scEvent.NewThreadID != 0)
                {
                    Synchronization newSync = null;
                    if (!SyncMap.TryGetValue(scEvent.NewThreadID, out newSync))
                    {
                        newSync = new Synchronization();
                        SyncMap.Add(scEvent.NewThreadID, newSync);
                    }

                    SyncInterval data = new SyncInterval()
                    {
                        Start  = scEvent.Timestamp.Start,
                        Finish = long.MaxValue,
                        Core   = scEvent.CPUID,
                    };

                    while (newSync.Count > 0)
                    {
                        SyncInterval previous = newSync[newSync.Count - 1];
                        if (previous.Finish <= data.Start)
                        {
                            break;
                        }

                        newSync.RemoveAt(newSync.Count - 1);
                    }

                    newSync.Add(data);
                }
            }
        }
Exemplo n.º 2
0
        public void Load(List <SyncEvent> events)
        {
            Events = events;

            SyncMap = new Dictionary <UInt64, Synchronization>();

            for (int i = 0; i < events.Count; ++i)
            {
                SyncEvent scEvent = events[i];

                if (scEvent.OldThreadID != 0)
                {
                    Synchronization oldSync = null;
                    if (!SyncMap.TryGetValue(scEvent.OldThreadID, out oldSync))
                    {
                        oldSync = new Synchronization();
                        SyncMap.Add(scEvent.OldThreadID, oldSync);
                    }

                    if (oldSync.Count > 0)
                    {
                        SyncInterval interval = oldSync[oldSync.Count - 1];
                        interval.Reason      = scEvent.Reason;
                        interval.Finish      = scEvent.Timestamp.Start;
                        interval.NewThreadId = scEvent.NewThreadID;
                    }
                }

                if (scEvent.NewThreadID != 0)
                {
                    Synchronization newSync = null;
                    if (!SyncMap.TryGetValue(scEvent.NewThreadID, out newSync))
                    {
                        newSync = new Synchronization();
                        SyncMap.Add(scEvent.NewThreadID, newSync);
                    }

                    SyncInterval data = new SyncInterval()
                    {
                        Start  = scEvent.Timestamp.Start,
                        Finish = long.MaxValue,
                        Core   = scEvent.CPUID,
                    };

                    while (newSync.Count > 0)
                    {
                        SyncInterval previous = newSync[newSync.Count - 1];
                        if (previous.Finish <= data.Start)
                        {
                            break;
                        }

                        newSync.RemoveAt(newSync.Count - 1);
                    }

                    newSync.Add(data);
                }
            }

#if DEBUG
            foreach (Synchronization sync in SyncMap.Values)
            {
                for (int i = 0; i < sync.Count - 1; ++i)
                {
                    Debug.Assert(sync[i].IsValid, "Invalid data!");
                    Debug.Assert(sync[i].Finish <= sync[i + 1].Start, "Not sorted!");
                }
            }
#endif
        }