Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

307 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Profile.c
  5. Abstract:
  6. This module contains routines for controling the rudimentary sampling
  7. profiler built into the profiling version of Ntvdm.
  8. Author:
  9. Dave Hastings (daveh) 31-Jul-1992
  10. Notes:
  11. The routines in this module assume that the pointers to the ntsd
  12. routines have already been set up.
  13. Revision History:
  14. --*/
  15. #include <precomp.h>
  16. #pragma hdrstop
  17. #include <stdio.h>
  18. VOID
  19. ProfDumpp(
  20. VOID
  21. )
  22. /*++
  23. Routine Description:
  24. This routine causes the profile information to be dumped the next
  25. time ntvdm switches from 32 to 16 bit mode.
  26. Arguments:
  27. Return Value:
  28. None.
  29. Notes:
  30. This routine assumes that the pointers to the ntsd routines have already
  31. been set up.
  32. --*/
  33. {
  34. BOOL Status;
  35. ULONG Address, Flags;
  36. Address = FIXED_NTVDMSTATE_LINEAR;
  37. //
  38. // Get Flags
  39. //
  40. Status = READMEM((PVOID)Address, &Flags, sizeof(ULONG));
  41. if (!Status) {
  42. (ULONG)Address = (*GetExpression)("ntvdm!InitialVdmTibFlags");
  43. Status = READMEM((PVOID)Address, &Flags, sizeof(ULONG));
  44. if (!Status) {
  45. GetLastError();
  46. (*Print)("Could not get InitialVdmTibFlags\n");
  47. return;
  48. }
  49. }
  50. //
  51. // Enable profile dump
  52. //
  53. Flags |= VDM_ANALYZE_PROFILE;
  54. Status = WRITEMEM(
  55. (PVOID)Address,
  56. &Flags,
  57. sizeof(ULONG)
  58. );
  59. if (!Status) {
  60. GetLastError();
  61. (*Print)("Could not set Flags\n");
  62. return;
  63. }
  64. }
  65. VOID
  66. ProfIntp(
  67. VOID
  68. )
  69. /*++
  70. Routine Description:
  71. This routine changes the profile interval the next time profiling is
  72. started.
  73. Arguments:
  74. None.
  75. Return Value:
  76. None.
  77. Notes:
  78. This routine assumes that the pointers to the ntsd routines have already
  79. been set up.
  80. --*/
  81. {
  82. BOOL Status;
  83. ULONG Address, ProfInt;
  84. //
  85. // Get profile interval
  86. //
  87. if (sscanf(lpArgumentString, "%ld", &ProfInt) < 1) {
  88. (*Print)("Profile Interval must be specified\n");
  89. return;
  90. }
  91. //
  92. // Get the address of the profile interval
  93. //
  94. Address = (*GetExpression)(
  95. "ProfInt"
  96. );
  97. if (Address) {
  98. Status = WRITEMEM(
  99. (PVOID)Address,
  100. &ProfInt,
  101. sizeof(ULONG)
  102. );
  103. if (!Status) {
  104. GetLastError();
  105. (*Print)("Could not set profile interval");
  106. }
  107. }
  108. return;
  109. }
  110. VOID
  111. ProfStartp(
  112. VOID
  113. )
  114. /*++
  115. Routine Description:
  116. This routine causes profiling to start the next
  117. time ntvdm switches from 32 to 16 bit mode.
  118. Arguments:
  119. None.
  120. Return Value:
  121. None.
  122. Notes:
  123. This routine assumes that the pointers to the ntsd routines have already
  124. been set up.
  125. --*/
  126. {
  127. BOOL Status;
  128. ULONG Address, Flags;
  129. Address = FIXED_NTVDMSTATE_LINEAR;
  130. //
  131. // Get Flags
  132. //
  133. Status = READMEM(
  134. (PVOID)Address,
  135. &Flags,
  136. sizeof(ULONG)
  137. );
  138. if (!Status) {
  139. (ULONG)Address = (*GetExpression)("ntvdm!InitialVdmTibFlags");
  140. Status = READMEM(
  141. (PVOID)Address,
  142. &Flags,
  143. sizeof(ULONG)
  144. );
  145. if (!Status) {
  146. GetLastError();
  147. (*Print)("Could not get InitialTibflags\n");
  148. return;
  149. }
  150. }
  151. //
  152. // Enable profiling
  153. //
  154. Flags |= VDM_PROFILE;
  155. Status = WRITEMEM(
  156. (PVOID)Address,
  157. &Flags,
  158. sizeof(ULONG)
  159. );
  160. if (!Status) {
  161. GetLastError();
  162. (*Print)("Could not get set Flags\n");
  163. return;
  164. }
  165. }
  166. VOID
  167. ProfStopp(
  168. VOID
  169. )
  170. /*++
  171. Routine Description:
  172. This routine causes profiling to stop the next
  173. time ntvdm switches from 32 to 16 bit mode.
  174. Arguments:
  175. None.
  176. Return Value:
  177. None.
  178. Notes:
  179. This routine assumes that the pointers to the ntsd routines have already
  180. been set up.
  181. --*/
  182. {
  183. BOOL Status;
  184. ULONG Address, Flags;
  185. Address = FIXED_NTVDMSTATE_LINEAR;
  186. //
  187. // Get Flags
  188. //
  189. Status = READMEM((PVOID)Address, &Flags, sizeof(ULONG));
  190. if (!Status) {
  191. (ULONG)Address = (*GetExpression)("ntvdm!InitialVdmTibFlags");
  192. Status = READMEM((PVOID)Address, &Flags, sizeof(ULONG));
  193. if (!Status) {
  194. GetLastError();
  195. (*Print)("Could not get InitialTibflags\n");
  196. return;
  197. }
  198. }
  199. //
  200. // Disable profiling
  201. //
  202. Flags &= ~VDM_PROFILE;
  203. Status = WRITEMEM(
  204. (PVOID)Address,
  205. &Flags,
  206. sizeof(ULONG)
  207. );
  208. if (!Status) {
  209. GetLastError();
  210. (*Print)("Could not get set VDM Flags in DOS arena\n");
  211. return;
  212. }
  213. }