aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llfasttimer.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llfasttimer.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llcommon/llfasttimer.cpp')
-rw-r--r--linden/indra/llcommon/llfasttimer.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llfasttimer.cpp b/linden/indra/llcommon/llfasttimer.cpp
new file mode 100644
index 0000000..61b6df2
--- /dev/null
+++ b/linden/indra/llcommon/llfasttimer.cpp
@@ -0,0 +1,183 @@
1/**
2 * @file llfasttimer.cpp
3 * @brief Implementation of the fast timer.
4 *
5 * Copyright (c) 2004-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27#include "linden_common.h"
28
29#include "llfasttimer.h"
30#include "llprocessor.h"
31
32#if LL_WINDOWS
33#include <time.h>
34
35#elif LL_LINUX
36#include <time.h>
37#include <sys/time.h>
38#include <sched.h>
39
40#elif LL_DARWIN
41# include <time.h>
42# include <sys/time.h>
43#else
44# error "architecture not supported"
45#endif
46
47//////////////////////////////////////////////////////////////////////////////
48// statics
49
50int LLFastTimer::sCurDepth = 0;
51U64 LLFastTimer::sStart[LLFastTimer::FTM_MAX_DEPTH];
52U64 LLFastTimer::sCounter[LLFastTimer::FTM_NUM_TYPES];
53U64 LLFastTimer::sCountHistory[LLFastTimer::FTM_HISTORY_NUM][LLFastTimer::FTM_NUM_TYPES];
54U64 LLFastTimer::sCountAverage[LLFastTimer::FTM_NUM_TYPES];
55U64 LLFastTimer::sCalls[LLFastTimer::FTM_NUM_TYPES];
56U64 LLFastTimer::sCallHistory[LLFastTimer::FTM_HISTORY_NUM][LLFastTimer::FTM_NUM_TYPES];
57U64 LLFastTimer::sCallAverage[LLFastTimer::FTM_NUM_TYPES];
58S32 LLFastTimer::sCurFrameIndex = -1;
59S32 LLFastTimer::sLastFrameIndex = -1;
60int LLFastTimer::sPauseHistory = 0;
61int LLFastTimer::sResetHistory = 0;
62
63F64 LLFastTimer::sCPUClockFrequency = 0.0;
64
65//////////////////////////////////////////////////////////////////////////////
66
67//
68// CPU clock/other clock frequency and count functions
69//
70
71#if LL_WINDOWS
72
73U64 get_cpu_clock_count()
74{ U32 hi,lo;
75
76 __asm
77 {
78 _emit 0x0f
79 _emit 0x31
80 mov lo,eax
81 mov hi,edx
82 }
83
84 U64 ret = hi;
85 ret *= 4294967296L;
86 ret |= lo;
87 return ret;
88};
89
90#endif // LL_WINDOWS
91
92
93#if LL_LINUX
94U64 get_cpu_clock_count()
95{
96 U64 x;
97 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
98 return x;
99}
100#endif
101
102#if LL_DARWIN
103//
104// Mac implementation of CPU clock
105//
106// Just use gettimeofday implementation for now
107
108U64 get_cpu_clock_count()
109{
110 return get_clock_count();
111}
112#endif
113
114//////////////////////////////////////////////////////////////////////////////
115
116//static
117#if LL_LINUX || LL_DARWIN
118// Both Linux and Mac use gettimeofday for accurate time
119U64 LLFastTimer::countsPerSecond()
120{
121 return 1000000; // microseconds, so 1 Mhz.
122}
123#else
124U64 LLFastTimer::countsPerSecond()
125{
126 if (!sCPUClockFrequency)
127 {
128 CProcessor proc;
129 sCPUClockFrequency = proc.GetCPUFrequency(50);
130 }
131 return U64(sCPUClockFrequency);
132}
133#endif
134
135void LLFastTimer::reset()
136{
137 countsPerSecond(); // good place to calculate clock frequency
138
139 if (sCurDepth != 0)
140 {
141 llerrs << "LLFastTimer::Reset() when sCurDepth != 0" << llendl;
142 }
143 if (sPauseHistory)
144 {
145 sResetHistory = 1;
146 }
147 else if (sResetHistory)
148 {
149 sCurFrameIndex = -1;
150 sResetHistory = 0;
151 }
152 else if (sCurFrameIndex >= 0)
153 {
154 int hidx = sCurFrameIndex % FTM_HISTORY_NUM;
155 for (S32 i=0; i<FTM_NUM_TYPES; i++)
156 {
157 sCountHistory[hidx][i] = sCounter[i];
158 sCountAverage[i] = (sCountAverage[i]*sCurFrameIndex + sCounter[i]) / (sCurFrameIndex+1);
159 sCallHistory[hidx][i] = sCalls[i];
160 sCallAverage[i] = (sCallAverage[i]*sCurFrameIndex + sCalls[i]) / (sCurFrameIndex+1);
161 }
162 sLastFrameIndex = sCurFrameIndex;
163 }
164 else
165 {
166 for (S32 i=0; i<FTM_NUM_TYPES; i++)
167 {
168 sCountAverage[i] = 0;
169 sCallAverage[i] = 0;
170 }
171 }
172
173 sCurFrameIndex++;
174
175 for (S32 i=0; i<FTM_NUM_TYPES; i++)
176 {
177 sCounter[i] = 0;
178 sCalls[i] = 0;
179 }
180 sCurDepth = 0;
181}
182
183//////////////////////////////////////////////////////////////////////////////