예제 #1
0
        private SampleData GetPhysicsSampleData(RawFrameDataView frameData, string markerName)
        {
            SampleData sampleData = default;

            // Find the marker.
            if (m_Markers.TryGetValue(markerName, out int markerId))
            {
                for (var i = 0; i < frameData.sampleCount; ++i)
                {
                    // Ignore if it's not the marker we want.
                    if (markerId != frameData.GetSampleMarkerId(i))
                    {
                        continue;
                    }

                    // Accumulate sample data.
                    sampleData.timeMs += frameData.GetSampleTimeMs(i);
                    sampleData.count++;
                }
            }

            return(sampleData);
        }
예제 #2
0
        ProfileData GetDataRaw(ProfileData data, int firstFrameIndex, int lastFrameIndex)
        {
            bool firstError = true;

            data.SetFrameIndexOffset(firstFrameIndex);

            var depthStack = new Stack <int>();

            var threadNameCount     = new Dictionary <string, int>();
            var markerIdToNameIndex = new Dictionary <int, int>();

            for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex)
            {
                m_progressBar.AdvanceProgressBar();

                int threadIndex = 0;

                threadNameCount.Clear();
                ProfileFrame frame = null;
                while (true)
                {
                    using (RawFrameDataView frameData = ProfilerDriver.GetRawFrameDataView(frameIndex, threadIndex))
                    {
                        if (threadIndex == 0)
                        {
                            frame = new ProfileFrame();
                            if (frameData.valid)
                            {
                                frame.msStartTime = frameData.frameStartTimeMs;
                                frame.msFrame     = frameData.frameTimeMs;
                            }
                            data.Add(frame);
                        }

                        if (!frameData.valid)
                        {
                            break;
                        }

                        string threadNameWithIndex = null;
                        string threadName          = frameData.threadName;
                        if (threadName.Trim() == "")
                        {
                            Debug.Log(string.Format("Warning: Unnamed thread found on frame {0}. Corrupted data suspected, ignoring frame", frameIndex));
                            threadIndex++;
                            continue;
                        }
                        var groupName = frameData.threadGroupName;
                        threadName = ProfileData.GetThreadNameWithGroup(threadName, groupName);

                        int nameCount = 0;
                        threadNameCount.TryGetValue(threadName, out nameCount);
                        threadNameCount[threadName] = nameCount + 1;

                        threadNameWithIndex = ProfileData.ThreadNameWithIndex(threadNameCount[threadName], threadName);

                        var thread = new ProfileThread();
                        data.AddThreadName(threadNameWithIndex, thread);

                        frame.Add(thread);

                        // The markers are in depth first order
                        depthStack.Clear();
                        // first sample is the thread name
                        for (int i = 1; i < frameData.sampleCount; i++)
                        {
                            float durationMS = frameData.GetSampleTimeMs(i);
                            int   markerId   = frameData.GetSampleMarkerId(i);
                            if (durationMS < 0)
                            {
                                if (firstError)
                                {
                                    int displayIndex = data.OffsetToDisplayFrame(frameIndex);

                                    string name = frameData.GetSampleName(i);
                                    Debug.LogFormat("Ignoring Invalid marker time found for {0} on frame {1} on thread {2} ({3} < 0)",
                                                    name, displayIndex, threadName, durationMS);

                                    firstError = false;
                                }
                            }
                            else
                            {
                                int depth      = 1 + depthStack.Count;
                                var markerData = ProfileMarker.Create(durationMS, depth);

                                // Use name index directly if we have already stored this named marker before
                                int nameIndex;
                                if (markerIdToNameIndex.TryGetValue(markerId, out nameIndex))
                                {
                                    markerData.nameIndex = nameIndex;
                                }
                                else
                                {
                                    string name = frameData.GetSampleName(i);
                                    data.AddMarkerName(name, markerData);
                                    markerIdToNameIndex[markerId] = markerData.nameIndex;
                                }

                                thread.AddMarker(markerData);
                            }

                            int childrenCount = frameData.GetSampleChildrenCount(i);
                            if (childrenCount > 0)
                            {
                                depthStack.Push(childrenCount);
                            }
                            else
                            {
                                while (depthStack.Count > 0)
                                {
                                    int remainingChildren = depthStack.Pop();
                                    if (remainingChildren > 1)
                                    {
                                        depthStack.Push(remainingChildren - 1);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    threadIndex++;
                }
            }

            data.Finalise();

            return(data);
        }