Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

perfutil.c File Reference

#include <windows.h>
#include <string.h>
#include <winperf.h>
#include "userctrs.h"
#include "perfmsg.h"
#include "perfutil.h"
#include "userdata.h"

Go to the source code of this file.

Defines

#define INITIAL_SIZE   1024L
#define EXTEND_SIZE   1024L
#define DIGIT   1
#define DELIMITER   2
#define ENDOFSTRING   3
#define INVALID   4
#define EvalThisChar(c, d)

Functions

HANDLE MonOpenEventLog ()
VOID MonCloseEventLog ()
DWORD GetQueryType (IN LPWSTR lpValue)
DWORD IsNumberInUnicodeList (IN LPWSTR lpwszUnicodeList)

Variables

ULONG ulInfoBufferSize = 0
HANDLE hEventLog = NULL
DWORD dwLogUsers = 0
DWORD MESSAGE_LEVEL = 0
WCHAR GLOBAL_STRING [] = L"Global"
WCHAR FOREIGN_STRING [] = L"Foreign"
WCHAR COSTLY_STRING [] = L"Costly"
WCHAR NULL_STRING [] = L"\0"
USER_DATA_DEFINITION UserDataDefinition
CS_DATA_DEFINITION CSDataDefinition


Define Documentation

#define DELIMITER   2
 

Definition at line 55 of file perfutil.c.

Referenced by IsNumberInUnicodeList().

#define DIGIT   1
 

Definition at line 54 of file perfutil.c.

Referenced by IsNumberInUnicodeList().

#define ENDOFSTRING   3
 

Definition at line 56 of file perfutil.c.

Referenced by IsNumberInUnicodeList().

#define EvalThisChar c,
 ) 
 

Value:

( \ (c == d) ? DELIMITER : \ (c == 0) ? ENDOFSTRING : \ (c < (WCHAR)'0') ? INVALID : \ (c > (WCHAR)'9') ? INVALID : \ DIGIT)

Definition at line 58 of file perfutil.c.

Referenced by IsNumberInUnicodeList().

#define EXTEND_SIZE   1024L
 

Definition at line 27 of file perfutil.c.

#define INITIAL_SIZE   1024L
 

Definition at line 26 of file perfutil.c.

#define INVALID   4
 

Definition at line 57 of file perfutil.c.


Function Documentation

DWORD GetQueryType IN LPWSTR  lpValue  ) 
 

Definition at line 151 of file perfutil.c.

References BOOL, COSTLY_STRING, DWORD, FALSE, FOREIGN_STRING, GLOBAL_STRING, QUERY_COSTLY, QUERY_FOREIGN, QUERY_GLOBAL, QUERY_ITEMS, and TRUE.

Referenced by CollectUserPerformanceData().

00154 : 00155 Returns the type of query described in the lpValue string so that 00156 the appropriate processing method may be used 00157 00158 Arguments 00159 IN lpValue 00160 string passed to PerfRegQuery Value for processing 00161 00162 Return Value 00163 00164 QUERY_GLOBAL if lpValue == 0 (null pointer) 00165 lpValue == pointer to Null string 00166 lpValue == pointer to "Global" string 00167 QUERY_FOREIGN 00168 if lpValue == pointer to "Foreign" string 00169 QUERY_COSTLY 00170 if lpValue == pointer to "Costly" string 00171 otherwise: 00172 00173 QUERY_ITEMS 00174 00175 --*/ 00176 00177 { 00178 WCHAR *pwcArgChar, *pwcTypeChar; 00179 BOOL bFound; 00180 if (lpValue == 0) { 00181 return QUERY_GLOBAL; 00182 } 00183 else if (*lpValue == 0) { 00184 return QUERY_GLOBAL; 00185 } 00186 00187 // check for "Global" request 00188 pwcArgChar = lpValue; 00189 pwcTypeChar = GLOBAL_STRING; 00190 bFound = TRUE; // assume found until contradicted 00191 00192 // check to the length of the shortest string 00193 while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) { 00194 if (*pwcArgChar++ != *pwcTypeChar++) { 00195 bFound = FALSE; // no match 00196 break; // bail out now 00197 } 00198 } 00199 if (bFound) return QUERY_GLOBAL; 00200 00201 // check for "Foreign" request 00202 pwcArgChar = lpValue; 00203 pwcTypeChar = FOREIGN_STRING; 00204 bFound = TRUE; // assume found until contradicted 00205 00206 // check to the length of the shortest string 00207 while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) { 00208 if (*pwcArgChar++ != *pwcTypeChar++) { 00209 bFound = FALSE; // no match 00210 break; // bail out now 00211 } 00212 } 00213 if (bFound) return QUERY_FOREIGN; 00214 00215 // check for "Costly" request 00216 pwcArgChar = lpValue; 00217 pwcTypeChar = COSTLY_STRING; 00218 bFound = TRUE; // assume found until contradicted 00219 00220 // check to the length of the shortest string 00221 while ((*pwcArgChar != 0) && (*pwcTypeChar != 0)) { 00222 if (*pwcArgChar++ != *pwcTypeChar++) { 00223 bFound = FALSE; // no match 00224 break; // bail out now 00225 } 00226 } 00227 if (bFound) return QUERY_COSTLY; 00228 00229 // if not Global and not Foreign and not Costly, 00230 // then it must be an item list 00231 00232 return QUERY_ITEMS; 00233 }

DWORD IsNumberInUnicodeList IN LPWSTR  lpwszUnicodeList  ) 
 

Definition at line 236 of file perfutil.c.

References BOOL, CSDataDefinition, _CS_DATA_DEFINITION::CSObjectType, DELIMITER, DIGIT, DWORD, ENDOFSTRING, EvalThisChar, FALSE, INVALID, QUERY_CS, QUERY_USER, TRUE, UserDataDefinition, and _USER_DATA_DEFINITION::UserObjectType.

00240 : 00241 When querying counters, the collect function receives a list of Unicode strings 00242 representing object indexes. This function parses the string and returns a bit 00243 combination representing the needed objects. 00244 00245 Arguments: 00246 IN lpwszUnicodeList 00247 Null terminated, space delimited list of decimal numbers 00248 00249 Return Value: 00250 The returned DWORD is a combination of QUERY_USER and QUERY_CS 00251 --*/ 00252 { 00253 DWORD dwThisNumber; 00254 DWORD dwReturnValue; 00255 WCHAR *pwcThisChar; 00256 WCHAR wcDelimiter; 00257 BOOL bValidNumber; 00258 BOOL bNewItem; 00259 00260 if (lpwszUnicodeList == 0) return 0; // null pointer, # not found 00261 00262 pwcThisChar = lpwszUnicodeList; 00263 dwThisNumber = 0; 00264 dwReturnValue = 0; 00265 wcDelimiter = (WCHAR)' '; 00266 bValidNumber = FALSE; 00267 bNewItem = TRUE; 00268 00269 while (TRUE) { 00270 switch (EvalThisChar (*pwcThisChar, wcDelimiter)) { 00271 case DIGIT: 00272 // if this is the first digit after a delimiter, then 00273 // set flags to start computing the new number 00274 if (bNewItem) { 00275 bNewItem = FALSE; 00276 bValidNumber = TRUE; 00277 } 00278 if (bValidNumber) { 00279 dwThisNumber *= 10; 00280 dwThisNumber += (*pwcThisChar - (WCHAR)'0'); 00281 } 00282 break; 00283 case ENDOFSTRING: 00284 case DELIMITER: 00285 // a delimiter is either the delimiter character or the 00286 // end of the string ('\0') if when the delimiter has been 00287 // reached a valid number was found, then compare it to the 00288 // number from the argument list. if this is the end of the 00289 // string and no match was found, then return. 00290 // 00291 if (bValidNumber) { 00292 if (dwThisNumber == UserDataDefinition.UserObjectType.ObjectNameTitleIndex) { 00293 dwReturnValue |= QUERY_USER; 00294 } 00295 else if (dwThisNumber == CSDataDefinition.CSObjectType.ObjectNameTitleIndex) { 00296 dwReturnValue |= QUERY_CS; 00297 } 00298 bValidNumber = FALSE; 00299 } 00300 if (*pwcThisChar == 0) { 00301 return dwReturnValue; 00302 } 00303 else { 00304 bNewItem = TRUE; 00305 dwThisNumber = 0; 00306 } 00307 break; 00308 00309 case INVALID: 00310 // if an invalid character was encountered, ignore all 00311 // characters up to the next delimiter and then start fresh. 00312 // the invalid number is not compared. 00313 bValidNumber = FALSE; 00314 break; 00315 00316 default: 00317 break; 00318 00319 } 00320 pwcThisChar++; 00321 } 00322 00323 } // IsNumberInUnicodeList } // IsNumberInUnicodeList

VOID MonCloseEventLog  ) 
 

Definition at line 131 of file perfutil.c.

References dwLogUsers, hEventLog, LOG_DEBUG, NULL, REPORT_INFORMATION, and VOID().

Referenced by CloseUserPerformanceData().

00133 : 00134 Closes the handle to the event logger if this is the last caller 00135 00136 Arguments: None 00137 00138 Return Value: None 00139 00140 --*/ 00141 { 00142 if (hEventLog != NULL) { 00143 dwLogUsers--; // decrement usage 00144 if (dwLogUsers <= 0) { // and if we're the last, then close up log 00145 REPORT_INFORMATION (UTIL_CLOSING_LOG, LOG_DEBUG); 00146 DeregisterEventSource (hEventLog); 00147 } 00148 } 00149 }

HANDLE MonOpenEventLog  ) 
 

Definition at line 65 of file perfutil.c.

References APP_NAME, dwLogUsers, DWORD, hEventLog, LOG_DEBUG, MESSAGE_LEVEL, MESSAGE_LEVEL_DEFAULT, NULL, and REPORT_INFORMATION.

Referenced by OpenUserPerformanceData().

00067 : 00068 00069 Reads the level of event logging from the registry and opens the 00070 channel to the event logger for subsequent event log entries. 00071 00072 Arguments: 00073 None 00074 00075 Return Value: 00076 Handle to the event log for reporting events. 00077 NULL if open not successful. 00078 --*/ 00079 { 00080 HKEY hAppKey; 00081 TCHAR LogLevelKeyName[] = "SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\PerfLib"; 00082 TCHAR LogLevelValueName[] = "EventLogLevel"; 00083 LONG lStatus; 00084 DWORD dwLogLevel; 00085 DWORD dwValueType; 00086 DWORD dwValueSize; 00087 00088 // if global value of the logging level not initialized or is disabled, 00089 // check the registry to see if it should be updated. 00090 00091 if (!MESSAGE_LEVEL) { 00092 lStatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE, 00093 LogLevelKeyName, 00094 0, 00095 KEY_READ, 00096 &hAppKey); 00097 dwValueSize = sizeof (dwLogLevel); 00098 if (lStatus == ERROR_SUCCESS) { 00099 lStatus = RegQueryValueEx (hAppKey, 00100 LogLevelValueName, 00101 (LPDWORD)NULL, 00102 &dwValueType, 00103 (LPBYTE)&dwLogLevel, 00104 &dwValueSize); 00105 if (lStatus == ERROR_SUCCESS) { 00106 MESSAGE_LEVEL = dwLogLevel; 00107 } 00108 else { 00109 MESSAGE_LEVEL = MESSAGE_LEVEL_DEFAULT; 00110 } 00111 RegCloseKey (hAppKey); 00112 } 00113 else { 00114 MESSAGE_LEVEL = MESSAGE_LEVEL_DEFAULT; 00115 } 00116 } 00117 if (hEventLog == NULL) { 00118 hEventLog = RegisterEventSource ( 00119 (LPTSTR)NULL, // Use Local Machine 00120 APP_NAME); // event log app name to find in registry 00121 if (hEventLog != NULL) { 00122 REPORT_INFORMATION (UTIL_LOG_OPEN, LOG_DEBUG); 00123 } 00124 } 00125 if (hEventLog != NULL) { 00126 dwLogUsers++; // increment count of perfctr log users 00127 } 00128 return (hEventLog); 00129 }


Variable Documentation

WCHAR COSTLY_STRING[] = L"Costly"
 

Definition at line 40 of file perfutil.c.

Referenced by GetQueryType().

CS_DATA_DEFINITION CSDataDefinition
 

Definition at line 47 of file perfutil.c.

DWORD dwLogUsers = 0
 

Definition at line 36 of file perfutil.c.

Referenced by MonCloseEventLog(), and MonOpenEventLog().

WCHAR FOREIGN_STRING[] = L"Foreign"
 

Definition at line 39 of file perfutil.c.

Referenced by GetQueryType().

WCHAR GLOBAL_STRING[] = L"Global"
 

Definition at line 38 of file perfutil.c.

Referenced by GetQueryType().

HANDLE hEventLog = NULL
 

Definition at line 34 of file perfutil.c.

Referenced by MonCloseEventLog(), MonOpenEventLog(), and OpenUserPerformanceData().

DWORD MESSAGE_LEVEL = 0
 

Definition at line 37 of file perfutil.c.

Referenced by MonOpenEventLog().

WCHAR NULL_STRING[] = L"\0"
 

Definition at line 41 of file perfutil.c.

ULONG ulInfoBufferSize = 0
 

Definition at line 33 of file perfutil.c.

USER_DATA_DEFINITION UserDataDefinition
 

Definition at line 46 of file perfutil.c.


Generated on Sat May 15 19:45:02 2004 for test by doxygen 1.3.7