void UpdateObjectRow(RawFrameDataView data, ref ObjectTableRow row, string countMarkerName, string sizeMarkerName = null) { row.Count.text = data.GetCounterValueAsLong(data.GetMarkerId(countMarkerName)).ToString(); if (!string.IsNullOrEmpty(sizeMarkerName)) { row.Size.text = EditorUtility.FormatBytes(data.GetCounterValueAsLong(data.GetMarkerId(sizeMarkerName))); } }
private static void GetMarkerIDs(RawFrameDataView frameData, Dictionary <string, FileAccessMarkerInfo> markers, ref Dictionary <string, int> markerToIDMap) { s_GetMarkerIDs.Begin(); // iterate over the markers we want to get their markerIDs foreach (var markerName in markers.Keys) { // this markerID can change for the same marker so have to do for each frame markerToIDMap[markerName] = frameData.GetMarkerId(markerName); } s_GetMarkerIDs.End(); }
int FindFirstMatchingRawSampleIndexInScopeRecursively(RawFrameDataView frameData, ref List <int> sampleIndexPath, string sampleName, int sampleMarkerId = FrameDataView.invalidMarkerId) { if (sampleMarkerId == FrameDataView.invalidMarkerId) { sampleMarkerId = frameData.GetMarkerId(sampleName); } var firstIndex = sampleIndexPath != null && sampleIndexPath.Count > 0 ? sampleIndexPath[sampleIndexPath.Count - 1] : 0; var lastSampleInSearchScope = firstIndex == 0 ? frameData.sampleCount - 1 : firstIndex + frameData.GetSampleChildrenCountRecursive(firstIndex); // Check if the enclosing scope matches the searched sample if (sampleIndexPath != null && sampleIndexPath.Count > 0 && (sampleMarkerId == FrameDataView.invalidMarkerId && GetItemName(frameData, firstIndex) == sampleName || frameData.GetSampleMarkerId(firstIndex) == sampleMarkerId)) { return(firstIndex); } var samplePathAndLastSampleInScope = new List <RawSampleIterationInfo>() { }; for (int i = firstIndex; i <= lastSampleInSearchScope; i++) { samplePathAndLastSampleInScope.Add(new RawSampleIterationInfo { sampleIndex = i, lastSampleIndexInScope = i + frameData.GetSampleChildrenCountRecursive(i) }); if (sampleMarkerId == FrameDataView.invalidMarkerId && (sampleName != null && GetItemName(frameData, i) == sampleName) || frameData.GetSampleMarkerId(i) == sampleMarkerId) { // ignore the first sample if it's the enclosing sample (which is already in the list) for (int j = sampleIndexPath.Count > 0 ? 1 : 0; j < samplePathAndLastSampleInScope.Count; j++) { // ignore the first sample if it's either the thread root sample. // we can't always assume that there is a thread root sample, as the data may be mal formed, but we need to check if this is one by checking the name if (j == 0 && frameData.GetSampleName(samplePathAndLastSampleInScope[j].sampleIndex) == frameData.threadName) { continue; } sampleIndexPath.Add(samplePathAndLastSampleInScope[j].sampleIndex); } return(i); } while (samplePathAndLastSampleInScope.Count > 0 && i + 1 > samplePathAndLastSampleInScope[samplePathAndLastSampleInScope.Count - 1].lastSampleIndexInScope) { samplePathAndLastSampleInScope.RemoveAt(samplePathAndLastSampleInScope.Count - 1); } } return(RawFrameDataView.invalidSampleIndex); }
int FindMarkerPathAndRawSampleIndexToFirstMatchingSampleInCurrentView(int frameIndex, int threadIndex, ref string sampleName, ref List <int> markerIdPath, string markerNamePath = null, int sampleMarkerId = FrameDataView.invalidMarkerId) { using (var frameData = new RawFrameDataView(frameIndex, threadIndex)) { List <int> tempMarkerIdPath = null; if (markerIdPath != null && markerIdPath.Count > 0) { tempMarkerIdPath = markerIdPath; } var foundSampleIndex = RawFrameDataView.invalidSampleIndex; var sampleIndexPath = new List <int>(); if (sampleMarkerId == FrameDataView.invalidMarkerId) { sampleMarkerId = frameData.GetMarkerId(sampleName); } int pathLength = 0; string lastSampleInPath = null; Func <int, int, RawFrameDataView, bool> sampleIdFitsMarkerPathIndex = null; if (tempMarkerIdPath != null && tempMarkerIdPath.Count > 0) { pathLength = tempMarkerIdPath.Count; } else if (!string.IsNullOrEmpty(markerNamePath)) { var path = markerNamePath.Split('/'); if (path != null && path.Length > 0) { pathLength = path.Length; using (var iterator = new RawFrameDataView(frameIndex, threadIndex)) { tempMarkerIdPath = new List <int>(pathLength); for (int i = 0; i < pathLength; i++) { tempMarkerIdPath.Add(iterator.GetMarkerId(path[i])); } } sampleIdFitsMarkerPathIndex = (sampleIndex, markerPathIndex, iterator) => { return(tempMarkerIdPath[markerPathIndex] == FrameDataView.invalidMarkerId && GetItemName(iterator, sampleIndex) == path[markerPathIndex]); }; } } if (pathLength > 0) { var enclosingScopeSampleIndex = RawFrameDataView.invalidSampleIndex; if (sampleIndexPath.Capacity < pathLength) { sampleIndexPath.Capacity = pathLength + 1; // +1 for the presumably often case of the searched sample being part of the path or in the last scope of it } enclosingScopeSampleIndex = ProfilerTimelineGUI.FindNextSampleThroughMarkerPath( frameData, this, tempMarkerIdPath, pathLength, ref lastSampleInPath, ref sampleIndexPath, sampleIdFitsMarkerPathIndex: sampleIdFitsMarkerPathIndex); if (enclosingScopeSampleIndex == RawFrameDataView.invalidSampleIndex) { //enclosing scope not found return(RawFrameDataView.invalidSampleIndex); } foundSampleIndex = FindFirstMatchingRawSampleIndexInScopeRecursively(frameData, ref sampleIndexPath, sampleName, sampleMarkerId); while (foundSampleIndex == RawFrameDataView.invalidSampleIndex && enclosingScopeSampleIndex != RawFrameDataView.invalidSampleIndex) { // sample wasn't found in the current scope, find the next scope ... enclosingScopeSampleIndex = ProfilerTimelineGUI.FindNextSampleThroughMarkerPath( frameData, this, tempMarkerIdPath, pathLength, ref lastSampleInPath, ref sampleIndexPath, sampleIdFitsMarkerPathIndex: sampleIdFitsMarkerPathIndex); if (enclosingScopeSampleIndex == RawFrameDataView.invalidSampleIndex) { return(RawFrameDataView.invalidSampleIndex); } // ... and search there foundSampleIndex = FindFirstMatchingRawSampleIndexInScopeRecursively(frameData, ref sampleIndexPath, sampleName, sampleMarkerId); } } else { if (sampleMarkerId == FrameDataView.invalidMarkerId) { foundSampleIndex = FindFirstMatchingRawSampleIndexInScopeRecursively(frameData, ref sampleIndexPath, sampleName); } else { foundSampleIndex = FindFirstMatchingRawSampleIndexInScopeRecursively(frameData, ref sampleIndexPath, null, sampleMarkerId); } } if (foundSampleIndex != RawFrameDataView.invalidSampleIndex) { if (string.IsNullOrEmpty(sampleName)) { sampleName = GetItemName(frameData, foundSampleIndex); } if (markerIdPath == null) { markerIdPath = new List <int>(sampleIndexPath.Count); } // populate marker id path with missing markers for (int i = markerIdPath.Count; i < sampleIndexPath.Count; i++) { markerIdPath.Add(frameData.GetSampleMarkerId(sampleIndexPath[i])); } } return(foundSampleIndex); } }
void MigrateSelectedState(bool expandIfNecessary, bool framingAllowed) { if (m_LocalSelectedItemMarkerIdPath == null || m_Selected == null || m_LocalSelectedItemMarkerIdPath.Count != m_Selected.markerNamePath.Count) { return; } m_SelectionNeedsMigration = false; var markerNamePath = m_Selected.markerNamePath; expandIfNecessary |= m_ExpandDuringNextSelectionMigration; using (k_MigrateSelectionStateMarker.Auto()) { var safeFrameWithSafeMarkerIds = m_Selected.frameIndexIsSafe && m_FrameDataView.frameIndex == m_Selected.safeFrameIndex; var rawHierarchyView = (m_FrameDataView.viewMode & HierarchyFrameDataView.ViewModes.MergeSamplesWithTheSameName) == HierarchyFrameDataView.ViewModes.Default; var allowProxySelection = !safeFrameWithSafeMarkerIds; var finalRawSampleIndex = RawFrameDataView.invalidSampleIndex; using (var frameData = new RawFrameDataView(m_FrameDataView.frameIndex, m_FrameDataView.threadIndex)) { if (!frameData.valid) { return; } if (!safeFrameWithSafeMarkerIds) { // marker names might have changed Ids between frames, update them if that is the case for (int i = 0; i < m_LocalSelectedItemMarkerIdPath.Count; i++) { m_LocalSelectedItemMarkerIdPath[i] = frameData.GetMarkerId(markerNamePath[i]); } } else if (!allowProxySelection) { for (int i = 0; i < m_LocalSelectedItemMarkerIdPath.Count; i++) { var markerIsEditorOnlyMarker = frameData.GetMarkerFlags(m_LocalSelectedItemMarkerIdPath[i]).HasFlag(Unity.Profiling.LowLevel.MarkerFlags.AvailabilityEditor); if (markerIsEditorOnlyMarker && i < m_LocalSelectedItemMarkerIdPath.Count - 1) { // Technically, proxy selections are not supposed to be allowed when switching between views in the same frame. // However, if there are Editor Only markers in the path that are NOT the last item, Hierarchy View might have collapsed the path from this point forward, // so we need to allow Proxy Selections here. allowProxySelection = true; break; } } } var name = m_Selected.sampleDisplayName; m_CachedDeepestRawSampleIndexPath.Clear(); if (m_CachedDeepestRawSampleIndexPath.Capacity < markerNamePath.Count) { m_CachedDeepestRawSampleIndexPath.Capacity = markerNamePath.Count; } if (allowProxySelection || rawHierarchyView) { finalRawSampleIndex = ProfilerTimelineGUI.FindFirstSampleThroughMarkerPath( frameData, m_ProfilerSampleNameProvider, m_LocalSelectedItemMarkerIdPath, markerNamePath.Count, ref name, longestMatchingPath: m_CachedDeepestRawSampleIndexPath); } else { finalRawSampleIndex = ProfilerTimelineGUI.FindNextSampleThroughMarkerPath( frameData, m_ProfilerSampleNameProvider, m_LocalSelectedItemMarkerIdPath, markerNamePath.Count, ref name, ref m_CachedDeepestRawSampleIndexPath); } } var newSelectedId = m_FrameDataView.GetRootItemID(); bool selectedItemsPathIsExpanded = true; var proxySelection = new ProxySelection(); proxySelectionInfo = default; var deepestPath = m_CachedDeepestRawSampleIndexPath.Count; if (finalRawSampleIndex >= 0 || allowProxySelection && deepestPath > 0) { // if a valid raw index was found, find the corresponding HierarchyView Sample id next: newSelectedId = GetItemIdFromRawFrameDataIndexPath(m_FrameDataView, m_CachedDeepestRawSampleIndexPath, out deepestPath, out selectedItemsPathIsExpanded); if (m_LocalSelectedItemMarkerIdPath.Count > deepestPath && newSelectedId >= 0) { proxySelection.hasProxySelection = true; proxySelection.nonProxyName = m_Selected.sampleDisplayName; proxySelection.nonProxySampleStack = m_Selected.markerNamePath; proxySelection.pathLengthDifferenceForProxy = deepestPath - m_LocalSelectedItemMarkerIdPath.Count; } } 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 currently receiving profiler data from the Editor we are profiling, or the user opted into a "Live" view of the data if (newSelectedId != 0 && isInitialized && framingAllowed && (selectedItemsPathIsExpanded || expandIfNecessary)) { FrameItem(newSelectedId); } m_ExpandDuringNextSelectionMigration = false; proxySelectionInfo = proxySelection; } }