コード例 #1
0
        public void DrawEvent(int textOffsetY, MyProfiler.MyProfilerBlock profilerBlock, int index = -1)
        {
            float Y_TEXT_POSITION = MyMinerGame.Static.GraphicsDevice.Viewport.Height / 2;

            float textScale = 0.7f;

            StringBuilder text = new StringBuilder(100);
            text.Clear();
            text.Append((textOffsetY + 1).ToString("0 "));
            text.Append(profilerBlock.Name);

            MyDebugDraw.DrawText(new Vector2(20, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);

            float length = 500;

            text.Clear();
            text.Append(profilerBlock.Children.Count.ToString("(0) "));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 50 * textScale;

            text.Clear();
            //text.Append(((index != -1 ? profilerBlock.TimePercentage[index] : profilerBlock.averagePctg)).ToString("#,#0.0%"));
            //MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 155 * textScale;

            text.Clear();
            text.Append((index != -1 ? profilerBlock.Miliseconds[index] : profilerBlock.averageMiliseconds).ToString("#,##0.00ms"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 155 * textScale;

            text.Clear();
            text.Append((index != -1 ? profilerBlock.ManagedMemory[index] : profilerBlock.TotalManagedMB).ToString("#,###0.000 GC"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 40 + 158 * textScale;

            text.Clear();
#if MEMORY_PROFILING
            text.Append((index != -1 ? profilerBlock.ProcessMemory[index] : profilerBlock.totalProcessMB).ToString("#,###0.000 MB"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            length += 158 * textScale;

            text.Clear();
#endif

            length += 40 + 40 * textScale;
            text.Append(profilerBlock.NumCallsArray[index != -1 ? index : 0].ToString());
            text.Append(profilerBlock.NumCalls.ToString(" calls"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);

            length += 150 * textScale;
            text.Clear();
            text.Append("Custom: ");
            text.Append((index != -1 ? profilerBlock.CustomValues[index] : profilerBlock.CustomValue).ToString("#,###0.000"));
            MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
            



//             if (profilerBlock.NumCalls > 1)
//                 text.Append("s");

            length += MyDebugDraw.DrawText(new Vector2(20 + length, Y_TEXT_POSITION + textOffsetY * 20), text, UintToColor(profilerBlock.color), textScale);
        }
コード例 #2
0
        public void StartProfilingBlock(string name, ref int blockId)
        {
            lock (m_lock)
            {
                if (!m_threadProfilers.ContainsKey(Thread.CurrentThread))
                    m_threadProfilers.Add(Thread.CurrentThread, new MyProfiler());

                MyProfiler currentProfiler = m_threadProfilers[Thread.CurrentThread];

                if (m_selectedProfiler == null)
                {
                    m_selectedProfiler = currentProfiler;
                    m_selectedThread = Thread.CurrentThread;
                    m_selectedProfilerIndex = 0;
                }

                if (m_levelLimit != -1 && currentProfiler.CurrentProfilingStack.Count >= m_levelLimit)
                {
                    currentProfiler.LevelSkipCount++;
                    return;
                }

#if MEMORY_PROFILING
                blockId = currentProfiler.StartMyProfilingBlock(name, true);
#else
                blockId = currentProfiler.StartMyProfilingBlock(name, false);
#endif
            }
        }
コード例 #3
0
        public static void PressedKey(Keys key, bool isCtrlPressed = false)
        {
            int index = key - Keys.NumPad0;
            if (index >= 0 && index <= 9)
            {
                if (isCtrlPressed)
                    index += 10;

                // Enable or Disable profiler drawing
                if (m_enabled && m_selectedProfiler.SelectedRoot == null)
                {
                    if (index == 0)
                    {
                        m_enabled = false;
                        m_useCustomFrame = false;
                        return;
                    }
                }
                else if (!m_enabled && index == 0)
                {
                    m_enabled = true;
                    return;
                }

                // Enter child node
                if (index >= 1 && index <= 19)
                {
                    if (m_selectedProfiler.SelectedRoot == null)
                    {
                        int cnt = 0;
                        foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.ProfilingBlocks.Values)
                        {
                            if (profilerBlock.Parent == null)
                            {
                                cnt++;

                                if (index == cnt)
                                {
                                    m_selectedProfiler.SelectedRoot = profilerBlock;
                                    return;
                                }
                            }
                        }
                    }
                    else if (m_selectedProfiler.SelectedRoot.Children.Count >= index)
                    {
                        int cnt = 0;
                        int flagIndex = 0;
                        foreach (MyProfiler.MyProfilerBlock profilerBlock in m_selectedProfiler.SelectedRoot.Children)
                        {
                            cnt++;
                            //if ((profilerBlock.flag & (int)filterMask) != 0)
                            {
                                flagIndex++;
                                if (index == flagIndex)
                                {
//                                     m_selectedRoot = profilerBlock;
//                                     return;

                                    m_selectedProfiler.SelectedRoot = m_selectedProfiler.SelectedRoot.Children[cnt - 1];
                                    return;
                                }
                            }
                        }
                        
                    }
                }

                // Go to parent node
                if (index == 0 && m_selectedProfiler.SelectedRoot != null)
                {
                    m_selectedProfiler.SelectedRoot = m_selectedProfiler.SelectedRoot.Parent;
                }
            }

            if (key == Keys.Enter)
            {
                Paused = !Paused;
                m_useCustomFrame = false; // Turf-off custom frame after ALT + ENTER
            }

            if(key == Keys.Delete)
            {
                // This will enable stack checking for StartProfilingblock and EndProfilingblock for some period of time.
                // It will check whether the StartProfilingblock and EndProfilingblock is called within the same function.
                
                m_stackCheckingDuration = 1;    // set duration to 1s 
            }

            if (key == Keys.Add)
            {
                List<MyProfiler> profilers = new List<MyProfiler>();
                foreach (var t in m_threadProfilers.Values)
                {
                    profilers.Add(t);
                }

                int profilerIndex = profilers.IndexOf(m_selectedProfiler);
                profilerIndex++;
                if (profilerIndex >= profilers.Count)
                    profilerIndex = 0;

                int i = 0;
                foreach (var t in m_threadProfilers)
                {
                    if (i == profilerIndex)
                    {
                        m_selectedProfiler = t.Value;
                        m_selectedThread = t.Key;
                        m_selectedProfilerIndex = i;
                        break;
                    }
                    i++;
                }
            }

            if (key == Keys.Subtract)
            {
                List<MyProfiler> profilers = new List<MyProfiler>();
                foreach (var t in m_threadProfilers.Values)
                {
                    profilers.Add(t);
                }

                int profilerIndex = profilers.IndexOf(m_selectedProfiler);
                profilerIndex--;
                if (profilerIndex < 0)
                    profilerIndex = profilers.Count - 1;

                int i = 0;
                foreach (var t in m_threadProfilers)
                {
                    if (i == profilerIndex)
                    {
                        m_selectedProfiler = t.Value;
                        m_selectedThread = t.Key;
                        m_selectedProfilerIndex = i;
                        break;
                    }
                    i++;
                }
            }

            if (key == Keys.Multiply)
            {
                m_levelLimit++;
            }

            if (key == Keys.Divide)
            {
                m_levelLimit--;
                if (m_levelLimit < -1)
                    m_levelLimit = -1;
            }
        }