IEnumerator <ThreadIndexIterator> GetNextThreadIndexFittingThreadFilters(int frameIndex, List <string> threadFilters) { ProfilerFrameDataIterator frameData = new ProfilerFrameDataIterator(); int threadCount = frameData.GetThreadCount(frameIndex); Dictionary <string, int> threadNameCount = new Dictionary <string, int>(); for (int threadIndex = 0; threadIndex < threadCount; ++threadIndex) { frameData.SetRoot(frameIndex, threadIndex); var threadName = frameData.GetThreadName(); // Name here could be "Worker Thread 1" var groupName = frameData.GetGroupName(); threadName = ProfileData.GetThreadNameWithGroup(threadName, groupName); int nameCount = 0; threadNameCount.TryGetValue(threadName, out nameCount); threadNameCount[threadName] = nameCount + 1; var threadNameWithIndex = ProfileData.ThreadNameWithIndex(threadNameCount[threadName], threadName); // To compare on the filter we need to remove the postfix on the thread name // "3:Worker Thread 0" -> "1:Worker Thread" // The index of the thread (0) is used +1 as a prefix // The preceding number (3) is the count of number of threads with this name // Unfortunately multiple threads can have the same name threadNameWithIndex = ProfileData.CorrectThreadName(threadNameWithIndex); if (threadFilters.Contains(threadNameWithIndex)) { yield return(new ThreadIndexIterator { frameData = frameData, threadIndex = threadIndex }); } } frameData.Dispose(); }
public void QuickScan() { var frameData = new ProfilerFrameDataIterator(); m_threadNames.Clear(); int frameIndex = 0; int threadCount = frameData.GetThreadCount(0); frameData.SetRoot(frameIndex, 0); Dictionary <string, int> threadNameCount = new Dictionary <string, int>(); for (int threadIndex = 0; threadIndex < threadCount; ++threadIndex) { frameData.SetRoot(frameIndex, threadIndex); var threadName = frameData.GetThreadName(); var groupName = frameData.GetGroupName(); threadName = ProfileData.GetThreadNameWithGroup(threadName, groupName); if (!threadNameCount.ContainsKey(threadName)) { threadNameCount.Add(threadName, 1); } else { threadNameCount[threadName] += 1; } string threadNameWithIndex = ProfileData.ThreadNameWithIndex(threadNameCount[threadName], threadName); threadNameWithIndex = ProfileData.CorrectThreadName(threadNameWithIndex); m_threadNames.Add(threadNameWithIndex); } frameData.Dispose(); }
bool GetMarkerInfo(string markerName, int frameIndex, List <string> threadFilters, out int outThreadIndex, out float time, out float duration, out int instanceId) { ProfilerFrameDataIterator frameData = new ProfilerFrameDataIterator(); outThreadIndex = 0; time = 0.0f; duration = 0.0f; instanceId = 0; bool found = false; int threadCount = frameData.GetThreadCount(frameIndex); Dictionary <string, int> threadNameCount = new Dictionary <string, int>(); for (int threadIndex = 0; threadIndex < threadCount; ++threadIndex) { frameData.SetRoot(frameIndex, threadIndex); var threadName = frameData.GetThreadName(); // Name here could be "Worker Thread 1" var groupName = frameData.GetGroupName(); threadName = ProfileData.GetThreadNameWithGroup(threadName, groupName); int nameCount = 0; threadNameCount.TryGetValue(threadName, out nameCount); threadNameCount[threadName] = nameCount + 1; var threadNameWithIndex = ProfileData.ThreadNameWithIndex(threadNameCount[threadName], threadName); // To compare on the filter we need to remove the postfix on the thread name // "3:Worker Thread 0" -> "1:Worker Thread" // The index of the thread (0) is used +1 as a prefix // The preceding number (3) is the count of number of threads with this name // Unfortunately multiple threads can have the same name threadNameWithIndex = ProfileData.CorrectThreadName(threadNameWithIndex); if (threadFilters.Contains(threadNameWithIndex)) { const bool enterChildren = true; while (frameData.Next(enterChildren)) { if (frameData.name == markerName) { time = frameData.startTimeMS; duration = frameData.durationMS; instanceId = frameData.instanceId; outThreadIndex = threadIndex; found = true; break; } } } if (found) { break; } } frameData.Dispose(); return(found); }