Ejemplo n.º 1
0
 private static bool CheckForContinuationMarker(RawFrameDataView frameData, ref FileAccessCaptureData captureData, int threadIndex, int markerId, int frameIndex, int sampleIndex, ulong markerStartTimeNs, ulong sampleLengthNs)
 {
     // if the marker is right at the start of the frame, it could have been split from another on the previous frame
     if (frameData.frameStartTimeNs == markerStartTimeNs)
     {
         // check for a matching marker that ends at the exact point this one starts
         for (int j = 0; j < captureData.m_FileAccessData.Count; j++)
         {
             if (captureData.m_FileAccessData[j].threadIndex == threadIndex && captureData.m_FileAccessData[j].markerId == markerId)
             {
                 if (AbsDiff(captureData.m_FileAccessData[j].endNs, markerStartTimeNs) < 10) // Account for rounding errors
                 {
                     captureData.m_FileAccessData[j].endNs    += sampleLengthNs;
                     captureData.m_FileAccessData[j].lengthNs += sampleLengthNs;
                     captureData.m_FileAccessData[j].ms        = captureData.m_FileAccessData[j].lengthNs * 0.000001;
                     captureData.m_FileAccessData[j].frameCount++;
                     captureData.m_FileAccessData[j].lastFrameIndex = frameIndex;
                     captureData.m_FileAccessData[j].sampleIds.Add(sampleIndex);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        public FileIOProfilerView()
        {
            m_CaptureData   = new FileAccessCaptureData();
            m_Markers       = new Dictionary <string, FileAccessMarkerInfo>();
            m_MarkerToIDMap = new Dictionary <string, int>();

            AddMarker("File.Open", FileAccessType.Open, FileOpenMetadataFiller, 1);
            AddMarker("File.Read", FileAccessType.Read, FileReadMetadataFiller, 3);
            AddMarker("File.Write", FileAccessType.Write, FileWriteMetadataFiller, 3);
            AddMarker("File.Seek", FileAccessType.Seek, FileSeekMetadataFiller, 3);
            AddMarker("File.Close", FileAccessType.Close, FileCloseMetadataFiller, 1);
        }
Ejemplo n.º 3
0
        public FileAccessTreeView(TreeViewState treeViewState, MultiColumnHeader multicolumnHeader, FileAccessCaptureData captureData, FileIOProfilerView fileIOProfilerView)
            : base(treeViewState, multicolumnHeader)
        {
            m_CaptureData  = captureData;
            m_ProfilerView = fileIOProfilerView;

            // Custom setup
            rowHeight = kRowHeights;
            showAlternatingRowBackgrounds = true;
            showBorder           = true;
            customFoldoutYOffset = (kRowHeights - EditorGUIUtility.singleLineHeight) * 0.5f; // center foldout in the row since we also center content. See RowGUI

            multicolumnHeader.canSort                = true;
            multicolumnHeader.sortingChanged        += OnSortingChanged;
            multicolumnHeader.visibleColumnsChanged += OnVisibleColumnsChanged;

            Reload();
        }
Ejemplo n.º 4
0
        void ClearData()
        {
            m_FileAccessTreeViewState          = null;
            m_FileAccessMulticolumnHeaderState = null;
            m_FileAccessTreeView          = null;
            m_FileAccessMultiColumnHeader = null;
            m_FileAccessTableIsCreated    = false;

            m_FileSummaryTreeViewState          = null;
            m_FileSummaryMulticolumnHeaderState = null;
            m_FileSummaryTreeView          = null;
            m_FileSummaryMultiColumnHeader = null;
            m_FileSummaryTableIsCreated    = false;

            m_CaptureData = new FileAccessCaptureData();
            DataPulled    = false;

            // Once there is no data, this will not need to be called again
            ProfilerDriver.profileCleared -= ClearData;
        }
Ejemplo n.º 5
0
        public static void PullDataStatic(ref FileAccessCaptureData captureData, Dictionary <string, FileAccessMarkerInfo> markers, ref Dictionary <string, int> markerToIDMap, int firstFrameIndex, int lastFrameIndex)
        {
            string error = null;

            captureData.m_FileAccessData.Clear();
            captureData.m_StartTimeNs = ulong.MaxValue;
            captureData.m_EndTimeNs   = ulong.MinValue;

            ProfilerFrameDataIterator frameIter = new ProfilerFrameDataIterator();
            double nsFrameStart;

            for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex)
            {
                frameIter.SetRoot(frameIndex, 0);

                int threadCount = frameIter.GetThreadCount(frameIndex);
                // iterate over the threads
                for (int threadIndex = 0; threadIndex < threadCount; ++threadIndex)
                {
                    using (RawFrameDataView frameData = ProfilerDriver.GetRawFrameDataView(frameIndex, threadIndex))
                    {
                        if (!frameData.valid)
                        {
                            break;
                        }

                        nsFrameStart = frameData.frameStartTimeNs;
                        if (frameIndex == firstFrameIndex)
                        {
                            if (captureData.m_StartTimeNs > nsFrameStart)
                            {
                                captureData.m_StartTimeNs = nsFrameStart;
                            }
                        }

                        GetMarkerIDs(frameData, markers, ref markerToIDMap);

                        string fullThreadName = GetFullThreadName(frameData.threadGroupName, frameData.threadName);

                        // iterate over the samples to collect up any markers
                        int sampleCount = frameData.sampleCount;
                        for (int i = 0; i < sampleCount; ++i)
                        {
                            s_CheckSamples.Begin();
                            int markerId = frameData.GetSampleMarkerId(i);
                            if (markerId == FrameDataView.invalidMarkerId || !markerToIDMap.ContainsValue(markerId))
                            {
                                s_CheckSamples.End();
                                continue;
                            }

                            string markerName = frameData.GetMarkerName(markerId);
                            Assert.IsTrue(markers.ContainsKey(markerName), string.Format("Marker {0} is not present in requested markers.", markerName));

                            s_CheckSamples.End();

                            s_AddNewMarker.Begin();

                            ulong markerStartTimeNs = Math.Max(frameData.GetSampleStartTimeNs(i) - (ulong)captureData.m_StartTimeNs, 0);
                            ulong sampleLengthNs    = frameData.GetSampleTimeNs(i);

                            // if the marker isn't a continuation of a previous marker, add a new access
                            if (!CheckForContinuationMarker(frameData, ref captureData, threadIndex, markerId, frameIndex, i, markerStartTimeNs, sampleLengthNs))
                            {
                                FileAccessMarker fileAccessMarker = new FileAccessMarker(frameIndex, threadIndex, i);

                                // fill in contexts from Metadata
                                FileAccessMarkerInfo markerInfo = markers[markerName];
                                if (markerInfo.metadataCount == frameData.GetSampleMetadataCount(i))
                                {
                                    markerInfo.metaDataFiller(ref fileAccessMarker, frameData, i);
                                }
                                else if (error == null) // Check the error is only shown once
                                {
                                    error = $"Some markers, such as '{markerName}', have unexpected metadata. This may be because of opening a profile captured with an older version of Unity. Certain values may be missing.";
                                    Debug.LogWarning(error);
                                }

                                if (string.IsNullOrEmpty(fileAccessMarker.filename))
                                {
                                    fileAccessMarker.readablePath     = "Unknown path";
                                    fileAccessMarker.readableFileName = "?";
                                }
                                else
                                {
                                    fileAccessMarker.readablePath     = fileAccessMarker.filename;
                                    fileAccessMarker.readableFileName = Path.GetFileName(fileAccessMarker.readablePath);
                                    if (fileAccessMarker.readablePath.Contains("/Analytics/"))
                                    {
                                        fileAccessMarker.readableFileName += " (Analytics)";
                                    }
                                }

                                fileAccessMarker.startNs  = markerStartTimeNs;
                                fileAccessMarker.lengthNs = sampleLengthNs;
                                fileAccessMarker.endNs    = markerStartTimeNs + sampleLengthNs;

                                fileAccessMarker.startTimeMs = markerStartTimeNs * 0.000001;
                                fileAccessMarker.ms          = fileAccessMarker.lengthNs * 0.000001;

                                fileAccessMarker.markerId   = markerId;
                                fileAccessMarker.type       = markerInfo.fileAccessType;
                                fileAccessMarker.markerName = markerName;
                                fileAccessMarker.threadName = fullThreadName;
                                fileAccessMarker.threadId   = frameData.threadId;

                                captureData.m_FileAccessData.Add(fileAccessMarker);
                            }
                            s_AddNewMarker.End();
                        }
                    }
                }
            }

            foreach (var fileAccessMarker in captureData.m_FileAccessData)
            {
                fileAccessMarker.averageBandwidthMBps = (fileAccessMarker.ms > 0) ? ((float)fileAccessMarker.sizeBytes / (float)fileAccessMarker.ms) * 0.001f : 0.0f;
            }

            frameIter.Dispose();
        }