网站首页  词典首页

请输入您要查询的函数:

 

术语 pdhcollectquerydataex
释义 PdhCollectQueryDataEx
语法:
C++
PDH_STATUS PdhCollectQueryDataEx(
__in PDH_HQUERY hQuery,
__in DWORD dwIntervalTime,
__in HANDLE hNewDataEvent
);
PdhCollectQueryDataEx功能
使用一个单独的线程来收集当前的原料在指定的查询所有计数器的数据值。然后函数信号的应用程序定义的事件和等待,然后返回在指定的时间间隔。
参数
hQuery [in]
处理查询。查询标识计数器,您要收集。该PdhOpenQuery函数返回此句柄。
dwIntervalTime [in]
等待时间间隔,以秒。
hNewDataEvent [in]
在事件处理您想要的PDH的信号的时间间隔后到期。要创建一个事件对象,调用CreateEvent函数。
返回值
如果函数成功,它返回ERROR_SUCCESS。
如果函数失败,返回值是一个系统错误代码或一种PDH错误代码。以下是可能的值。
返回codeDescription
PDH_INVALID_HANDLEThe查询处理是无效的。
PDH_NO_DATAThe查询目前还没有任何柜台。
备注
光端机终止线程当您调用PdhCloseQuery功能。如果您调用PdhCollectQueryDataEx超过一次,以后每次调用终止从以前的调用线程,然后启动一个新线程。
当PdhCollectQueryDataEx的要求,例如从一个柜台只计数器实例不存在,函数返回PDH_NO_DATA数据。但是,如果从多个计数器数据查询,PdhCollectQueryDataEx可能会返回计数器实例ERROR_SUCCESS即使还不存在。这是因为它不知道如果指定的计数器实例不存在,或是否会存在,但尚未建立。在这种情况下,要求利益的计数器实例每个PdhGetRawCounterValue或PdhGetFormattedCounterValue以确定它们是否存在。
光端机存储原始计数器值为当前和以前的集合。如果您想检索当前原料计数器的值,调用PdhGetRawCounterValue功能。如果您想计算的计数器值显示的值,调用PdhGetFormattedCounterValue。如果计数器路径中包含一个实例名通配符,而不是调用PdhGetRawCounterArray和PdhGetFormattedCounterArray职能分别。
实例
下面的示例显示了如何使用此功能。
#define UNICODE
#include
#include
#include
#include
#pragma comment(lib, "pdh.lib")
CONST PWSTR COUNTER_NAME = L"\\\\Processor(0)\\\\% Processor Time";
CONST ULONG SAMPLE_COUNT = 10;
CONST ULONG SAMPLE_INTERVAL = 2;
void wmain(void)
{
PDH_STATUS Status;
HANDLE Event = NULL;
PDH_HQUERY Query = NULL;
PDH_HCOUNTER Counter;
ULONG WaitResult;
ULONG CounterType;
PDH_FMT_COUNTERVALUE DisplayValue;
Status = PdhOpenQuery(NULL, 0, &Query);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhOpenQuery failed with status 0x%x.", Status);
goto Cleanup;
}
Status = PdhAddCounter(Query, COUNTER_NAME, 0, &Counter);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhAddCounter failed with 0x%x.", Status);
goto Cleanup;
}
//
// Calculating the formatted value of some counters requires access to the
// value of a previous sample. Make this call to get the first sample value
// populated, to be used later for calculating the next sample.
//
Status = PdhCollectQueryData(Query);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhCollectQueryData failed with status 0x%x.", Status);
goto Cleanup;
}
//
// This will create a separate thread that will collect raw counter data
// every 2 seconds and set the supplied Event.
//
Event = CreateEvent(NULL, FALSE, FALSE, L"MyEvent");
if (Event == NULL)
{
wprintf(L"\\nCreateEvent failed with status 0x%x.", GetLastError());
goto Cleanup;
}
Status = PdhCollectQueryDataEx(Query, SAMPLE_INTERVAL, Event);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhCollectQueryDataEx failed with status 0x%x.", Status);
goto Cleanup;
}
//
// Collect and format 10 samples, 2 seconds apart.
//
for (ULONG i = 0; i < SAMPLE_COUNT; i++)
{
WaitResult = WaitForSingleObject(Event, INFINITE);
if (WaitResult == WAIT_OBJECT_0)
{
Status = PdhGetFormattedCounterValue(Counter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
if (Status == ERROR_SUCCESS)
{
wprintf(L"\\nCounter Value: %.20g", DisplayValue.doubleValue);
}
else
{
wprintf(L"\\nPdhGetFormattedCounterValue failed with status 0x%x.", Status);
goto Cleanup;
}
}
else if (WaitResult == WAIT_FAILED)
{
wprintf(L"\\nWaitForSingleObject failed with status 0x%x.", GetLastError());
goto Cleanup;
}
}
Cleanup:
if (Event)
{
CloseHandle(Event);
}
//
// This will close both the Query handle and all associated Counter handles
// returned by PdhAddCounter.
//
if (Query)
{
PdhCloseQuery(Query);
}
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderPdh.h
LibraryPdh.lib
DLLPdh.dll
参见
PdhCollectQueryData
PdhOpenQuery
CreateEvent
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月23日
==英文原文==PdhCollectQueryDataEx Function
Uses a separate thread to collect the current raw data value for all counters in the specified query. The function then signals the application-defined event and waits the specified time interval before returning.
Syntax
C++
PDH_STATUS PdhCollectQueryDataEx(
__in PDH_HQUERY hQuery,
__in DWORD dwIntervalTime,
__in HANDLE hNewDataEvent
);
Parameters
hQuery [in]
Handle of the query. The query identifies the counters that you want to collect. The PdhOpenQuery function returns this handle.
dwIntervalTime [in]
Time interval to wait, in seconds.
hNewDataEvent [in]
Handle to the event that you want PDH to signal after the time interval expires. To create an event object, call the CreateEvent function.
Return Value
If the function succeeds, it returns ERROR_SUCCESS.
If the function fails, the return value is a system error code or a PDH error code . The following are possible values.
Return codeDescription
PDH_INVALID_HANDLEThe query handle is not valid.
PDH_NO_DATAThe query does not currently have any counters.

Remarks
PDH terminates the thread when you call the PdhCloseQuery function. If you call PdhCollectQueryDataEx more than once, each subsequent call terminates the thread from the previous call and then starts a new thread.
When PdhCollectQueryDataEx is called for data from one counter instance only and the counter instance does not exist, the function returns PDH_NO_DATA. However, if data from more than one counter is queried, PdhCollectQueryDataEx may return ERROR_SUCCESS even if one of the counter instances does not yet exist. This is because it is not known if the specified counter instance does not exist, or if it will exist but has not yet been created. In this case, call PdhGetRawCounterValue or PdhGetFormattedCounterValue for each of the counter instances of interest to determine whether they exist.
PDH stores the raw counter values for the current and previous collection. If you want to retrieve the current raw counter value, call the PdhGetRawCounterValue function. If you want to compute a displayable value for the counter value, call the PdhGetFormattedCounterValue. If the counter path contains a wildcard for the instance name, instead call the PdhGetRawCounterArray and PdhGetFormattedCounterArray functions, respectively.
Examples
The following example shows how to use this function.
#define UNICODE
#include
#include
#include
#include
#pragma comment(lib, "pdh.lib")
CONST PWSTR COUNTER_NAME = L"\\\\Processor(0)\\\\% Processor Time";
CONST ULONG SAMPLE_COUNT = 10;
CONST ULONG SAMPLE_INTERVAL = 2;
void wmain(void)
{
PDH_STATUS Status;
HANDLE Event = NULL;
PDH_HQUERY Query = NULL;
PDH_HCOUNTER Counter;
ULONG WaitResult;
ULONG CounterType;
PDH_FMT_COUNTERVALUE DisplayValue;
Status = PdhOpenQuery(NULL, 0, &Query);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhOpenQuery failed with status 0x%x.", Status);
goto Cleanup;
}
Status = PdhAddCounter(Query, COUNTER_NAME, 0, &Counter);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhAddCounter failed with 0x%x.", Status);
goto Cleanup;
}
//
// Calculating the formatted value of some counters requires access to the
// value of a previous sample. Make this call to get the first sample value
// populated, to be used later for calculating the next sample.
//
Status = PdhCollectQueryData(Query);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhCollectQueryData failed with status 0x%x.", Status);
goto Cleanup;
}
//
// This will create a separate thread that will collect raw counter data
// every 2 seconds and set the supplied Event.
//
Event = CreateEvent(NULL, FALSE, FALSE, L"MyEvent");
if (Event == NULL)
{
wprintf(L"\\nCreateEvent failed with status 0x%x.", GetLastError());
goto Cleanup;
}
Status = PdhCollectQueryDataEx(Query, SAMPLE_INTERVAL, Event);
if (Status != ERROR_SUCCESS)
{
wprintf(L"\\nPdhCollectQueryDataEx failed with status 0x%x.", Status);
goto Cleanup;
}
//
// Collect and format 10 samples, 2 seconds apart.
//
for (ULONG i = 0; i < SAMPLE_COUNT; i++)
{
WaitResult = WaitForSingleObject(Event, INFINITE);
if (WaitResult == WAIT_OBJECT_0)
{
Status = PdhGetFormattedCounterValue(Counter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
if (Status == ERROR_SUCCESS)
{
wprintf(L"\\nCounter Value: %.20g", DisplayValue.doubleValue);
}
else
{
wprintf(L"\\nPdhGetFormattedCounterValue failed with status 0x%x.", Status);
goto Cleanup;
}
}
else if (WaitResult == WAIT_FAILED)
{
wprintf(L"\\nWaitForSingleObject failed with status 0x%x.", GetLastError());
goto Cleanup;
}
}
Cleanup:
if (Event)
{
CloseHandle(Event);
}
//
// This will close both the Query handle and all associated Counter handles
// returned by PdhAddCounter.
//
if (Query)
{
PdhCloseQuery(Query);
}
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderPdh.h
LibraryPdh.lib
DLLPdh.dll
See Also
PdhCollectQueryData
PdhOpenQuery
CreateEvent
Send comments about this topic to Microsoft
Build date: 7/23/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa372566(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:22:43