📄 perfgen.cpp
字号:
size = sizeof (DWORD);
status = RegQueryValueEx(
hKeyDriverPerf,
"First Counter",
0L,
&type,
(LPBYTE)&dwFirstCounter,
&size);
if (status != ERROR_SUCCESS) {
REPORT_ERROR_DATA (GENPERF_UNABLE_READ_FIRST_COUNTER, LOG_USER,
&status, sizeof(status));
// this is fatal, if we can't get the base values of the
// counter or help names, then the names won't be available
// to the requesting application so there's not much
// point in continuing.
goto OpenExitPoint;
}
size = sizeof (DWORD);
status = RegQueryValueEx(
hKeyDriverPerf,
"First Help",
0L,
&type,
(LPBYTE)&dwFirstHelp,
&size);
if (status != ERROR_SUCCESS) {
REPORT_ERROR_DATA (GENPERF_UNABLE_READ_FIRST_HELP, LOG_USER,
&status, sizeof(status));
// this is fatal, if we can't get the base values of the
// counter or help names, then the names won't be available
// to the requesting application so there's not much
// point in continuing.
goto OpenExitPoint;
}
//
// NOTE: the initialization program could also retrieve
// LastCounter and LastHelp if they wanted to do
// bounds checking on the new number. e.g.
//
// counter->CounterNameTitleIndex += dwFirstCounter;
// if (counter->CounterNameTitleIndex > dwLastCounter) {
// LogErrorToEventLog (INDEX_OUT_OF_BOUNDS);
// }
//--------------------------------------------------------------
// TODO: Set the data definition values
//--------------------------------------------------------------
CE_TickStats_DataDefinition.CETickStatsObjectType.ObjectNameTitleIndex += dwFirstCounter;
CE_TickStats_DataDefinition.CETickStatsObjectType.ObjectHelpTitleIndex += dwFirstHelp;
// assign index of default counter (Sine Wave)
CE_TickStats_DataDefinition.CETickStatsObjectType.DefaultCounter = 0;
//--------------------------------------------------------------
// TODO: Add one pair of definitions for each *def variable in
// Data Definition (datagen.h)
//--------------------------------------------------------------
CE_TickStats_DataDefinition.TickCountDef.CounterNameTitleIndex += dwFirstCounter;
CE_TickStats_DataDefinition.TickCountDef.CounterHelpTitleIndex += dwFirstHelp;
RegCloseKey (hKeyDriverPerf); // close key to registry
bInitOK = TRUE; // ok to use this function
}
InitializeRemoteData();
dwOpenCount++; // increment OPEN counter
status = ERROR_SUCCESS; // for successful exit
OpenExitPoint:
return status;
}
//----------------------------------------------------------------------
// TODO: This is the Collect function.
//----------------------------------------------------------------------
DWORD APIENTRY
CollectCETickStats(
IN LPWSTR lpValueName,
IN OUT LPVOID *lppData,
IN OUT LPDWORD lpcbTotalBytes,
IN OUT LPDWORD lpNumObjectTypes
)
/*++
Routine Description:
This routine will return the data for the Signal Generator counters.
Arguments:
IN LPWSTR lpValueName
pointer to a wide character string passed by registry.
IN OUT LPVOID *lppData
IN: pointer to the address of the buffer to receive the completed
PerfDataBlock and subordinate structures. This routine will
append its data to the buffer starting at the point referenced
by *lppData.
OUT: points to the first byte after the data structure added by this
routine. This routine updated the value at lppdata after appending
its data.
IN OUT LPDWORD lpcbTotalBytes
IN: the address of the DWORD that tells the size in bytes of the
buffer referenced by the lppData argument
OUT: the number of bytes added by this routine is writted to the
DWORD pointed to by this argument
IN OUT LPDWORD NumObjectTypes
IN: the address of the DWORD to receive the number of objects added
by this routine
OUT: the number of objects added by this routine is writted to the
DWORD pointed to by this argument
Return Value:
ERROR_MORE_DATA if buffer passed is too small to hold data
any error conditions encountered are reported to the event log if
event logging is enabled.
ERROR_SUCCESS if success or any other error. Errors, however are
also reported to the event log.
--*/
{
// Variables for reformating the data
ULONG SpaceNeeded;
DWORD dwQueryType;
//------------------------------------------------------------------
// TODO: Create a pointer to a data definition structure and counter
//------------------------------------------------------------------
CE_TICKSTATS_DATA_DEFINITION *pCE_TickStats_DataDefinition;
CE_TICK_COUNTER * pTickCounter;
static TICK_STATS TickStats = {0};
//
// before doing anything else, see if Open went OK
//
if (!bInitOK ) {
// unable to continue because open failed.
*lpcbTotalBytes = (DWORD) 0;
*lpNumObjectTypes = (DWORD) 0;
return ERROR_SUCCESS; // yes, this is a successful exit
}
// see if this is a foreign (i.e. non-NT) computer data request
//
dwQueryType = GetQueryType (lpValueName);
if (dwQueryType == QUERY_FOREIGN) {
// this routine does not service requests for data from
// Non-NT computers
*lpcbTotalBytes = (DWORD) 0;
*lpNumObjectTypes = (DWORD) 0;
return ERROR_SUCCESS;
}
if (dwQueryType == QUERY_ITEMS){
//------------------------------------------------------------------
// TODO: Replace this with reference to the data definition structure
//------------------------------------------------------------------
if ( !(IsNumberInUnicodeList (CE_TickStats_DataDefinition.CETickStatsObjectType.ObjectNameTitleIndex, lpValueName))) {
// request received for data object not provided by this routine
*lpcbTotalBytes = (DWORD) 0;
*lpNumObjectTypes = (DWORD) 0;
return ERROR_SUCCESS;
}
}
//------------------------------------------------------------------
// TODO: Replace these with reference to the data definition structure
//------------------------------------------------------------------
pCE_TickStats_DataDefinition = (CE_TICKSTATS_DATA_DEFINITION *) *lppData;
SpaceNeeded = sizeof(CE_TICKSTATS_DATA_DEFINITION) + sizeof(CE_TICK_COUNTER);
/* ~gs (NUM_INSTANCES * (sizeof(PERF_INSTANCE_DEFINITION) +
(24) + // size of instance names
sizeof (CE_TICK_COUNTER)));
*/
if ( *lpcbTotalBytes < SpaceNeeded ) {
*lpcbTotalBytes = (DWORD) 0;
*lpNumObjectTypes = (DWORD) 0;
return ERROR_MORE_DATA;
}
//
// Copy the (constant, initialized) Object Type and counter definitions
// to the caller's data buffer
//
//------------------------------------------------------------------
// TODO: Replace these with reference to the data definition structure
//------------------------------------------------------------------
memmove(pCE_TickStats_DataDefinition,
&CE_TickStats_DataDefinition,
sizeof(CE_TICKSTATS_DATA_DEFINITION));
//------------------------------------------------------------------
// TODO: Replace these with reference to the data definition structure
//------------------------------------------------------------------
pTickCounter = (CE_TICK_COUNTER *)((LPBYTE)(*lppData) + sizeof(CE_TICKSTATS_DATA_DEFINITION));
//------------------------------------------------------------------
// TODO: CAll the function that gets the data from the device
//------------------------------------------------------------------
// Get the data
HRESULT hr = GetTickPerf(&TickStats);
if(FAILED(hr))
{
return hr;
}
//------------------------------------------------------------------
// TODO: Replace these with reference to the counter structure
//------------------------------------------------------------------
pTickCounter->CounterBlock.ByteLength = sizeof(CE_TICK_COUNTER);
pTickCounter->dwTickCount = TickStats.dwTickCount;
// update arguments for return
//------------------------------------------------------------------
// TODO: Replace this with reference to the counter structure
//------------------------------------------------------------------
*((LPBYTE*)lppData) += sizeof(CE_TICKSTATS_DATA_DEFINITION) + sizeof(CE_TICK_COUNTER);
*lpNumObjectTypes = 1;
//------------------------------------------------------------------
// TODO: Replace this with reference to the counter structure
//------------------------------------------------------------------
*lpcbTotalBytes = sizeof(CE_TICKSTATS_DATA_DEFINITION) + sizeof(CE_TICK_COUNTER);
//------------------------------------------------------------------
// TODO: Replace this with reference to the data definition structure
//------------------------------------------------------------------
pCE_TickStats_DataDefinition->CETickStatsObjectType.TotalByteLength = *lpcbTotalBytes ;
//------------------------------------------------------------------
// TODO: Replace this with reference to the data definition structure
//------------------------------------------------------------------
// update instance count
pCE_TickStats_DataDefinition->CETickStatsObjectType.NumInstances = PERF_NO_INSTANCES;
return ERROR_SUCCESS;
}
//----------------------------------------------------------------------
// TODO: This is the Close function
//----------------------------------------------------------------------
DWORD APIENTRY
CloseCETickStats(
)
/*++
Routine Description:
This routine closes the open handles to the Signal Gen counters.
Arguments:
None.
Return Value:
ERROR_SUCCESS
--*/
{
if (!(--dwOpenCount)) { // when this is the last thread...
MonCloseEventLog();
}
UninitializeRemoteData();
return ERROR_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -