Example #1
0
 public static void SetProfiler(MyRenderProfiler profiler)
 {
     Profiler = profiler;
 }
        public static void HandleInput(RenderProfilerCommand command, int index)
        {
            switch (command)
            {
            case RenderProfilerCommand.Enable:
            {
                if (!m_enabled)
                {
                    m_enabled = true;
                    m_profilerProcessingEnabled = true;         // Enable when disabled and keep enabled
                    SetLevel();
                }
                break;
            }

            case RenderProfilerCommand.ToggleEnabled:
            {
                // Enable or Disable profiler drawing
                if (m_enabled)
                {
                    m_enabled        = false;
                    m_useCustomFrame = false;
                }
                else
                {
                    m_enabled = true;
                    m_profilerProcessingEnabled = true;         // Enable when disabled and keep enabled
                }
                break;
            }

            case RenderProfilerCommand.JumpToRoot:
                m_selectedProfiler.SelectedRoot = null;
                break;

            case RenderProfilerCommand.JumpToLevel:
            {
                // Enable when disabled, added this for programmers who are too used to using the numpad 0 to open the profiler.
                if (index == 0 && !m_enabled)
                {
                    m_enabled = true;
                    m_profilerProcessingEnabled = true;         // Enable when disabled and keep enabled
                }
                else
                {
                    m_selectedProfiler.SelectedRoot = FindBlockByIndex(index - 1);         // On screen it's indexed from 1 (zero is level up)
                }
                break;
            }

            case RenderProfilerCommand.Pause:
            {
                Paused = !Paused;
                GpuProfiler.AutoCommit = !Paused;
                break;
            }

            case RenderProfilerCommand.NextThread:
            {
                lock (m_threadProfilers)
                {
                    int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) + 1) % m_threadProfilers.Count;
                    m_selectedProfiler = m_threadProfilers[profilerIndex];
                }
                break;
            }

            case RenderProfilerCommand.PreviousThread:
            {
                lock (m_threadProfilers)
                {
                    int profilerIndex = (m_threadProfilers.IndexOf(m_selectedProfiler) - 1 + m_threadProfilers.Count) % m_threadProfilers.Count;
                    m_selectedProfiler = m_threadProfilers[profilerIndex];
                }
                break;
            }

            case RenderProfilerCommand.Reset:
            {
                lock (m_threadProfilers)
                {
                    foreach (var profiler in m_threadProfilers)
                    {
                        profiler.Reset();
                    }
                    m_selectedFrame = 0;
                }
                break;
            }

            case RenderProfilerCommand.NextFrame:
            {
                MyRenderProfiler.NextFrame(index);
                break;
            }

            case RenderProfilerCommand.PreviousFrame:
            {
                MyRenderProfiler.PreviousFrame(index);
                break;
            }

            case RenderProfilerCommand.DisableFrameSelection:
            {
                m_useCustomFrame = false;
                break;
            }

            case RenderProfilerCommand.IncreaseLevel:
            {
                m_levelLimit++;
                SetLevel();
                break;
            }

            case RenderProfilerCommand.DecreaseLevel:
            {
                m_levelLimit--;
                if (m_levelLimit < -1)
                {
                    m_levelLimit = -1;
                }
                SetLevel();
                break;
            }

            case RenderProfilerCommand.CopyPathToClipboard:
            {
                StringBuilder   pathBuilder  = new StringBuilder(200);
                MyProfilerBlock currentBlock = m_selectedProfiler.SelectedRoot;

                while (currentBlock != null)
                {
                    if (pathBuilder.Length > 0)
                    {
                        pathBuilder.Insert(0, " > ");
                    }
                    pathBuilder.Insert(0, currentBlock.Name);
                    currentBlock = currentBlock.Parent;
                }

                if (pathBuilder.Length > 0)
                {
                    // Clipboard can only be accessed from a thread on the STA apartment
                    System.Threading.Thread thread = new System.Threading.Thread(() => System.Windows.Forms.Clipboard.SetText(pathBuilder.ToString()));
                    thread.SetApartmentState(System.Threading.ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
                break;
            }

            case RenderProfilerCommand.TryGoToPathInClipboard:
            {
                string fullPath = string.Empty;

                Exception threadEx = null;
                System.Threading.Thread staThread = new System.Threading.Thread(
                    delegate()
                    {
                        try
                        {
                            fullPath = System.Windows.Forms.Clipboard.GetText();
                        }

                        catch (Exception ex)
                        {
                            threadEx = ex;
                        }
                    });
                staThread.SetApartmentState(System.Threading.ApartmentState.STA);
                staThread.Start();
                staThread.Join();

                if (!string.IsNullOrEmpty(fullPath))
                {
                    string[] split = fullPath.Split(new string[] { " > " }, StringSplitOptions.None);

                    MyProfilerBlock        pathBlock = null;
                    List <MyProfilerBlock> blockSet  = m_selectedProfiler.RootBlocks;
                    for (int i = 0; i < split.Length; i++)
                    {
                        string          blockName = split[i];
                        MyProfilerBlock oldPath   = pathBlock;

                        for (int j = 0; j < blockSet.Count; j++)
                        {
                            MyProfilerBlock block = blockSet[j];
                            if (block.Name == blockName)
                            {
                                pathBlock = block;
                                blockSet  = pathBlock.Children;
                                break;
                            }
                        }

                        // If the path did not change, we cannot go any deeper, break out of this loop
                        if (oldPath == pathBlock)
                        {
                            break;
                        }
                    }

                    if (pathBlock != null)
                    {
                        m_selectedProfiler.SelectedRoot = pathBlock;
                    }
                }
                break;
            }

            case RenderProfilerCommand.SetLevel:
            {
                m_levelLimit = index;
                if (m_levelLimit < -1)
                {
                    m_levelLimit = -1;
                }
                SetLevel();
                break;
            }

            case RenderProfilerCommand.DecreaseLocalArea:
                m_frameLocalArea = Math.Max(2, m_frameLocalArea / 2);
                break;

            case RenderProfilerCommand.IncreaseLocalArea:
                m_frameLocalArea = Math.Min(MyProfiler.MAX_FRAMES, m_frameLocalArea * 2);
                break;

            case RenderProfilerCommand.IncreaseRange:
                m_milisecondsGraphScale.IncreaseYRange();
                break;

            case RenderProfilerCommand.DecreaseRange:
                m_milisecondsGraphScale.DecreaseYRange();
                break;

            case RenderProfilerCommand.ChangeSortingOrder:
                m_sortingOrder += 1;
                if (m_sortingOrder >= RenderProfilerSortingOrder.NumSortingTypes)
                {
                    m_sortingOrder = RenderProfilerSortingOrder.Id;
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false, "Unknown command");
                break;
            }
        }
Example #3
0
 static NetProfiler()
 {
     m_profiler            = MyRenderProfiler.CreateProfiler("Network", "B");
     m_profiler.AutoCommit = false;
 }
 public static void SetProfiler(MyRenderProfiler profiler)
 {
     Profiler = profiler;
 }