PROFILE.H 7.0 KB

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