internal void HandleEventDataSetCreation(DiagnosticEvent evt)
        {
            var ds = new EventDataSet(evt);

            m_DataSets.Add(evt.ObjectId, ds);
            if (evt.Dependencies != null)
            {
                foreach (var d in evt.Dependencies)
                {
                    EventDataSet depDS;
                    if (m_DataSets.TryGetValue(d, out depDS))
                    {
                        ds.AddChild(depDS);
                        HashSet <int> depParents = null;
                        if (!m_objectToParents.TryGetValue(d, out depParents))
                        {
                            RootStreamEntry.RemoveChild(d);
                            m_objectToParents.Add(d, depParents = new HashSet <int>());
                        }
                        depParents.Add(evt.ObjectId);
                    }
                }
            }

            if (!m_objectToParents.ContainsKey(evt.ObjectId))
            {
                RootStreamEntry.AddChild(ds);
            }
        }
        internal int CompareTo(EventDataSet other)
        {
            var x = m_SortOrder < 0 ? m_SortOrder : FirstSampleFrame;
            var y = other.m_SortOrder < 0 ? other.m_SortOrder : other.FirstSampleFrame;

            return(x - y);
        }
Exemple #3
0
 internal void AddChild(EventDataSet eventDataSet)
 {
     if (m_Children == null)
     {
         m_Children = new Dictionary <int, EventDataSet>();
     }
     m_Children.Add(eventDataSet.ObjectId, eventDataSet);
 }
 internal void HandleInstantiationEvent(DiagnosticEvent evt)
 {
     if (m_InstantitationCountDataSet == null)
     {
         m_InstantitationCountDataSet = new EventDataSet(1, "InstantiationCount", "Instantiation Counts", EventDataSet.k_InstanceCountSortOrder);
         RootStreamEntry.AddChild(m_InstantitationCountDataSet);
     }
     m_LastInstantiationFrame = evt.Frame;
     m_LastFrameInstantiationCount++;
 }
 internal void Clear()
 {
     RootStreamEntry.Clear();
     m_FrameEvents.Clear();
     m_LastFrameWithEvents         = -1;
     m_LastFrameInstantiationCount = 0;
     m_EventCountDataSet           = null;
     m_InstantitationCountDataSet  = null;
     m_DataSets.Clear();
     m_objectToParents.Clear();
 }
        internal void HandleRecordedEvent(DiagnosticEvent evt)
        {
            List <DiagnosticEvent> frameEvents;

            if (!m_FrameEvents.TryGetValue(evt.Frame, out frameEvents))
            {
                if (m_EventCountDataSet == null)
                {
                    m_EventCountDataSet = new EventDataSet(0, "EventCount", "Event Counts", EventDataSet.k_EventCountSortOrder);
                    RootStreamEntry.AddChild(m_EventCountDataSet);
                }
                m_LastFrameWithEvents = evt.Frame;
                m_FrameEvents.Add(evt.Frame, frameEvents = new List <DiagnosticEvent>());
            }
            frameEvents.Add(evt);
        }
        internal void AddSample(DiagnosticEvent evt, bool recordEvent, ref bool entryCreated)
        {
            m_LatestFrame = evt.Frame;
            m_StartFrame  = m_LatestFrame - m_FrameCount;
            entryCreated  = false;

            bool countedAllRecordedEventsOnCurrentFrame = evt.Frame > m_LastFrameWithEvents &&
                                                          m_LastFrameWithEvents >= 0 &&
                                                          m_FrameEvents[m_LastFrameWithEvents] != null &&
                                                          m_FrameEvents[m_LastFrameWithEvents].Count > 0 &&
                                                          m_EventCountDataSet != null;

            //once all recorded events on a given frame have been logged in m_FrameEvents, create a sample for alevents
            if (countedAllRecordedEventsOnCurrentFrame)
            {
                m_EventCountDataSet.AddSample(0, m_LastFrameWithEvents, m_FrameEvents[m_LastFrameWithEvents].Count);
            }

            // Registers events under "Event Counts" (excluding instantiations)
            if (recordEvent && !evt.DisplayName.StartsWith("Instance"))
            {
                HandleRecordedEvent(evt);
            }

            bool countedAllInstantiationEventsOnCurrentFrame = evt.Frame > m_LastInstantiationFrame &&
                                                               m_LastInstantiationFrame >= 0 &&
                                                               m_LastFrameInstantiationCount > 0 &&
                                                               m_InstantitationCountDataSet != null;

            if (countedAllInstantiationEventsOnCurrentFrame)
            {
                m_InstantitationCountDataSet.AddSample(0, m_LastInstantiationFrame, m_LastFrameInstantiationCount);
                m_LastFrameInstantiationCount = 0;
            }

            if (evt.DisplayName.StartsWith("Instance"))
            {
                if ((ResourceManager.DiagnosticEventType)evt.Stream == ResourceManager.DiagnosticEventType.AsyncOperationCreate)
                {
                    HandleInstantiationEvent(evt);
                }
                return;
            }

            //if creation event, create a data set and update all dependecies
            if (!m_DataSets.ContainsKey(evt.ObjectId))
            {
                HandleEventDataSetCreation(evt);
                entryCreated = true;
            }

            EventDataSet data = null;

            if (m_DataSets.TryGetValue(evt.ObjectId, out data))
            {
                data.AddSample(evt.Stream, evt.Frame, evt.Value);
            }

            if ((ResourceManager.DiagnosticEventType)evt.Stream == ResourceManager.DiagnosticEventType.AsyncOperationDestroy)
            {
                m_Queue.Add(new EvtQueueData {
                    Event = evt, DestroyFrame = evt.Frame
                });
            }
        }
        internal void AddSample(DiagnosticEvent evt, bool recordEvent, ref bool entryCreated)
        {
            m_LatestFrame = evt.Frame;
            m_StartFrame  = m_LatestFrame - m_FrameCount;

            if (recordEvent && !evt.DisplayName.StartsWith("Instance"))
            {
                List <DiagnosticEvent> frameEvents;
                if (!m_FrameEvents.TryGetValue(evt.Frame, out frameEvents))
                {
                    if (lastFrameWithEvents >= 0)
                    {
                        if (m_eventCountDataSet == null)
                        {
                            m_eventCountDataSet = new EventDataSet(0, "EventCount", "Event Counts");
                            RootStreamEntry.AddChild(m_eventCountDataSet);
                        }
                        m_eventCountDataSet.AddSample(0, lastFrameWithEvents, m_FrameEvents[lastFrameWithEvents].Count);
                    }
                    lastFrameWithEvents = evt.Frame;
                    m_FrameEvents.Add(evt.Frame, frameEvents = new List <DiagnosticEvent>());
                }
                frameEvents.Add(evt);
            }

            if (evt.DisplayName.StartsWith("Instance"))
            {
                if (evt.Stream == (int)ResourceManager.DiagnosticEventType.AsyncOperationCreate)
                {
                    if (evt.Frame != lastInstantiationCountFrame)
                    {
                        if (lastInstantiationCountFrame >= 0 && lastInstantiationCountValue > 0)
                        {
                            if (m_instantitationCountDataSet == null)
                            {
                                m_instantitationCountDataSet = new EventDataSet(1, "InstantiationCount", "Instantiation Counts");
                                RootStreamEntry.AddChild(m_instantitationCountDataSet);
                            }
                            m_instantitationCountDataSet.AddSample(0, lastInstantiationCountFrame, lastInstantiationCountValue);
                        }
                        lastInstantiationCountFrame = evt.Frame;
                        lastInstantiationCountValue = 0;
                    }
                    lastInstantiationCountValue++;
                }
                return;
            }

/*
 *          if (evt.Stream == (int)ResourceManager.DiagnosticEventType.AsyncOperationDisplayName)
 *          {
 *              EventDataSet ds;
 *              if(m_dataSets.TryGetValue(evt.ObjectId, out ds))
 *                  ds.DisplayName = evt.DisplayName;
 *          }
 */
            //if creation event, create a data set and update all dependecies
            if (!m_dataSets.ContainsKey(evt.ObjectId))
            {
                var ds = new EventDataSet(evt);
                m_dataSets.Add(evt.ObjectId, ds);
                if (evt.Dependencies != null)
                {
                    foreach (var d in evt.Dependencies)
                    {
                        EventDataSet depDS;
                        if (m_dataSets.TryGetValue(d, out depDS))
                        {
                            ds.AddChild(depDS);
                            HashSet <int> depParents = null;
                            if (!m_objectToParents.TryGetValue(d, out depParents))
                            {
                                RootStreamEntry.RemoveChild(d);
                                m_objectToParents.Add(d, depParents = new HashSet <int>());
                            }
                            depParents.Add(evt.ObjectId);
                        }
                    }
                }
                if (!m_objectToParents.ContainsKey(evt.ObjectId))
                {
                    RootStreamEntry.AddChild(ds);
                }
            }


            EventDataSet data = null;

            if (m_dataSets.TryGetValue(evt.ObjectId, out data))
            {
                data.AddSample(evt.Stream, evt.Frame, evt.Value);
            }

            if (evt.Stream == (int)ResourceManager.DiagnosticEventType.AsyncOperationDestroy)
            {
                if (evt.Dependencies != null)
                {
                    foreach (var d in evt.Dependencies)
                    {
                        HashSet <int> depParents = null;
                        if (m_objectToParents.TryGetValue(d, out depParents))
                        {
                            depParents.Remove(evt.ObjectId);
                            if (depParents.Count == 0)
                            {
                                m_objectToParents.Remove(d);
                                RootStreamEntry.AddChild(m_dataSets[d]);
                            }
                        }
                    }
                }
                m_dataSets.Remove(evt.ObjectId);

                HashSet <int> parents = null;
                if (m_objectToParents.TryGetValue(evt.ObjectId, out parents))
                {
                    foreach (var p in parents)
                    {
                        EventDataSet pp;
                        if (m_dataSets.TryGetValue(p, out pp))
                        {
                            pp.RemoveChild(evt.ObjectId);
                        }
                    }
                }
                else
                {
                    RootStreamEntry.RemoveChild(evt.ObjectId);
                }
            }
        }