Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AProfiler.cpp

Go to the documentation of this file.
00001 /*
00002 CS Senior Project 2003
00003 Team : Leftfield
00004 Project : ModernWarfare
00005 Members :
00006 - Russ Christensen              <rchriste@cs.utah.edu>
00007 - Todd Smith                    <tcsmith@cs.utah.edu>
00008 - Usit Duongsaa                 <duongsaa@cs.utah.edu>
00009 Copyright 2003 Russ Christensen, Usit Duongsaa, and Todd Smith. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012 
00013 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
00014 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
00015 THIS SOFTWARE IS PROVIDED BY RUSS CHRISTENSEN, USIT DUONGSAA, AND TODD SMITH ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUSS, USIT, TODD OR OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00016 */
00017 
00018 
00031 #include "AEngine.h"
00032 #include "AState.h"
00033 #include "AConstants.h"
00034 #include "ADevice.h"
00035 #include "ASharedFunc.h"
00036 
00037 //------------------------------------------------------------------------------------
00038 inline __int64 getOSTime()
00039 {
00040         __int64 time;
00041         int *dest_low  = (int*) (&time);
00042         int *dest_high = dest_low + 1;  
00043 
00044         __asm
00045         {
00046                 rdtsc;
00047                 mov             ebx,    dest_low;
00048                 mov             ecx,    dest_high;
00049                 mov             [ebx],  eax;
00050                 mov             [ecx],  edx;
00051         }
00052 
00053         return time;
00054 }
00055 //------------------------------------------------------------------------------------
00056 void profiler_begin(string s)
00057 {
00058         map<string,__int64>::iterator iter;
00059         iter = AS.profiler_startTime.find(s);
00060         if( iter==AS.profiler_startTime.end() )         // if this is the first time we come across this name
00061         {
00062                 AS.profiler_startTime[s] = getOSTime();
00063                 AS.profiler_totalTime[s] = 0;           
00064                 AS.profiler_names.push_back(s);
00065         }
00066         else
00067         {
00068                 AS.profiler_startTime[s] = getOSTime();
00069         }
00070 }
00071 //------------------------------------------------------------------------------------
00072 void profiler_end(string s)
00073 {
00074         map<string,__int64>::iterator iter;
00075         iter = AS.profiler_totalTime.find(s);
00076         if( iter==AS.profiler_totalTime.end() )
00077         {
00078                 throw Error("Profiler_end("+s+")  not preceded by Profiler_begin");
00079         }
00080         else
00081         {
00082                 iter->second += getOSTime() - AS.profiler_startTime.find(s)->second;            
00083         }
00084 }
00085 //------------------------------------------------------------------------------------
00086 void profiler_reset()
00087 {
00088         for( UINT i=0; i<AS.profiler_names.size(); i++ )
00089                 AS.profiler_totalTime.find( AS.profiler_names[i] )->second = 0;
00090         AS.profiler_RDTSClastReset = getOSTime();
00091         AS.profiler_MSlastReset    = sys_getMilliSec();
00092 }
00093 //------------------------------------------------------------------------------------
00094 void profiler_render()
00095 {
00096         sys_console() << "-------BEGIN-PROFILER-SUMMARY-------" << endl;
00097         __int64 t = getOSTime();
00098         __int64 deltaT = t - AS.profiler_RDTSClastReset;
00099         for( UINT i=0; i<AS.profiler_names.size(); i++ )
00100         {
00101                 string s = AS.profiler_names[i];
00102                 FLOAT percent = AS.profiler_totalTime.find(s)->second * 100.0f / deltaT;
00103                 while( s.length()<24 ) s += " ";                
00104                 sys_console() << s << percent << endl;
00105         }
00106 }
00107 //------------------------------------------------------------------------------------

Generated on Wed Apr 23 05:50:13 2003 for Modern Warfare by doxygen1.3-rc2