PROFILE.H 6.9 KB

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