网站首页  词典首页

请输入您要查询的函数:

 

术语 pdhgetformattedcounterarray
释义 PdhGetFormattedCounterArray
语法:
C++
PDH_STATUS PdhGetFormattedCounterArray(
__in PDH_HCOUNTER hCounter,
__in DWORD dwFormat,
__inout LPDWORD lpdwBufferSize,
__out LPDWORD lpdwBufferCount,
__out PPDH_FMT_COUNTERVALUE_ITEM ItemBuffer
);
PdhGetFormattedCounterArray功能
返回格式化的计数器值的数组。使用此功能时,要设置格式的一个计数器,包含一个实例名称通配符计数器值。
参数
hCounter [in]
句柄计数器的当前值要设置格式。该PdhAddCounter函数返回此句柄。
dwFormat [in]
决定了格式化值的数据类型。指定下列值之一。
ValueMeaning
作为一个双精度浮点真正PDH_FMT_DOUBLEReturn数据。
作为一个64位整数PDH_FMT_LARGEReturn数据。
作为一个长整型PDH_FMT_LONGReturn数据。
您可以使用按位包容性的OR运算符(|)来组合与下列因素之一缩放的数据类型。
ValueMeaning
PDH_FMT_NOSCALEDo不适用于计数器的默认缩放因子。
PDH_FMT_NOCAP100Counter值大于100(例如,计数器值衡量处理器的多处理器计算机上的负载)将不会被重置为100。默认行为是计数器的值是在100值上限。
PDH_FMT_1000Multiply由1000的实际价值。
lpdwBufferSize [ in , out ]
的大小ItemBuffer缓冲区,以字节为单位。如果零输入,该函数返回PDH_MORE_DATA,并设置此参数所需的缓冲区大小。如果缓冲区比所需的大小,功能设置此参数的时候,往往有人使用的缓冲区的实际大小。如果在输入指定的大小是大于零,但比所需的大小少,您不应该依靠返回的大小重新分配缓冲区。
lpdwBufferCount [out]
数在ItemBuffer缓冲区计数器值。
ItemBuffer [out]
来电分配的缓冲区,它接收的PDH_FMT_COUNTERVALUE_ITEM结构的数组,该结构包含计数器的值。设置为NULL,如果lpdwBufferSize是零。
返回值
如果函数成功,它返回ERROR_SUCCESS。
如果函数失败,返回值是一个系统错误代码或一种PDH错误代码。以下是可能的值。
返回codeDescription
PDH_MORE_DATAThe ItemBuffer缓冲区不够大,无法包含对象的名称。这个返回值,预计如果lpdwBufferSize是在输入为零。如果在输入指定的大小是大于零,但比所需的大小少,您不应该依靠返回的大小重新分配缓冲区。
PDH_INVALID_ARGUMENTA参数无效或格式不正确。例如,在某些版本中您可以收到此错误如果在输入指定的大小是大于零但小于所需的大小。
PDH_INVALID_HANDLEThe计数器句柄无效。
备注
您应该调用这个函数两次,第一次获得所需的缓冲区大小(设置ItemBuffer为NULL和lpdwBufferSize为0),和第二次获取数据。
该计数器的数据被锁定为通话时间,以PdhGetFormattedCounterArray,以防止在呼叫处理的任何变化。
实例
下面的示例显示了如何使用此功能。
#define UNICODE
#include
#include
#include
#include
#pragma comment(lib, "pdh.lib")
CONST PWSTR COUNTER_PATH = L"\\\\Processor(*)\\\\% Processor Time";
CONST ULONG SAMPLE_INTERVAL_MS = 1000;
void main()
{
PDH_HQUERY hQuery = NULL;
PDH_STATUS status = ERROR_SUCCESS;
PDH_HCOUNTER hCounter = NULL;
DWORD dwBufferSize = 0; // Size of the pItems buffer
DWORD dwItemCount = 0; // Number of items in the pItems buffer
PDH_FMT_COUNTERVALUE_ITEM *pItems = NULL; // Array of PDH_FMT_COUNTERVALUE_ITEM structures
if (status = PdhOpenQuery(NULL, 0, &hQuery))
{
wprintf(L"PdhOpenQuery failed with 0x%x.\\n", status);
goto cleanup;
}
// Specify a counter object with a wildcard for the instance.
if (status = PdhAddCounter(hQuery, COUNTER_PATH, 0, &hCounter))
{
wprintf(L"PdhAddCounter failed with 0x%x.\\n", status);
goto cleanup;
}
// Some counters need two sample in order to format a value, so
// make this call to get the first value before entering the loop.
if (status = PdhCollectQueryData(hQuery))
{
wprintf(L"PdhCollectQueryData failed with 0x%x.\\n", status);
goto cleanup;
}
for (int i = 0; i < 10; i++)
{
Sleep(SAMPLE_INTERVAL_MS);
if (status = PdhCollectQueryData(hQuery))
{
wprintf(L"PdhCollectQueryData failed with 0x%x.\\n", status);
goto cleanup;
}
// Get the required size of the pItems buffer.
status = PdhGetFormattedCounterArray(hCounter, PDH_FMT_DOUBLE, &dwBufferSize, &dwItemCount, pItems);
if (PDH_MORE_DATA == status)
{
pItems = (PDH_FMT_COUNTERVALUE_ITEM *) malloc(dwBufferSize);
if (pItems)
{
status = PdhGetFormattedCounterArray(hCounter, PDH_FMT_DOUBLE, &dwBufferSize, &dwItemCount, pItems);
if (ERROR_SUCCESS == status)
{
// Loop through the array and print the instance name and counter value.
for (DWORD i = 0; i < dwItemCount; i++)
{
wprintf(L"counter: %s, value %.20g\\n", pItems[i].szName, pItems[i].FmtValue.doubleValue);
}
}
else
{
wprintf(L"Second PdhGetFormattedCounterArray call failed with 0x%x.\\n", status);
goto cleanup;
}
free(pItems);
pItems = NULL;
dwBufferSize = dwItemCount = 0;
}
else
{
wprintf(L"malloc for PdhGetFormattedCounterArray failed.\\n");
goto cleanup;
}
}
else
{
wprintf(L"PdhGetFormattedCounterArray failed with 0x%x.\\n", status);
goto cleanup;
}
}
cleanup:
if (pItems)
free(pItems);
if (hQuery)
PdhCloseQuery(hQuery); // Closes all counter handles and the query handle
}

要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderPdh.h
LibraryPdh.lib
DLLPdh.dll
Unicode和ANSI namesPdhGetFormattedCounterArrayW(Unicode)和PdhGetFormattedCounterArrayA(ANSI)的
参见
PdhGetFormattedCounterValue
PdhGetRawCounterValue
PdhGetRawCounterArray
PDH_FMT_COUNTERVALUE_ITEM
PdhAddCounter
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月23日
==英文原文==PdhGetFormattedCounterArray Function
Returns an array of formatted counter values. Use this function when you want to format the counter values of a counter that contains a wildcard character for the instance name.
Syntax
C++
PDH_STATUS PdhGetFormattedCounterArray(
__in PDH_HCOUNTER hCounter,
__in DWORD dwFormat,
__inout LPDWORD lpdwBufferSize,
__out LPDWORD lpdwBufferCount,
__out PPDH_FMT_COUNTERVALUE_ITEM ItemBuffer
);
Parameters
hCounter [in]
Handle to the counter whose current value you want to format. The PdhAddCounter function returns this handle.
dwFormat [in]
Determines the data type of the formatted value. Specify one of the following values.
ValueMeaning
PDH_FMT_DOUBLEReturn data as a double-precision floating point real.
PDH_FMT_LARGEReturn data as a 64-bit integer.
PDH_FMT_LONGReturn data as a long integer.

You can use the bitwise inclusive OR operator (|) to combine the data type with one of the following scaling factors.
ValueMeaning
PDH_FMT_NOSCALEDo not apply the counter's default scaling factor.
PDH_FMT_NOCAP100Counter values greater than 100 (for example, counter values measuring the processor load on multiprocessor computers) will not be reset to 100. The default behavior is that counter values are capped at a value of 100.
PDH_FMT_1000Multiply the actual value by 1,000.

lpdwBufferSize [in, out]
Size of the ItemBuffer buffer, in bytes. If zero on input, the function returns PDH_MORE_DATA and sets this parameter to the required buffer size. If the buffer is larger than the required size, the function sets this parameter to the actual size of the buffer that was used. If the specified size on input is greater than zero but less than the required size, you should not rely on the returned size to reallocate the buffer.
lpdwBufferCount [out]
Number of counter values in the ItemBuffer buffer.
ItemBuffer [out]
Caller-allocated buffer that receives an array of PDH_FMT_COUNTERVALUE_ITEM structures; the structures contain the counter values. Set to NULL if lpdwBufferSize is zero.
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_MORE_DATAThe ItemBuffer buffer is not large enough to contain the object name. This return value is expected if lpdwBufferSize is zero on input. If the specified size on input is greater than zero but less than the required size, you should not rely on the returned size to reallocate the buffer.
PDH_INVALID_ARGUMENTA parameter is not valid or is incorrectly formatted. For example, on some releases you could receive this error if the specified size on input is greater than zero but less than the required size.
PDH_INVALID_HANDLEThe counter handle is not valid.

Remarks
You should call this function twice, the first time to get the required buffer size (set ItemBuffer to NULL and lpdwBufferSize to 0), and the second time to get the data.
The data for the counter is locked for the duration of the call to PdhGetFormattedCounterArray to prevent any changes during the processing of the call.
Examples
The following example shows how to use this function.
#define UNICODE
#include
#include
#include
#include
#pragma comment(lib, "pdh.lib")
CONST PWSTR COUNTER_PATH = L"\\\\Processor(*)\\\\% Processor Time";
CONST ULONG SAMPLE_INTERVAL_MS = 1000;
void main()
{
PDH_HQUERY hQuery = NULL;
PDH_STATUS status = ERROR_SUCCESS;
PDH_HCOUNTER hCounter = NULL;
DWORD dwBufferSize = 0; // Size of the pItems buffer
DWORD dwItemCount = 0; // Number of items in the pItems buffer
PDH_FMT_COUNTERVALUE_ITEM *pItems = NULL; // Array of PDH_FMT_COUNTERVALUE_ITEM structures
if (status = PdhOpenQuery(NULL, 0, &hQuery))
{
wprintf(L"PdhOpenQuery failed with 0x%x.\\n", status);
goto cleanup;
}
// Specify a counter object with a wildcard for the instance.
if (status = PdhAddCounter(hQuery, COUNTER_PATH, 0, &hCounter))
{
wprintf(L"PdhAddCounter failed with 0x%x.\\n", status);
goto cleanup;
}
// Some counters need two sample in order to format a value, so
// make this call to get the first value before entering the loop.
if (status = PdhCollectQueryData(hQuery))
{
wprintf(L"PdhCollectQueryData failed with 0x%x.\\n", status);
goto cleanup;
}
for (int i = 0; i < 10; i++)
{
Sleep(SAMPLE_INTERVAL_MS);
if (status = PdhCollectQueryData(hQuery))
{
wprintf(L"PdhCollectQueryData failed with 0x%x.\\n", status);
goto cleanup;
}
// Get the required size of the pItems buffer.
status = PdhGetFormattedCounterArray(hCounter, PDH_FMT_DOUBLE, &dwBufferSize, &dwItemCount, pItems);
if (PDH_MORE_DATA == status)
{
pItems = (PDH_FMT_COUNTERVALUE_ITEM *) malloc(dwBufferSize);
if (pItems)
{
status = PdhGetFormattedCounterArray(hCounter, PDH_FMT_DOUBLE, &dwBufferSize, &dwItemCount, pItems);
if (ERROR_SUCCESS == status)
{
// Loop through the array and print the instance name and counter value.
for (DWORD i = 0; i < dwItemCount; i++)
{
wprintf(L"counter: %s, value %.20g\\n", pItems[i].szName, pItems[i].FmtValue.doubleValue);
}
}
else
{
wprintf(L"Second PdhGetFormattedCounterArray call failed with 0x%x.\\n", status);
goto cleanup;
}
free(pItems);
pItems = NULL;
dwBufferSize = dwItemCount = 0;
}
else
{
wprintf(L"malloc for PdhGetFormattedCounterArray failed.\\n");
goto cleanup;
}
}
else
{
wprintf(L"PdhGetFormattedCounterArray failed with 0x%x.\\n", status);
goto cleanup;
}
}
cleanup:
if (pItems)
free(pItems);
if (hQuery)
PdhCloseQuery(hQuery); // Closes all counter handles and the query handle
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderPdh.h
LibraryPdh.lib
DLLPdh.dll
Unicode and ANSI namesPdhGetFormattedCounterArrayW (Unicode) and PdhGetFormattedCounterArrayA (ANSI)
See Also
PdhGetFormattedCounterValue
PdhGetRawCounterValue
PdhGetRawCounterArray
PDH_FMT_COUNTERVALUE_ITEM
PdhAddCounter
Send comments about this topic to Microsoft
Build date: 7/23/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa372633(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 11:22:45