public string GetItemName(HierarchyFrameDataView frameData, int itemId)
        {
            var name = frameData.GetItemName(itemId);

            if ((ViewOptions & ProfilerViewFilteringOptions.ShowFullScriptingMethodNames) != 0)
            {
                return(name);
            }

            var flags = frameData.GetItemMarkerFlags(itemId);

            if (((int)flags & k_AnyFullManagedMarker) == 0)
            {
                return(name);
            }

            var namespaceDelimiterIndex = name.IndexOf(':');

            if (namespaceDelimiterIndex == -1)
            {
                return(name);
            }
            ++namespaceDelimiterIndex;
            if (namespaceDelimiterIndex < name.Length && name[namespaceDelimiterIndex] == ':')
            {
                return(name.Substring(namespaceDelimiterIndex + 1));
            }

            return(name);
        }
        void UpdateIfNeeded(HierarchyFrameDataView 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.GetItemName(selectedId) + UnityString.Format(" - Total time: {0:f2} ms", callersAndCalleeData.totalSelectedPropertyTime);
        }
Exemplo n.º 3
0
    private static int GetItemIdMatchingRecursive(HierarchyFrameDataView frameData, int itemId, Func <string, bool> predicate)
    {
        string searchString = "";

        var functionName = frameData.GetItemName(itemId);

        searchString += functionName;
        var goInstanceId = frameData.GetItemInstanceID(itemId);

        if (goInstanceId > 0)
        {
            var go       = EditorUtility.InstanceIDToObject(goInstanceId);
            var typeName = go.GetType().Name;
            searchString += $" - {go.name} ({typeName})";
        }

        var isMatch = predicate(searchString);

        if (isMatch)
        {
            return(itemId);
        }
        else
        {
            var itemChildrenIds = new List <int>();
            frameData.GetItemChildren(itemId, itemChildrenIds);
            foreach (var childId in itemChildrenIds)
            {
                var foundId = GetItemIdMatchingRecursive(frameData, childId, predicate);
                if (foundId != -1)
                {
                    return(foundId);
                }
            }
        }

        return(-1);
    }
Exemplo n.º 4
0
    private void ShowFoundItemInProfiler(HierarchyFrameDataView frameData, int matchingItemId, int frameIndex)
    {
        var goInstanceId = frameData.GetItemInstanceID(matchingItemId);
        var foundObject  = EditorUtility.InstanceIDToObject(goInstanceId);

        //Selection.activeObject = foundObject;
        EditorGUIUtility.PingObject(foundObject);

        var profilerWindowInterface = new ProfilerWindowInterface();

        profilerWindowInterface.OpenProfilerOrUseExisting();
        profilerWindowInterface.JumpToFrame(frameIndex + 1);

        var markerName = frameData.GetItemName(matchingItemId);

        profilerWindowInterface.SetProfilerWindowMarkerName(markerName, new List <string>()
        {
            LookInThread
        });

        ProfilerDriver.enabled     = false;
        EditorApplication.isPaused = true;
    }
        internal float UpdateData(HierarchyFrameDataView 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, HierarchyFrameDataView.columnTotalTime);
                        totalSelectedPropertyTime += totalSelfTime;

                        if (current != 0)
                        {
                            // Add markerId to callers (except root)
                            CallInformation callInfo;
                            var             totalTime = frameDataView.GetItemColumnDataAsSingle(current, HierarchyFrameDataView.columnTotalTime);
                            var             calls     = (int)frameDataView.GetItemColumnDataAsSingle(current, HierarchyFrameDataView.columnCalls);
                            var             gcAlloc   = (int)frameDataView.GetItemColumnDataAsSingle(current, HierarchyFrameDataView.columnGcMemory);
                            if (!m_Callers.TryGetValue(markerId, out callInfo))
                            {
                                m_Callers.Add(markerId, new CallInformation()
                                {
                                    id              = current,
                                    name            = frameDataView.GetItemName(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, HierarchyFrameDataView.columnTotalTime);
                        var             calls     = (int)frameDataView.GetItemColumnDataAsSingle(childId, HierarchyFrameDataView.columnCalls);
                        var             gcAlloc   = (int)frameDataView.GetItemColumnDataAsSingle(childId, HierarchyFrameDataView.columnGcMemory);
                        if (!m_Callees.TryGetValue(childMarkerId, out callInfo))
                        {
                            m_Callees.Add(childMarkerId, new CallInformation()
                            {
                                id              = childId,
                                name            = frameDataView.GetItemName(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);
        }
Exemplo n.º 6
0
        void MigrateSelectedState(bool expandIfNecessary)
        {
            if (m_SelectedItemMarkerIdPath == null && m_LegacySelectedItemMarkerNamePath == null)
            {
                return;
            }

            // Find view id which corresponds to markerPath
            var  newSelectedId = m_FrameDataView.GetRootItemID();
            bool selectedItemsPathIsExpanded = true;

            if (m_SelectedItemMarkerIdPath != null)
            {
                foreach (var marker in m_SelectedItemMarkerIdPath)
                {
                    if (m_FrameDataView.HasItemChildren(newSelectedId))
                    {
                        m_FrameDataView.GetItemChildren(newSelectedId, m_ReusableChildrenIds);
                        foreach (var childId in m_ReusableChildrenIds)
                        {
                            if (marker == m_FrameDataView.GetItemMarkerID(childId))
                            {
                                // check if the parent is expanded
                                if (!IsExpanded(newSelectedId))
                                {
                                    selectedItemsPathIsExpanded = false;
                                }

                                newSelectedId = childId;
                                break;
                            }
                        }
                    }

                    if (newSelectedId == 0)
                    {
                        break;
                    }
                }
            }
            else if (m_LegacySelectedItemMarkerNamePath != null)
            {
                var markerIdPath = new List <int>();
                var markerNames  = m_LegacySelectedItemMarkerNamePath.Split('/');
                foreach (var markerName in markerNames)
                {
                    if (m_FrameDataView.HasItemChildren(newSelectedId))
                    {
                        m_FrameDataView.GetItemChildren(newSelectedId, m_ReusableChildrenIds);
                        foreach (var childId in m_ReusableChildrenIds)
                        {
                            if (markerName == m_FrameDataView.GetItemName(childId))
                            {
                                // check if the parent is expanded
                                if (!IsExpanded(newSelectedId))
                                {
                                    selectedItemsPathIsExpanded = false;
                                }

                                newSelectedId = childId;
                                markerIdPath.Add(m_FrameDataView.GetItemMarkerID(childId));
                                break;
                            }
                        }
                    }

                    if (newSelectedId == 0)
                    {
                        break;
                    }
                }

                m_SelectedItemMarkerIdPath         = markerIdPath;
                m_LegacySelectedItemMarkerNamePath = null;
            }

            var newSelection = (newSelectedId == 0) ? new List <int>() : new List <int>()
            {
                newSelectedId
            };

            state.selectedIDs = newSelection;

            // Framing invalidates expanded state and this is very expensive operation to perform each frame.
            // Thus we auto frame selection only when we are not profiling.
            var collectingSamples = ProfilerDriver.enabled && (ProfilerDriver.profileEditor || EditorApplication.isPlaying);
            var isFramingAllowed  = !collectingSamples;

            if (newSelectedId != 0 && isInitialized && isFramingAllowed && (selectedItemsPathIsExpanded || expandIfNecessary))
            {
                FrameItem(newSelectedId);
            }
        }
Exemplo n.º 7
0
        void UpdateIfNeeded(HierarchyFrameDataView frameDataView, int selectedId)
        {
            var needReload = m_SelectedID != selectedId || !Equals(m_FrameDataView, frameDataView);

            if (!needReload)
            {
                return;
            }

            m_FrameDataView = frameDataView;
            m_SelectedID    = selectedId;
            m_TreeView.SetSelection(new List <int>());

            var samplesCount = m_FrameDataView.GetItemMergedSamplesCount(selectedId);

            // Collect all the data
            var instanceIDs = new List <int>(samplesCount);

            m_FrameDataView.GetItemMergedSamplesInstanceID(selectedId, instanceIDs);

            var columns           = m_MultiColumnHeader.columns;
            var columnsCount      = columns.Length;
            var objectsDatas      = new List <string> [columnsCount];
            var objectsValueDatas = new List <float> [columnsCount];

            for (var i = 0; i < columnsCount; i++)
            {
                objectsDatas[i] = new List <string>(samplesCount);
                m_FrameDataView.GetItemMergedSamplesColumnData(selectedId, columns[i].profilerColumn, objectsDatas[i]);

                objectsValueDatas[i] = new List <float>(samplesCount);
                m_FrameDataView.GetItemMergedSamplesColumnDataAsFloats(selectedId, columns[i].profilerColumn, objectsValueDatas[i]);
            }

            // Store it per sample
            var objectsData = new List <ObjectInformation>();

            for (var i = 0; i < samplesCount; i++)
            {
                var objData = new ObjectInformation()
                {
                    columnStrings = new string[columnsCount], columnValues = new float[columnsCount]
                };
                objData.id          = selectedId;
                objData.sampleIndex = i;

                objData.instanceId = (i < instanceIDs.Count) ? instanceIDs[i] : 0;
                for (var j = 0; j < columnsCount; j++)
                {
                    objData.columnStrings[j] = (i < objectsDatas[j].Count) ? objectsDatas[j][i] : string.Empty;
                    objData.columnValues[j]  = (i < objectsValueDatas[j].Count) ? objectsValueDatas[j][i] : 0.0f;
                }

                objectsData.Add(objData);
            }

            m_TreeView.SetData(objectsData);

            // Update instances label
            var sampleName = m_FrameDataView.GetItemName(selectedId);

            m_InstancesLabel.text    = UnityString.Format(kInstancesCountFormatText, samplesCount, sampleName);
            m_InstancesLabel.tooltip = kInstancesCountTooltipText;
        }