2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "precompiled.h"
32 double idTimer::base = -1.0;
37 idTimer::InitBaseClockTicks
40 void idTimer::InitBaseClockTicks( void ) const {
47 for ( i = 0; i < 1000; i++ ) {
51 ct = timer.ClockTicks();
52 if ( b < 0.0 || ct < b ) {
62 idTimerReport::idTimerReport
65 idTimerReport::idTimerReport() {
70 idTimerReport::SetReportName
73 void idTimerReport::SetReportName( const char *name ) {
74 reportName = ( name ) ? name : "Timer Report";
79 idTimerReport::~idTimerReport
82 idTimerReport::~idTimerReport() {
88 idTimerReport::AddReport
91 int idTimerReport::AddReport( const char *name ) {
92 if ( name && *name ) {
94 return timers.Append( new idTimer() );
104 void idTimerReport::Clear() {
105 timers.DeleteContents( true );
115 void idTimerReport::Reset() {
116 assert ( timers.Num() == names.Num() );
117 for ( int i = 0; i < timers.Num(); i++ ) {
124 idTimerReport::AddTime
127 void idTimerReport::AddTime( const char *name, idTimer *time ) {
128 assert ( timers.Num() == names.Num() );
130 for ( i = 0; i < names.Num(); i++ ) {
131 if ( names[i].Icmp( name ) == 0 ) {
136 if ( i == names.Num() ) {
137 int index = AddReport( name );
139 timers[index]->Clear();
140 *timers[index] += *time;
147 idTimerReport::PrintReport
150 void idTimerReport::PrintReport() {
151 assert( timers.Num() == names.Num() );
152 idLib::common->Printf( "Timing Report for %s\n", reportName.c_str() );
153 idLib::common->Printf( "-------------------------------\n" );
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();
159 idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), total * 0.001f );