Ejemplo n.º 1
0
        void UpdateIfNeeded(FrameDataView frameDataView, int selectedId)
        {
            var needReload = m_SelectedID != selectedId || !Equals(m_FrameDataView, frameDataView);

            if (!needReload)
            {
                return;
            }

            m_FrameDataView = frameDataView;
            m_SelectedID    = selectedId;

            callersAndCalleeData.UpdateData(m_FrameDataView, m_FrameDataView.GetItemMarkerID(m_SelectedID));

            m_CallersTreeView.SetCallsData(callersAndCalleeData.callersData);
            m_CalleesTreeView.SetCallsData(callersAndCalleeData.calleesData);

            m_TotalSelectedPropertyTimeLabel.text = m_FrameDataView.GetItemFunctionName(selectedId) + string.Format(" - Total time: {0:f2} ms", callersAndCalleeData.totalSelectedPropertyTime);
        }
        void UpdateIfNeeded(FrameDataView frameDataView, int selectedId)
        {
            var needReload = m_SelectedID != selectedId || !Equals(m_FrameDataView, frameDataView);

            if (!needReload)
            {
                return;
            }

            m_FrameDataView = frameDataView;
            m_SelectedID    = selectedId;

            m_TotalSelectedPropertyTime = 0;

            var selectedMarkerId = m_FrameDataView.GetItemMarkerID(m_SelectedID);

            var callers = new Dictionary <int, CallInformation>();
            var callees = new Dictionary <int, CallInformation>();

            var childrenIds = new List <int>(256);
            var stack       = new Stack <int>();

            stack.Push(m_FrameDataView.GetRootItemID());

            while (stack.Count > 0)
            {
                var current = stack.Pop();

                if (m_FrameDataView.HasItemChildren(current))
                {
                    continue;
                }

                var markerId = m_FrameDataView.GetItemMarkerID(current);
                m_FrameDataView.GetItemChildren(current, childrenIds);
                foreach (var childId in childrenIds)
                {
                    var childMarkerId = m_FrameDataView.GetItemMarkerID(childId);
                    if (childMarkerId == selectedMarkerId)
                    {
                        var totalSelfTime = m_FrameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.TotalTime);
                        m_TotalSelectedPropertyTime += totalSelfTime;

                        if (current != 0)
                        {
                            // Add markerId to callers (except root)
                            CallInformation callInfo;
                            var             totalTime = m_FrameDataView.GetItemColumnDataAsSingle(current, ProfilerColumn.TotalTime);
                            var             calls     = (int)m_FrameDataView.GetItemColumnDataAsSingle(current, ProfilerColumn.Calls);
                            var             gcAlloc   = (int)m_FrameDataView.GetItemColumnDataAsSingle(current, ProfilerColumn.GCMemory);
                            if (!callers.TryGetValue(markerId, out callInfo))
                            {
                                callers.Add(markerId, new CallInformation()
                                {
                                    id              = current,
                                    name            = m_FrameDataView.GetItemFunctionName(current),
                                    callsCount      = calls,
                                    gcAllocBytes    = gcAlloc,
                                    totalCallTimeMs = totalTime,
                                    totalSelfTimeMs = totalSelfTime
                                });
                            }
                            else
                            {
                                callInfo.callsCount      += calls;
                                callInfo.gcAllocBytes    += gcAlloc;
                                callInfo.totalCallTimeMs += totalTime;
                                callInfo.totalSelfTimeMs += totalSelfTime;
                            }
                        }
                    }

                    if (markerId == selectedMarkerId)
                    {
                        // Add childMarkerId to callees
                        CallInformation callInfo;
                        var             totalTime = m_FrameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.TotalTime);
                        var             calls     = (int)m_FrameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.Calls);
                        var             gcAlloc   = (int)m_FrameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.GCMemory);
                        if (!callees.TryGetValue(childMarkerId, out callInfo))
                        {
                            callees.Add(childMarkerId, new CallInformation()
                            {
                                id              = childId,
                                name            = m_FrameDataView.GetItemFunctionName(childId),
                                callsCount      = calls,
                                gcAllocBytes    = gcAlloc,
                                totalCallTimeMs = totalTime,
                                totalSelfTimeMs = 0
                            });
                        }
                        else
                        {
                            callInfo.callsCount      += calls;
                            callInfo.gcAllocBytes    += gcAlloc;
                            callInfo.totalCallTimeMs += totalTime;
                        }
                    }

                    stack.Push(childId);
                }
            }

            m_CallersTreeView.SetCallsData(new CallsData()
            {
                calls = callers.Values.ToList(), totalSelectedPropertyTime = m_TotalSelectedPropertyTime
            });
            m_CalleesTreeView.SetCallsData(new CallsData()
            {
                calls = callees.Values.ToList(), totalSelectedPropertyTime = m_TotalSelectedPropertyTime
            });

            m_TotalSelectedPropertyTimeLabel.text = m_FrameDataView.GetItemFunctionName(selectedId) + string.Format(" - Total time: {0:f2} ms", m_TotalSelectedPropertyTime);
        }
Ejemplo n.º 3
0
        internal float UpdateData(FrameDataView frameDataView, int selectedMarkerId)
        {
            totalSelectedPropertyTime = 0;

            m_Callers.Clear();
            m_Callees.Clear();

            m_ChildrenIds.Clear();
            m_Stack.Clear();
            m_Stack.Push(frameDataView.GetRootItemID());

            while (m_Stack.Count > 0)
            {
                var current = m_Stack.Pop();

                if (!frameDataView.HasItemChildren(current))
                {
                    continue;
                }

                var markerId = frameDataView.GetItemMarkerID(current);
                frameDataView.GetItemChildren(current, m_ChildrenIds);
                foreach (var childId in m_ChildrenIds)
                {
                    var childMarkerId = frameDataView.GetItemMarkerID(childId);
                    if (childMarkerId == selectedMarkerId)
                    {
                        var totalSelfTime = frameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.TotalTime);
                        totalSelectedPropertyTime += totalSelfTime;

                        if (current != 0)
                        {
                            // Add markerId to callers (except root)
                            CallInformation callInfo;
                            var             totalTime = frameDataView.GetItemColumnDataAsSingle(current, ProfilerColumn.TotalTime);
                            var             calls     = (int)frameDataView.GetItemColumnDataAsSingle(current, ProfilerColumn.Calls);
                            var             gcAlloc   = (int)frameDataView.GetItemColumnDataAsSingle(current, ProfilerColumn.GCMemory);
                            if (!m_Callers.TryGetValue(markerId, out callInfo))
                            {
                                m_Callers.Add(markerId, new CallInformation()
                                {
                                    id              = current,
                                    name            = frameDataView.GetItemFunctionName(current),
                                    callsCount      = calls,
                                    gcAllocBytes    = gcAlloc,
                                    totalCallTimeMs = totalTime,
                                    totalSelfTimeMs = totalSelfTime
                                });
                            }
                            else
                            {
                                callInfo.callsCount      += calls;
                                callInfo.gcAllocBytes    += gcAlloc;
                                callInfo.totalCallTimeMs += totalTime;
                                callInfo.totalSelfTimeMs += totalSelfTime;
                            }
                        }
                    }

                    if (markerId == selectedMarkerId)
                    {
                        // Add childMarkerId to callees
                        CallInformation callInfo;
                        var             totalTime = frameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.TotalTime);
                        var             calls     = (int)frameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.Calls);
                        var             gcAlloc   = (int)frameDataView.GetItemColumnDataAsSingle(childId, ProfilerColumn.GCMemory);
                        if (!m_Callees.TryGetValue(childMarkerId, out callInfo))
                        {
                            m_Callees.Add(childMarkerId, new CallInformation()
                            {
                                id              = childId,
                                name            = frameDataView.GetItemFunctionName(childId),
                                callsCount      = calls,
                                gcAllocBytes    = gcAlloc,
                                totalCallTimeMs = totalTime,
                                totalSelfTimeMs = 0
                            });
                        }
                        else
                        {
                            callInfo.callsCount      += calls;
                            callInfo.gcAllocBytes    += gcAlloc;
                            callInfo.totalCallTimeMs += totalTime;
                        }
                    }

                    m_Stack.Push(childId);
                }
            }
            UpdateCallsData(ref m_CallersData, m_Callers, totalSelectedPropertyTime);
            UpdateCallsData(ref m_CalleesData, m_Callees, totalSelectedPropertyTime);
            return(totalSelectedPropertyTime);
        }