summaryrefslogtreecommitdiff
path: root/indra/llcommon/llfasttimer.h
blob: 1a7e60656cf5ec2baae01a2dab5cf469a2eebddd (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/** 
 * @file llfasttimer.h
 * @brief Declaration of a fast timer.
 *
 * Copyright (c) 2004-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#ifndef LL_LLFASTTIMER_H
#define LL_LLFASTTIMER_H

#include "lltimer.h"

#define FAST_TIMER_ON 1

U64 get_cpu_clock_count();

class LLFastTimer
{
public:
	enum EFastTimerType
	{
		// high level
		FTM_FRAME,
		FTM_UPDATE,
		FTM_RENDER,
		FTM_SWAP,
		FTM_IDLE,
		FTM_SLEEP,

		// common messaging components
		FTM_PUMP,
		FTM_CURL,
		
		// common simulation components
		FTM_UPDATE_ANIMATION,
		FTM_UPDATE_TERRAIN,
		FTM_UPDATE_PRIMITIVES,
		FTM_UPDATE_PARTICLES,
		FTM_SIMULATE_PARTICLES,
		FTM_UPDATE_SKY,
		FTM_UPDATE_TEXTURES,
		FTM_UPDATE_WATER,
		FTM_UPDATE_CLOUDS,
		FTM_UPDATE_GRASS,
		FTM_UPDATE_TREE,
		FTM_UPDATE_AVATAR,
		
		// common render components
		FTM_RENDER_GEOMETRY,
		 FTM_RENDER_TERRAIN,
		 FTM_RENDER_SIMPLE,
		 FTM_RENDER_FULLBRIGHT,
		 FTM_RENDER_GRASS,
		 FTM_RENDER_INVISIBLE,
		 FTM_RENDER_SHINY,
		 FTM_RENDER_BUMP,
		 FTM_RENDER_TREES,
		 FTM_RENDER_CHARACTERS,
		 FTM_RENDER_OCCLUSION,
		 FTM_RENDER_ALPHA,
         FTM_RENDER_CLOUDS,
		 FTM_RENDER_HUD,
		 FTM_RENDER_PARTICLES,
		 FTM_RENDER_WATER,
		FTM_RENDER_TIMER,
		FTM_RENDER_UI,
		FTM_RENDER_FONTS,
		
		// newview specific
		FTM_MESSAGES,
		FTM_REBUILD,
		FTM_STATESORT,
		FTM_STATESORT_DRAWABLE,
		FTM_STATESORT_POSTSORT,
		FTM_REBUILD_VBO,
		FTM_REBUILD_VOLUME_VB,
		FTM_REBUILD_BRIDGE_VB,
		FTM_REBUILD_HUD_VB,
		FTM_REBUILD_TERRAIN_VB,
		FTM_REBUILD_WATER_VB,
		FTM_REBUILD_TREE_VB,
		FTM_REBUILD_PARTICLE_VB,
		FTM_REBUILD_CLOUD_VB,
		FTM_REBUILD_GRASS_VB,
		FTM_REBUILD_NONE_VB,
		FTM_REBUILD_OCCLUSION_VB,
		FTM_POOLS,
		FTM_POOLRENDER,
		FTM_IDLE_CB,
		FTM_WORLD_UPDATE,
		FTM_UPDATE_MOVE,
		FTM_OCTREE_BALANCE,
		FTM_UPDATE_LIGHTS,
		FTM_CULL,
		FTM_CULL_REBOUND,
		FTM_FRUSTUM_CULL,
		FTM_GEO_UPDATE,
		FTM_GEO_RESERVE,
		FTM_GEO_LIGHT,
		FTM_GEO_SHADOW,
		FTM_GEN_VOLUME,
		FTM_GEN_TRIANGLES,
		FTM_GEN_FLEX,
		FTM_AUDIO_UPDATE,
		FTM_RESET_DRAWORDER,
		FTM_OBJECTLIST_UPDATE,
		FTM_AVATAR_UPDATE,
		FTM_JOINT_UPDATE,
		FTM_ATTACHMENT_UPDATE,
		FTM_LOD_UPDATE,
		FTM_REGION_UPDATE,
		FTM_CLEANUP,
		FTM_NETWORK,
		FTM_IDLE_NETWORK,
		FTM_CREATE_OBJECT,
		FTM_LOAD_AVATAR,
		FTM_PROCESS_MESSAGES,
		FTM_PROCESS_OBJECTS,
		FTM_PROCESS_IMAGES,
		FTM_IMAGE_UPDATE,
		FTM_IMAGE_CREATE,
		FTM_IMAGE_DECODE,
		FTM_IMAGE_MARK_DIRTY,
		FTM_PIPELINE,
		FTM_VFILE_WAIT,
		FTM_FLEXIBLE_UPDATE,
		FTM_OCCLUSION,
		FTM_OCCLUSION_READBACK,
		FTM_HUD_EFFECTS,
		FTM_HUD_UPDATE,
		FTM_INVENTORY,
		FTM_AUTO_SELECT,
		FTM_ARRANGE,
		FTM_FILTER,
		FTM_REFRESH,
		FTM_SORT,
		
		// Temp
		FTM_TEMP1,
		FTM_TEMP2,
		FTM_TEMP3,
		FTM_TEMP4,
		FTM_TEMP5,
		FTM_TEMP6,
		FTM_TEMP7,
		FTM_TEMP8,
		
		FTM_OTHER, // Special, used by display code
		
		FTM_NUM_TYPES
	};
	enum { FTM_HISTORY_NUM = 60 };
	enum { FTM_MAX_DEPTH = 64 };
	
public:
	LLFastTimer(EFastTimerType type)
	{
#if FAST_TIMER_ON
		mType = type;

		// These don't get counted, because they use CPU clockticks
		//gTimerBins[gCurTimerBin]++;
		//LLTimer::sNumTimerCalls++;

		U64 cpu_clocks = get_cpu_clock_count();

		sStart[sCurDepth] = cpu_clocks;
		sCurDepth++;
#endif
	};
	~LLFastTimer()
	{
#if FAST_TIMER_ON
		U64 end,delta;
		int i;

		// These don't get counted, because they use CPU clockticks
		//gTimerBins[gCurTimerBin]++;
		//LLTimer::sNumTimerCalls++;
		end = get_cpu_clock_count();

		sCurDepth--;
		delta = end - sStart[sCurDepth];
		sCounter[mType] += delta;
		sCalls[mType]++;
		// Subtract delta from parents
		for (i=0; i<sCurDepth; i++)
			sStart[i] += delta;
#endif
	}

	static void reset();
	static U64 countsPerSecond();

public:
	static int sCurDepth;
	static U64 sStart[FTM_MAX_DEPTH];
	static U64 sCounter[FTM_NUM_TYPES];
	static U64 sCalls[FTM_NUM_TYPES];
	static U64 sCountAverage[FTM_NUM_TYPES];
	static U64 sCallAverage[FTM_NUM_TYPES];
	static U64 sCountHistory[FTM_HISTORY_NUM][FTM_NUM_TYPES];
	static U64 sCallHistory[FTM_HISTORY_NUM][FTM_NUM_TYPES];
	static S32 sCurFrameIndex;
	static S32 sLastFrameIndex;
	static int sPauseHistory;
	static int sResetHistory;
	static F64 sCPUClockFrequency;
	
private:
	EFastTimerType mType;
};


#endif // LL_LLFASTTIMER_H