public static ProfileMarker Create(float durationMS, int depth)
        {
            var item = new ProfileMarker
            {
                msMarkerTotal = durationMS,
                depth         = depth,
                msChildren    = 0.0f
            };

            return(item);
        }
コード例 #2
0
        public static ProfileMarker Create(ProfilerFrameDataIterator frameData)
        {
            var item = new ProfileMarker
            {
                msMarkerTotal = frameData.durationMS,
                depth         = frameData.depth,
                msChildren    = 0.0f
            };

            return(item);
        }
        ProfileMarker PopMarkerAndRecordTimeInParent(Stack <ProfileMarker> markerStack)
        {
            ProfileMarker child = markerStack.Pop();

            ProfileMarker parentMarker = (markerStack.Count > 0) ? markerStack.Peek() : null;

            // Record the last markers time in its parent
            if (parentMarker != null)
            {
                parentMarker.msChildren += child.msMarkerTotal;
            }

            return(parentMarker);
        }
        public void AddMarkerName(string markerName, ProfileMarker marker)
        {
            int index = -1;

            if (!markerNamesDict.TryGetValue(markerName, out index))
            {
                markerNames.Add(markerName);
                index = markerNames.Count - 1;

                markerNamesDict.Add(markerName, index);
            }

            marker.nameIndex = index;
        }
コード例 #5
0
        private ProfileMarker PopMarkerAndRecordTimeInParent(List <ProfileMarker> markerStack)
        {
            ProfileMarker child = markerStack[markerStack.Count - 1];

            markerStack.RemoveAt(markerStack.Count - 1);

            ProfileMarker parentMarker = (markerStack.Count > 0) ? markerStack[markerStack.Count - 1] : null;

            // Record the last markers time in its parent
            if (parentMarker != null)
            {
                parentMarker.msChildren += child.msMarkerTotal;
            }

            return(parentMarker);
        }
 public void AddMarker(ProfileMarker markerData)
 {
     markers.Add(markerData);
     markerCount++;
 }
 void PushMarker(Stack <ProfileMarker> markerStack, ProfileMarker markerData)
 {
     Debug.Assert(markerData.depth == markerStack.Count + 1);
     markerStack.Push(markerData);
 }
 public string GetMarkerName(ProfileMarker marker)
 {
     return(markerNames[marker.nameIndex]);
 }
コード例 #9
0
 public void Add(ProfileMarker marker)
 {
     markers.Add(marker);
 }
コード例 #10
0
        ProfileData GetDataOriginal(ProfileData data, int firstFrameIndex, int lastFrameIndex)
        {
            ProfilerFrameDataIterator frameData = new ProfilerFrameDataIterator();
            bool firstError = true;

            data.SetFrameIndexOffset(firstFrameIndex);

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

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

                int threadCount = frameData.GetThreadCount(frameIndex);
                frameData.SetRoot(frameIndex, 0);

                var msFrame = frameData.frameTimeMS;

                /*
                 * if (frameIndex == lastFrameIndex)
                 * {
                 *  // Check if last frame appears to be invalid data
                 *  float median;
                 *  float mean;
                 *  float standardDeviation;
                 *  CalculateFrameTimeStats(data, out median, out mean, out standardDeviation);
                 *  float execessiveDeviation = (3f * standardDeviation);
                 *  if (msFrame > (median + execessiveDeviation))
                 *  {
                 *      Debug.LogFormat("Dropping last frame as it is significantly larger than the median of the rest of the data set {0} > {1} (median {2} + 3 * standard deviation {3})", msFrame, median + execessiveDeviation, median, standardDeviation);
                 *      break;
                 *  }
                 *  if (msFrame < (median - execessiveDeviation))
                 *  {
                 *      Debug.LogFormat("Dropping last frame as it is significantly smaller than the median of the rest of the data set {0} < {1} (median {2} - 3 * standard deviation {3})", msFrame, median - execessiveDeviation, median, standardDeviation);
                 *      break;
                 *  }
                 * }
                 */

                ProfileFrame frame = new ProfileFrame();
                frame.msStartTime = 1000.0 * frameData.GetFrameStartS(frameIndex);
                frame.msFrame     = msFrame;
                data.Add(frame);

                threadNameCount.Clear();
                for (int threadIndex = 0; threadIndex < threadCount; ++threadIndex)
                {
                    frameData.SetRoot(frameIndex, threadIndex);

                    var threadName = frameData.GetThreadName();
                    if (threadName.Trim() == "")
                    {
                        Debug.Log(string.Format("Warning: Unnamed thread found on frame {0}. Corrupted data suspected, ignoring frame", frameIndex));
                        continue;
                    }

                    var groupName = frameData.GetGroupName();
                    threadName = ProfileData.GetThreadNameWithGroup(threadName, groupName);

                    ProfileThread thread = new ProfileThread();
                    frame.Add(thread);

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

                    data.AddThreadName(ProfileData.ThreadNameWithIndex(threadNameCount[threadName], threadName), thread);

                    const bool enterChildren = true;
                    // The markers are in depth first order and the depth is known
                    // So we can infer a parent child relationship
                    while (frameData.Next(enterChildren))
                    {
                        if (frameData.durationMS < 0)
                        {
                            if (firstError)
                            {
                                int displayIndex = data.OffsetToDisplayFrame(frameIndex);

                                Debug.LogFormat("Ignoring Invalid marker time found for {0} on frame {1} on thread {2} ({3} < 0) : Instance id : {4}",
                                                frameData.name, displayIndex, threadName, frameData.durationMS, frameData.instanceId);

                                firstError = false;
                            }
                            continue;
                        }
                        var markerData = ProfileMarker.Create(frameData);

                        data.AddMarkerName(frameData.name, markerData);
                        thread.AddMarker(markerData);
                    }
                }
            }

            data.Finalise();

            frameData.Dispose();
            return(data);
        }
コード例 #11
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);
        }
コード例 #12
0
 private void PushMarker(List <ProfileMarker> markerStack, ProfileMarker markerData)
 {
     Debug.Assert(markerData.depth == markerStack.Count + 1);
     markerStack.Add(markerData);
 }