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.

278 lines
7.2 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. PerfUtil.c
  5. Abstract:
  6. This file implements utility functions for performance monitoring functions
  7. Author:
  8. Eliot Gillum (t-eliotg) - July 5, 1998
  9. Revision History
  10. --*/
  11. #include <windows.h>
  12. #include <winperf.h>
  13. #include "PerfUtil.h"
  14. WCHAR GLOBAL_STRING[] = L"Global";
  15. WCHAR FOREIGN_STRING[] = L"Foreign";
  16. WCHAR COSTLY_STRING[] = L"Costly";
  17. WCHAR NULL_STRING[] = L"\0"; // pointer to null string
  18. // test for delimiter, end of line and non-digit characters
  19. // used by IsNumberInUnicodeList routine
  20. //
  21. #define DIGIT 1
  22. #define DELIMITER 2
  23. #define INVALID 3
  24. #define EvalThisChar(c,d) ( \
  25. (c == d) ? DELIMITER : \
  26. (c == 0) ? DELIMITER : \
  27. (c < (WCHAR)'0') ? INVALID : \
  28. (c > (WCHAR)'9') ? INVALID : \
  29. DIGIT)
  30. // convertIndices()
  31. // Takes a pointer to an array of PERF_COUNTER_DEFINITIONs and converts their indices
  32. // to be absolute by adding the appropriate value (dwFirstCounter/dwFirstHelp)
  33. //
  34. // BYTE *buf Pointer to an array of PERF_COUNTER_DEFINITIONs
  35. // int numCounters The number of PERF_COUNTER_DEFINITIONs to convert
  36. // DWORD dwFirstCounter Absolute index of the first counter in the series
  37. // DWORD dwFirstHelp Absolute index of the first help index in the series
  38. void convertIndices(BYTE *buf, int numCounters, DWORD dwFirstCounter, DWORD dwFirstHelp)
  39. {
  40. int i;
  41. // then the counter indices
  42. for (i=0; i<numCounters; i++) {
  43. ((PERF_COUNTER_DEFINITION *)buf)->CounterNameTitleIndex += dwFirstCounter;
  44. ((PERF_COUNTER_DEFINITION *)buf)->CounterHelpTitleIndex += dwFirstHelp;
  45. buf += sizeof(PERF_COUNTER_DEFINITION);
  46. }
  47. }
  48. DWORD
  49. GetQueryType (
  50. IN LPWSTR lpValue
  51. )
  52. /*++
  53. GetQueryType
  54. returns the type of query described in the lpValue string so that
  55. the appropriate processing method may be used
  56. Arguments
  57. IN lpValue
  58. string passed to PerfRegQuery Value for processing
  59. Return Value
  60. QUERY_GLOBAL
  61. if lpValue == 0 (null pointer)
  62. lpValue == pointer to Null string
  63. lpValue == pointer to "Global" string
  64. QUERY_FOREIGN
  65. if lpValue == pointer to "Foreign" string
  66. QUERY_COSTLY
  67. if lpValue == pointer to "Costly" string
  68. otherwise:
  69. QUERY_ITEMS
  70. --*/
  71. {
  72. WCHAR *pwcArgChar, *pwcTypeChar;
  73. BOOL bFound;
  74. if (lpValue == 0) {
  75. return QUERY_GLOBAL;
  76. } else if (*lpValue == 0) {
  77. return QUERY_GLOBAL;
  78. }
  79. // check for "Global" request
  80. pwcArgChar = lpValue;
  81. pwcTypeChar = GLOBAL_STRING;
  82. bFound = TRUE; // assume found until contradicted
  83. // check to the length of the shortest string
  84. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  85. if (*pwcArgChar++ != *pwcTypeChar++) {
  86. bFound = FALSE; // no match
  87. break; // bail out now
  88. }
  89. }
  90. if (bFound) return QUERY_GLOBAL;
  91. // check for "Foreign" request
  92. pwcArgChar = lpValue;
  93. pwcTypeChar = FOREIGN_STRING;
  94. bFound = TRUE; // assume found until contradicted
  95. // check to the length of the shortest string
  96. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  97. if (*pwcArgChar++ != *pwcTypeChar++) {
  98. bFound = FALSE; // no match
  99. break; // bail out now
  100. }
  101. }
  102. if (bFound) return QUERY_FOREIGN;
  103. // check for "Costly" request
  104. pwcArgChar = lpValue;
  105. pwcTypeChar = COSTLY_STRING;
  106. bFound = TRUE; // assume found until contradicted
  107. // check to the length of the shortest string
  108. while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) {
  109. if (*pwcArgChar++ != *pwcTypeChar++) {
  110. bFound = FALSE; // no match
  111. break; // bail out now
  112. }
  113. }
  114. if (bFound) return QUERY_COSTLY;
  115. // if not Global and not Foreign and not Costly,
  116. // then it must be an item list
  117. return QUERY_ITEMS;
  118. }
  119. BOOL
  120. IsNumberInUnicodeList (
  121. IN DWORD dwNumber,
  122. IN LPWSTR lpwszUnicodeList
  123. )
  124. /*++
  125. IsNumberInUnicodeList
  126. Arguments:
  127. IN dwNumber
  128. DWORD number to find in list
  129. IN lpwszUnicodeList
  130. Null terminated, Space delimited list of decimal numbers
  131. Return Value:
  132. TRUE: dwNumber was found in the list of unicode number strings
  133. FALSE: dwNumber was not found in the list.
  134. --*/
  135. {
  136. DWORD dwThisNumber;
  137. WCHAR *pwcThisChar;
  138. BOOL bValidNumber;
  139. BOOL bNewItem;
  140. BOOL bReturnValue;
  141. WCHAR wcDelimiter; // could be an argument to be more flexible
  142. if (lpwszUnicodeList == 0) return FALSE; // null pointer, # not found
  143. pwcThisChar = lpwszUnicodeList;
  144. dwThisNumber = 0;
  145. wcDelimiter = (WCHAR)' ';
  146. bValidNumber = FALSE;
  147. bNewItem = TRUE;
  148. while (TRUE) {
  149. switch (EvalThisChar (*pwcThisChar, wcDelimiter)) {
  150. case DIGIT:
  151. // if this is the first digit after a delimiter, then
  152. // set flags to start computing the new number
  153. if (bNewItem) {
  154. bNewItem = FALSE;
  155. bValidNumber = TRUE;
  156. }
  157. if (bValidNumber) {
  158. dwThisNumber *= 10;
  159. dwThisNumber += (*pwcThisChar - (WCHAR)'0');
  160. }
  161. break;
  162. case DELIMITER:
  163. // a delimiter is either the delimiter character or the
  164. // end of the string ('\0') if when the delimiter has been
  165. // reached a valid number was found, then compare it to the
  166. // number from the argument list. if this is the end of the
  167. // string and no match was found, then return.
  168. //
  169. if (bValidNumber) {
  170. if (dwThisNumber == dwNumber) return TRUE;
  171. bValidNumber = FALSE;
  172. }
  173. if (*pwcThisChar == 0) {
  174. return FALSE;
  175. } else {
  176. bNewItem = TRUE;
  177. dwThisNumber = 0;
  178. }
  179. break;
  180. case INVALID:
  181. // if an invalid character was encountered, ignore all
  182. // characters up to the next delimiter and then start fresh.
  183. // the invalid number is not compared.
  184. bValidNumber = FALSE;
  185. break;
  186. default:
  187. break;
  188. }
  189. pwcThisChar++;
  190. }
  191. } // IsNumberInUnicodeList
  192. VOID
  193. CorrectInstanceName(PWCHAR IfcName)
  194. {
  195. WCHAR SpecialChars[] = L")(#\\/";
  196. int k;
  197. int r;
  198. WCHAR *p;
  199. //
  200. // perfmon does not allow the following characters in the name. We need to munge the name
  201. // and replace them with some other character.
  202. //
  203. for(r=0; SpecialChars[r]; r++)
  204. {
  205. p = IfcName;
  206. while((p = wcschr(p, SpecialChars[r])))
  207. {
  208. *p = L'-';
  209. }
  210. }
  211. }