コード例 #1
0
 static MyRenderProfiler()
 {
     // Create block, some unique id
     m_fpsBlock = MyProfiler.CreateExternalBlock("FPS", -2);
 }
コード例 #2
0
ファイル: MyProfiler.cs プロジェクト: warex0/SpaceEngineers
        private void CommitInternal()
        {
            Debug.Assert(!EnableAsserts || OwnerThread == Thread.CurrentThread);
            Debug.Assert(m_currentProfilingStack.Count == 0, "CommitFrame cannot be called when there are some opened blocks, it must be outside blocks!");
            m_currentProfilingStack.Clear();

            if (m_blocksToAdd.Count > 0)
            {
                using (m_historyLock.AcquireExclusiveUsing())
                {
                    foreach (var block in m_blocksToAdd)
                    {
                        if (block.Value.Parent != null)
                        {
                            block.Value.Parent.Children.AddOrInsert(block.Value, block.Value.ForceOrder);
                        }
                        else
                        {
                            m_rootBlocks.AddOrInsert(block.Value, block.Value.ForceOrder);
                        }

                        m_profilingBlocks.Add(block.Key, block.Value);
                    }
                    m_blocksToAdd.Clear();
                    Interlocked.Exchange(ref m_remainingWindow, UPDATE_WINDOW - 1); // We have lock, no one is in draw, reset window
                }
            }
            else if (m_historyLock.TryAcquireExclusive())
            {
                Interlocked.Exchange(ref m_remainingWindow, UPDATE_WINDOW - 1); // We have lock, no one is in draw, reset window
                m_historyLock.ReleaseExclusive();
            }
            else if (Interlocked.Decrement(ref m_remainingWindow) < 0)
            {
                // Window is empty, wait for lock and reset it
                using (m_historyLock.AcquireExclusiveUsing())
                {
                    Interlocked.Exchange(ref m_remainingWindow, UPDATE_WINDOW - 1); // We have lock, no one is in draw, reset window
                }
            }

            int callCount = 0;

            m_levelLimit = m_newLevelLimit;

            int writeFrame = (m_lastFrameIndex + 1) % MyProfiler.MAX_FRAMES;

            foreach (MyProfiler.MyProfilerBlock profilerBlock in m_profilingBlocks.Values)
            {
                callCount += profilerBlock.NumCalls;

                profilerBlock.ManagedMemory[writeFrame] = profilerBlock.ManagedDeltaMB;
                if (MemoryProfiling)
                {
                    profilerBlock.ProcessMemory[writeFrame] = profilerBlock.ProcessDeltaMB;
                }
                profilerBlock.NumCallsArray[writeFrame] = profilerBlock.NumCalls;
                profilerBlock.CustomValues[writeFrame]  = profilerBlock.CustomValue;
                profilerBlock.Miliseconds[writeFrame]   = (float)profilerBlock.Elapsed.Miliseconds;

                // Unused
                profilerBlock.averageMiliseconds = 0.9f * profilerBlock.averageMiliseconds + 0.1f * (float)profilerBlock.Elapsed.Miliseconds;
                //profilerBlock.NumChildCalls = profilerBlock.GetNumChildCalls();

                if (ENABLE_PROFILER_LOG)
                {
                    if (profilerBlock.Elapsed.Miliseconds > LOG_THRESHOLD_MS)
                    {
                        m_logWriter.Write(DateTime.Now.ToString());
                        m_logWriter.Write("; ");
                        m_logWriter.Write(((int)profilerBlock.Elapsed.Miliseconds).ToString());
                        m_logWriter.Write("; ");
                        m_logWriter.Write(profilerBlock.Name);
                        MyProfiler.MyProfilerBlock tempBlock = profilerBlock;
                        while (tempBlock.Parent != null)
                        {
                            tempBlock = tempBlock.Parent;
                            m_logWriter.Write(" <- " + tempBlock.Name);
                        }
                        m_logWriter.WriteLine("");
                    }
                }

                profilerBlock.Clear();
            }

            TotalCalls[writeFrame] = callCount;
            m_lastFrameIndex       = writeFrame;
        }
コード例 #3
0
 static MyRenderProfiler()
 {
     m_levelLimit = VRage.MyCompilationSymbols.ProfileFromStart ? -1 : 0;
     // Create block, some unique id
     m_fpsBlock = MyProfiler.CreateExternalBlock("FPS", -2);
 }