CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

PROFILE.H (7170B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 
     17 /***********************************************************************************************
     18  ***              C O N F I D E N T I A L  ---  W E S T W O O D  S T U D I O S               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Library profiler                                             *
     22  *                                                                                             *
     23  *                    File Name : PROFILE.H                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Steve Tall                                                   *
     26  *                                                                                             *
     27  *                   Start Date : 11/17/95                                                     *
     28  *                                                                                             *
     29  *                  Last Update : November 20th 1995 [ST]                                      *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Overview:                                                                                   *
     33  *                                                                                             *
     34  *  New System                                                                                 *
     35  * ~~~~~~~~~~~                                                                                 *
     36  *                                                                                             *
     37  *  The new profiler system creates a seperate thread and then starts a timer off there. The   *
     38  *  timer in the second thread uses GetThreadContext to sample the IP address of each user     *
     39  *  thread. This system has the advantage of being able to sample what is happening in all the *
     40  *  threads we own not just the main thread. Another advantage is that it doesnt require a     *
     41  *  major recompilation.                                                                       *
     42  *  The disadvantage is that we dont really know what is going on when the IP is outside the   *
     43  *  scope of our threads - We could be in direct draw, direct sound or even something like the *
     44  *  VMM and there is no way to tell.                                                           *
     45  *                                                                                             *
     46  *                                                                                             *
     47  *                                                                                             *
     48  *  Old System                                                                                 *
     49  * ~~~~~~~~~~~                                                                                 *
     50  *                                                                                             *
     51  *  The profiler works by using the function prologue and epilogue hooks available in Watcom   *
     52  *  to register the current functions address in a global variable and then sampling the       *
     53  *  contents of the variable using a windows timer which runs at up to 1000 samples per second.*
     54  *                                                                                             *
     55  *  Compile the code to be sampled with the -ep and -ee flags to enable the prologue (__PRO)   *
     56  *  and epilogue (__EPI) calls to be generated.                                                *
     57  *  At the beginning of the section to be profiled (just before main loop normally) call the   *
     58  *  Start_Profiler function to start sampling. At the end of the section, call Stop_Profiler   *
     59  *  which will stop the timer and write the profile data to disk in the PROFILE.BIN file.      *
     60  *                                                                                             *
     61  *  Use PROFILE.EXE to view the results of the session.                                        *
     62  *                                                                                             *
     63  *  The addition of prologue and epilogue code will slow down the product and the profiler     *
     64  *  allocates a huge buffer for data so it should not be linked in unless it is going to be    *
     65  *  used.                                                                                      *
     66  *                                                                                             *
     67  *  The advantage of the prologue/epilogue approach is that all samples represent valid        *
     68  *  addresses within our code so we get valid results we can use even when the IP is in system *
     69  *  code.                                                                                      *
     70  *                                                                                             *
     71  *                                                                                             *
     72  *---------------------------------------------------------------------------------------------*
     73  *                                                                                             *
     74  * Functions:                                                                                  *
     75  *                                                                                             *
     76  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     77 
     78 
     79 #define	MAX_PROFILE_TIME	60*1		//1 minute(s) @ 14.4 Mb per hour
     80 #define	PROFILE_RATE		1000	//samples per sec (max 1000)
     81 
     82 
     83 /*
     84  * Defines for choosing between the old and new profiler system
     85  *
     86 */
     87 
     88 #define	OLD_PROFILE_SYSTEM	1
     89 #define	NEW_PROFILE_SYSTEM	2
     90 
     91 //#define	PROFILE_SYSTEM			OLD_PROFILE_SYSTEM
     92 #define	PROFILE_SYSTEM			NEW_PROFILE_SYSTEM
     93 
     94 
     95 
     96 extern "C"{
     97 	void __cdecl Profile_Init(void);
     98 	void __cdecl Profile_End(void);
     99 	void __cdecl Start_Profiler(void);
    100 	void __cdecl Stop_Profiler(void);
    101 }
    102