The MeterManager creates and hands out TimingMeter instances. Those instances are looked up by meter "title", a string name for the meter. Meter instances also have a string "category", so you can turn metering on and off by category. All public methods of MeterManager are static, so the user doesn't have to worry about managing the instance of MeterManager. The workflow is that the user program creates several meters by calling the static MakeMeter method, passing the title and category of the meter. That method looks up the meter by title, creating it if it doesn't already exists, and returns the meter. Thereafter, the user invokes the TimingMeter.Enter() and TimingMeter.Exit() methods, each of which causes the MeterManager to add a record to a collection of entries and exits. The record has the identity of the meter; whether it's an entry or exit, and the time in processor ticks, captured using the assembler primitive RDTSC. At any point, the program can call the method MeterManager.Report, which produces a report based on the trace.
Пример #1
0
 public void Exit()
 {
     if (MeterManager.Collecting && this.enabled)
     {
         MeterManager.AddEvent(this, MeterManager.ekExit, "");
     }
 }
Пример #2
0
 public static void Init()
 {
     if (instance == null)
     {
         instance = new MeterManager();
     }
 }
Пример #3
0
 protected MeterManager()
 {
     this.timerIdCounter      = 1;
     this.eventTrace          = new List <MeterEvent>();
     this.metersByName        = new Dictionary <string, TimingMeter>();
     this.metersById          = new Dictionary <int, TimingMeter>();
     this.startTime           = CaptureCurrentTime();
     this.microsecondsPerTick = 1000000.0f / (float)Stopwatch.Frequency;
     instance = this;
 }
Пример #4
0
 public void ToggleMetering(int frameCount)
 {
     if (meterFrameCount == 0)
     {
         MeterManager.ClearEvents();
         pendingMeterFrameCount = frameCount;
     }
     else
     {
         // Set it to 1 so we'll stop metering at the end of the next frame
         meterFrameCount = 1;
     }
 }
Пример #5
0
        public bool ToggleMeteringLongestFrame()
        {
            bool value = false;

            if (meterLongestFrame)
            {
                if (longestFrameMeterEvents != null)
                {
                    MeterManager.Report("Longest Frame", longestFrameMeterEvents);
                    longestFrameMeterEvents = null;
                    value = true;
                }
            }
            longestFrameTime  = 0;
            meterLongestFrame = !meterLongestFrame;
            return(value);
        }
Пример #6
0
		public static void Init()
		{
			if ( instance == null )
				instance = new MeterManager();
		}
Пример #7
0
		protected MeterManager()
		{
			timerIdCounter = 1;
			eventTrace = new List<MeterEvent>();
			metersByName = new Dictionary<string, TimingMeter>();
			metersById = new Dictionary<int, TimingMeter>();
			startTime = CaptureCurrentTime();
			microsecondsPerTick = 1000000.0f / (float)Stopwatch.Frequency;
			instance = this;
		}
Пример #8
0
        /// <summary>
        ///		Starts the default rendering loop.
        /// </summary>
        public void StartRendering()
        {
            bool cachedMeterLongestFrame = false;
            int  frameStartTime          = 0;

            Debug.Assert(activeRenderSystem != null, "Engine cannot start rendering without an active RenderSystem.");

            activeRenderSystem.InitRenderTargets();

            // initialize the vars
            lastStartTime = lastEndTime = timer.Milliseconds;

            // reset to false so that rendering can begin
            queuedEnd = false;

            while (!queuedEnd)
            {
                // Make sure we're collecting if it's called for
                if (meterFrameCount > 0)
                {
                    MeterManager.Collecting = true;
                }
                else if (meterLongestFrame)
                {
                    cachedMeterLongestFrame = true;
                    MeterManager.Collecting = true;
                    frameStartTime          = System.Environment.TickCount;
                }

                // allow OS events to process (if the platform requires it
                frameMeter.Enter();
                eventMeter.Enter();
                PlatformManager.Instance.DoEvents();
                eventMeter.Exit();

                if (suspendRendering)
                {
                    Thread.Sleep(100);
                    frameMeter.Exit();
                    continue;
                }

                renderMeter.Enter();
                RenderOneFrame();
                renderMeter.Exit();

                if (activeRenderSystem.RenderTargetCount == 0)
                {
                    QueueEndRendering();
                }
                frameMeter.Exit();

                // Turn metering on or off, and generate the report if
                // we're done
                if (meterFrameCount > 0)
                {
                    meterFrameCount--;
                    if (meterFrameCount == 0)
                    {
                        MeterManager.Collecting = false;
                        MeterManager.Report("Frame Processing");
                    }
                }
                else if (pendingMeterFrameCount > 0)
                {
                    // We'll start metering next frame
                    meterFrameCount        = pendingMeterFrameCount;
                    pendingMeterFrameCount = 0;
                }
                else if (cachedMeterLongestFrame)
                {
                    MeterManager.Collecting = false;
                    int frameTime = System.Environment.TickCount - frameStartTime;
                    if (frameTime > longestFrameTime)
                    {
                        longestFrameTime        = frameTime;
                        longestFrameMeterEvents = MeterManager.ReturnEvents();
                    }
                    else
                    {
                        MeterManager.ClearEvents();
                    }
                }
            }
        }