doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Timer.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "precompiled.h"
30 #pragma hdrstop
31 
32 double idTimer::base = -1.0;
33 
34 
35 /*
36 =================
37 idTimer::InitBaseClockTicks
38 =================
39 */
40 void idTimer::InitBaseClockTicks( void ) const {
41  idTimer timer;
42  double ct, b;
43  int i;
44 
45  base = 0.0;
46  b = -1.0;
47  for ( i = 0; i < 1000; i++ ) {
48  timer.Clear();
49  timer.Start();
50  timer.Stop();
51  ct = timer.ClockTicks();
52  if ( b < 0.0 || ct < b ) {
53  b = ct;
54  }
55  }
56  base = b;
57 }
58 
59 
60 /*
61 =================
62 idTimerReport::idTimerReport
63 =================
64 */
66 }
67 
68 /*
69 =================
70 idTimerReport::SetReportName
71 =================
72 */
73 void idTimerReport::SetReportName( const char *name ) {
74  reportName = ( name ) ? name : "Timer Report";
75 }
76 
77 /*
78 =================
79 idTimerReport::~idTimerReport
80 =================
81 */
83  Clear();
84 }
85 
86 /*
87 =================
88 idTimerReport::AddReport
89 =================
90 */
91 int idTimerReport::AddReport( const char *name ) {
92  if ( name && *name ) {
93  names.Append( name );
94  return timers.Append( new idTimer() );
95  }
96  return -1;
97 }
98 
99 /*
100 =================
101 idTimerReport::Clear
102 =================
103 */
105  timers.DeleteContents( true );
106  names.Clear();
107  reportName.Clear();
108 }
109 
110 /*
111 =================
112 idTimerReport::Reset
113 =================
114 */
116  assert ( timers.Num() == names.Num() );
117  for ( int i = 0; i < timers.Num(); i++ ) {
118  timers[i]->Clear();
119  }
120 }
121 
122 /*
123 =================
124 idTimerReport::AddTime
125 =================
126 */
127 void idTimerReport::AddTime( const char *name, idTimer *time ) {
128  assert ( timers.Num() == names.Num() );
129  int i;
130  for ( i = 0; i < names.Num(); i++ ) {
131  if ( names[i].Icmp( name ) == 0 ) {
132  *timers[i] += *time;
133  break;
134  }
135  }
136  if ( i == names.Num() ) {
137  int index = AddReport( name );
138  if ( index >= 0 ) {
139  timers[index]->Clear();
140  *timers[index] += *time;
141  }
142  }
143 }
144 
145 /*
146 =================
147 idTimerReport::PrintReport
148 =================
149 */
151  assert( timers.Num() == names.Num() );
152  idLib::common->Printf( "Timing Report for %s\n", reportName.c_str() );
153  idLib::common->Printf( "-------------------------------\n" );
154  float total = 0.0f;
155  for ( int i = 0; i < names.Num(); i++ ) {
156  idLib::common->Printf( "%s consumed %5.2f seconds\n", names[i].c_str(), timers[i]->Milliseconds() * 0.001f );
157  total += timers[i]->Milliseconds();
158  }
159  idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), total * 0.001f );
160 }
void InitBaseClockTicks(void) const
Definition: Timer.cpp:40
idStr reportName
Definition: Timer.h:220
assert(prefInfo.fullscreenBtn)
void Reset(void)
Definition: Timer.cpp:115
static double base
Definition: Timer.h:58
Definition: Timer.h:40
idTimerReport(void)
Definition: Timer.cpp:65
void Start(void)
Definition: Timer.h:144
int i
Definition: process.py:33
~idTimerReport(void)
Definition: Timer.cpp:82
GLuint index
Definition: glext.h:3476
int AddReport(const char *name)
Definition: Timer.cpp:91
void DeleteContents(bool clear)
Definition: List.h:207
void Clear(void)
Definition: Str.h:724
virtual void Printf(const char *fmt,...) id_attribute((format(printf
GLubyte GLubyte b
Definition: glext.h:4662
void SetReportName(const char *name)
Definition: Timer.cpp:73
void Stop(void)
Definition: Timer.h:155
int Append(const type &obj)
Definition: List.h:646
double ClockTicks(void) const
Definition: Timer.h:181
tuple f
Definition: idal.py:89
idList< idTimer * > timers
Definition: Timer.h:218
int Num(void) const
Definition: List.h:265
const GLcharARB * name
Definition: glext.h:3629
void PrintReport(void)
Definition: Timer.cpp:150
idStrList names
Definition: Timer.h:219
const char * c_str(void) const
Definition: Str.h:487
void Clear(void)
Definition: Timer.cpp:104
void AddTime(const char *name, idTimer *time)
Definition: Timer.cpp:127
static class idCommon * common
Definition: Lib.h:53
void Clear(void)
Definition: Timer.h:172
void Clear(void)
Definition: List.h:184