File: FramerateTimer.h

package info (click to toggle)
storm-lang 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,100 kB
  • sloc: ansic: 261,471; cpp: 140,438; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (62 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "Timestamp.h"

namespace util {

	// A class designed to measure a large number of short intervals and report
	// any outstandingly large intervals. This is useful for measuring rendering times.
	// The class is used by creating a static instance of the FramerateTimer class
	// in the beginning of the function to be measured. Then an instance of FramerateTimer::Time
	// should be created so that its lifetime is during what is to be measured.
	//
	// Example:
	// static FramerateTimer timer(L"Rendering");
	// FramerateTimer::Time timerTime(timer);
	//
	// This is what is done by the macro FRAMERATE_TIME(L"Rendering");
	class FramerateTimer : NoCopy {
	public:
		// Create the static class with a label. This label is used with outputs.
		FramerateTimer(const wchar_t *name);

		// Class to keep track of a single run.
		class Time : NoCopy {
		public:
			Time(FramerateTimer &t);
			~Time();
		private:
			FramerateTimer &owner;
			Timestamp startTime;
		};

	private:
		const wchar_t *name;

		// Called by ~Time when an interval has been elapsed.
		void onInterval(Timespan time);

		// Number of samples before output
		static const nat numSamples = 100;

		// Current sample.
		nat currentSample;

		// Sample record.
		Timespan samples[numSamples];

		// Output statistics.
		void outputStats();
	};

}

// Macros
#ifdef _DEBUG
#define FRAMERATE_TIME(X) \
	static util::FramerateTimer timer(X); \
	util::FramerateTimer::Time timerTime(timer)

#else
#define FRAMERATE_TIME(X)
#endif