Ejemplo n.º 1
0
        // Deep copy constructor
        public ProfilerTimeSampleSelection(ProfilerTimeSampleSelection selection)
        {
            if (selection == null)
            {
                throw new ArgumentNullException($"{nameof(selection)}", $"{nameof(selection)} can't be null.");
            }
            frameIndex = selection.frameIndex;
            // frame index is safe until proven otherwise by Integrity checks in CPUOrGPUProfilerModule.SetSelection
            // creating a copy means the CPUOrGPUProfilerModule no longer has control over this, so assume its no longer safe
            frameIndexIsSafe  = false;
            threadName        = selection.threadName;
            threadGroupName   = selection.threadGroupName;
            threadId          = selection.threadId;
            sampleDisplayName = selection.sampleDisplayName;
            legacyMarkerPath  = selection.legacyMarkerPath;

            if (selection.rawSampleIndices != null)
            {
                m_RawSampleIndices = new List <int>(selection.rawSampleIndices.Count);
                m_RawSampleIndices.AddRange(selection.rawSampleIndices);
            }
            else
            {
                m_RawSampleIndices = new List <int>()
                {
                    selection.rawSampleIndex
                };
            }
            markerPathDepth = 0;

            if (selection.markerNamePath != null)
            {
                m_MarkerNamePath = new List <string>(selection.markerNamePath);
                markerPathDepth  = m_MarkerNamePath.Count;
            }
            else
            {
                m_MarkerNamePath = null;
            }

            if (selection.markerIdPath != null)
            {
                m_MarkerIdPath = new List <int>(selection.markerIdPath);
                if (markerPathDepth != m_MarkerIdPath.Count)
                {
                    throw new ArgumentException($"The Selection had a different marker path depth for {nameof(markerIdPath)} than for {nameof(markerNamePath)}, but they must be in sync");
                }
                markerPathDepth = m_MarkerIdPath.Count;
            }
            else
            {
                if (markerPathDepth > 0)
                {
                    throw new ArgumentException($"The Selection had a different marker path depth for {nameof(markerIdPath)} than for {nameof(markerNamePath)}, but they must be in sync");
                }
                m_MarkerIdPath = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search for a sample fitting the '/' seperated path to it and select it
        /// </summary>
        /// <param name="markerNameOrMarkerNamePath">'/' seperated path to the marker </param>
        /// <param name="frameIndex"> The frame to make the selection in, or -1 to select in currently active frame. </param>
        /// <param name="threadIndex"> The index of the thread to find the sample in. </param>
        /// <returns></returns>
        public static bool SetSelection(this IProfilerFrameTimeViewSampleSelectionController controller, string markerNameOrMarkerNamePath, long frameIndex = FrameDataView.invalidOrCurrentFrameIndex, string threadGroupName = CPUProfilerModule.mainThreadGroupName, string threadName = CPUProfilerModule.mainThreadName, ulong threadId = FrameDataView.invalidThreadId)
        {
            var iController = controller as IProfilerFrameTimeViewSampleSelectionControllerInternal;

            if (controller == null || iController == null)
            {
                throw new ArgumentNullException($"{nameof(controller)}", $"The IProfilerFrameTimeViewSampleSelectionController you are setting a selection on can't be null.");
            }

            ProfilerTimeSampleSelection selection;
            List <int> markerIdPath;

            using (CPUOrGPUProfilerModule.setSelectionIntegrityCheckMarker.Auto())
            {
                // this could've come from anywhere, check the inputs first
                if (string.IsNullOrEmpty(markerNameOrMarkerNamePath))
                {
                    throw new ArgumentException($"{nameof(markerNameOrMarkerNamePath)} can't be null or empty. Hint: To clear a selection, use {nameof(IProfilerFrameTimeViewSampleSelectionController.ClearSelection)} instead.");
                }

                if (frameIndex == FrameDataView.invalidOrCurrentFrameIndex)
                {
                    frameIndex = iController.GetActiveVisibleFrameIndexOrLatestFrameForSettingTheSelection();
                }

                var threadIndex = CPUOrGPUProfilerModule.IntegrityCheckFrameAndThreadDataOfSelection(frameIndex, threadGroupName, threadName, ref threadId);

                int    lastSlashIndex = markerNameOrMarkerNamePath.LastIndexOf('/');
                string sampleName     = lastSlashIndex == -1 ? markerNameOrMarkerNamePath : markerNameOrMarkerNamePath.Substring(lastSlashIndex + 1, markerNameOrMarkerNamePath.Length - (lastSlashIndex + 1));

                if (lastSlashIndex == -1)// no path provided? just find the first sample
                {
                    markerNameOrMarkerNamePath = null;
                }

                int selectedSampleRawIndex = iController.FindMarkerPathAndRawSampleIndexToFirstMatchingSampleInCurrentView((int)frameIndex, 0, sampleName, out markerIdPath, markerNameOrMarkerNamePath);

                if (selectedSampleRawIndex < 0)
                {
                    return(false);
                }

                selection = new ProfilerTimeSampleSelection(frameIndex, threadGroupName, threadName, threadId, selectedSampleRawIndex, sampleName);
            }
            using (CPUOrGPUProfilerModule.setSelectionApplyMarker.Auto())
            {
                // looks good, apply
                selection.frameIndexIsSafe = true;
                iController.SetSelectionWithoutIntegrityChecks(selection, markerIdPath);
                return(true);
            }
        }
Ejemplo n.º 3
0
        // selects first occurence of this sample in the given frame and thread (and optionally given the markerNamePath leading up to it or a (grand, (grand)...) parent of it)
        public static bool SetSelection(this IProfilerFrameTimeViewSampleSelectionController controller, long frameIndex, string threadGroupName, string threadName, string sampleName, string markerNamePath = null, ulong threadId = FrameDataView.invalidThreadId)
        {
            var iController = controller as IProfilerFrameTimeViewSampleSelectionControllerInternal;

            if (controller == null || iController == null)
            {
                throw new ArgumentNullException($"{nameof(controller)}", $"The IProfilerFrameTimeViewSampleSelectionController you are setting a selection on can't be null.");
            }

            ProfilerTimeSampleSelection selection;
            List <int> markerIdPath;

            using (CPUOrGPUProfilerModule.setSelectionIntegrityCheckMarker.Auto())
            {
                // this could've come from anywhere, check the inputs first
                if (string.IsNullOrEmpty(sampleName))
                {
                    throw new ArgumentException($"{nameof(sampleName)} can't be null or empty. Hint: To clear a selection, use {nameof(IProfilerFrameTimeViewSampleSelectionController.ClearSelection)} instead.");
                }


                var threadIndex = CPUOrGPUProfilerModule.IntegrityCheckFrameAndThreadDataOfSelection(frameIndex, threadGroupName, threadName, ref threadId);

                int selectedSampleRawIndex = iController.FindMarkerPathAndRawSampleIndexToFirstMatchingSampleInCurrentView((int)frameIndex, threadIndex, sampleName, out markerIdPath, markerNamePath);

                if (selectedSampleRawIndex < 0)
                {
                    return(false);
                }

                selection = new ProfilerTimeSampleSelection(frameIndex, threadGroupName, threadName, threadId, selectedSampleRawIndex, sampleName);
            }
            using (CPUOrGPUProfilerModule.setSelectionApplyMarker.Auto())
            {
                // looks good, apply
                selection.frameIndexIsSafe = true;
                iController.SetSelectionWithoutIntegrityChecks(selection, markerIdPath);
                return(true);
            }
        }