Directly on the code:
#include <windows.h>
#include <stdio.h>
#include <pdh.h>
#include <pdhmsg.h>
#pragma comment (lib, "Pdh.lib")
BOOL Diskiomon ()
{
CONST pwstr Counter_path = L "\\Processor (0) \\% Processor time";
CONST pwstr Counter_path = L "\\Processor (_total) \\% Processor time";
CONST pwstr Counter_path = L "\\Process (*) \\% Processor time";
CONST pwstr Counter_path = L "\\Process (QQ) \\% Processor time";
CONST pwstr counter_path = L " \\PhysicalDisk (_total) \\% Disk time ";
CONST pwstr Counter_path = L "\\PhysicalDisk (_total) \\Current Disk Queue Length";
CONST pwstr Counter_path = L "\\LogicalDisk (_total) \\% free spaces";
Hquery hquery = NULL;
Hcounter hcounter = NULL;
Pdh_status STATUS = ERROR_SUCCESS;
DWORD Dwformat = pdh_fmt_double;
Pdh_fmt_countervalue Itembuffer;
Opens the log file that Writein performance Data to a log file
Example created.
Status = Pdhopenquery (0, 0, &hquery);
if (error_success!= status)
{
wprintf (L "Pdhopenquery failed with 0x%x\n", status);
Goto cleanup;
}
ADD the same counter used when writing the log file.
Status = Pdhaddcounter (Hquery, Counter_path, 0, &hcounter);
if (error_success!= status)
{
if (Pdh_cstatus_no_object = = status)//0xc0000bb8
{
wprintf (L "The specified object is not found on the system.\n");
}
Else
wprintf (L "Pdhaddcounter failed with 0x%x\n", status);
Goto cleanup;
}
Read a performance data record.
Status = Pdhcollectquerydata (Hquery);
if (error_success!= status)
{
wprintf (L "Pdhcollectquerydata failed with 0x%x\n", status);
Goto cleanup;
}
while (error_success = = status)
{
Read the next record
Status = Pdhcollectquerydata (Hquery);
Sleep (100);
if (error_success = = status)
{
Format the performance data record.
Status = Pdhgetformattedcountervalue (Hcounter,
Dwformat,
(Lpdword) Null
&itembuffer);
if (error_success!= status)
{
wprintf (L "Pdhgetformattedcountervalue failed with 0x%x.\n", status);
Goto cleanup;
}
wprintf (L "formatted counter value =%.20g\n", itembuffer.doublevalue);
}
Else
{
if (pdh_no_more_data!= status)
{
wprintf (L "Pdhcollectquerydata failed with 0x%x\n", status);
}
}
}
Cleanup
Close the query.
if (hquery)
Pdhclosequery (Hquery);
return TRUE;
}
Note that it takes time to collect data, and to increase sleep latency, otherwise the collected values are 0 or 1.
===================================================================================================
If the timer is not open, return error 0XC0000BB8
The explanation for this error on MSDN is
0xc0000bb8 Pdh_cstatus_no_object
The specified object isn't found on the system.
The system is afraid of performance counters affect the performance of the system, but the relevant counter objects are closed.
So let's go through the registration form and open it.
The path is as follows:
Hkey_local_machine\system\currentcontrolset\services\remoteaccess\performance
Disable Performance counters:0x000
It's OK to change the above item to 0x000.
IsOpen, turn passed on as true, turn off pass false
void Assertnotdiabletherasobject (BOOL IsOpen)
{
Hkey_local_machine\system\currentcontrolset\services\remoteaccess\performance
HKEY hkey;
Long ret0 = RegOpenKeyEx (HKEY_LOCAL_MACHINE, _t ("System\\currentcontrolset\\services\\remoteaccess\\performance"), 0,key_all_access,&hkey);
if (ret0 = = ERROR_SUCCESS)
{
DWORD dwdiable;
DWORD cbdata_1 = sizeof (DWORD);
RegQueryValueEx (hkey, _t ("Disable performance counters"), NULL, NULL, (LPBYTE) &dwdiable, &cbdata_1);
if (dwdiable== IsOpen)
{
Dwdiable=! IsOpen;
RegSetValueEx (hkey, _t ("Disable performance Counters"), Null,reg_dword, (LPBYTE) &dwdiable, cbdata_1);
}
RegCloseKey (HKEY);
}
}
================================================================================================
With Microsoft performance counters: http://technet.microsoft.com/en-us/library/cc938959.aspx
Counters for disks
Counter |
Description |
logicaldisk\% Free Spaces |
Reports the percentage of unallocated disk to the total usable spaces on the logical volume. When calculating the _total instance, the%free spaces counters recalculate the sum as a percentage for each disk. There is no% free spaces counter for the PhysicalDisk object. |
logicaldisk| PhysicalDisk\Avg. Disk Bytes/transfer |
Measures the size of input/output (I/O) operations. The disk is efficient if it transfers large amounts of data relatively quickly. Watch This counter when measuring maximum throughput. To analyze transfer the data further, use Avg. disk Bytes/read and Avg. disk Bytes/write. |
Logicaldisk| PhysicalDisk\Avg. Disk sec/transfer |
Indicates how fast the data is being moved (in seconds). Measures the average of each data transfer, regardless of the number of bytes read or written. Shows the total time of the ' read or write ', from the moment it leaves the Diskperf.sys driver to the moment it is complete. A High value for this counter might mean that's system is retrying requests due to lengthy queuing or, less common Ly, disk failures. to analyze transfer the data further, use Avg. disk Sec/read and Avg. disk Sec/write. |
Logicaldisk| PhysicalDisk\Avg. Disk Queue Length |
Tracks the number of requests that are queued and waiting for a di SK during the sample interval, as as the requests in service. As a result, the might overstate activity. If More than two requests are continuously waiting on a single-disk system, the disk might to be a bottleneck. To analyze the queue length data further, use Avg. disk Read Queue Length and avg. disk Write Queue Length. |
logicaldisk| Physicaldisk\current Disk Queue Length |
Indicates the number of disk requests that are currently waiting as as-as-requests currently being. Subject to wide variations unless-workload has a achieved state and you steady have a collected number of s Amples to establish a pattern. An instantaneous value or snapshot of the current queue length, unlike Avg. Disk Queue Length, Avg. disk Read Queue Length , and AVG. Disk Write Queue Length, that reports averages. |
logicaldisk| PhysicalDisk\Disk Bytes/sec |
Indicates the rate at which bytes are transferred and is the primary of disk measure. To analyze transfer data based in reads and writes, use disk Read bytes/sec and disk Write bytes/sec, respectively. |
logicaldisk| PhysicalDisk\Disk Transfers/sec |
Indicates the number of read and writes completed/second, regardless of how much data they involve. Measures disk utilization. If value exceeds (per physical disk in the case of a striped volume), then a bottleneck might is developing. To analyze transfer data based in reads and writes, use disk read/sec and disk writes/sec, respectively. |
Logicaldisk\free Megabytes |
Reports the amount of bytes on the disk is not allocated. There is no free megabytes counter for the PhysicalDisk object. |
Logicaldisk| Physicaldisk\split io/sec |
Reports the rate at which the operating system divides I/O requests to the D ISK into multiple requests. A split I/O request might occur if the program requests data in a size this is too large to fit into a single request or I f the disk is fragmented. Factors that influence the size of a I/O request can include application design, the file system, or drivers. A high rate of split I/O might not, in itself, represent a problem. However, on Single-disk systems, Ace rate for this counter tends to indicate disk fragmentation. |
logicaldisk| physicaldisk\% Disk Time |
Reports The percentage of time this selected disk drive is busy servicing read or write requests. Because this counters data can span more than one sample, and consequently overstate disk utilization, compare this value Against% Idle time for a to accurate picture. By default this counter cannot exceed percent; However, you can reset the registry to allow System Monitor to display percentages exceeding if percent. For information about this adjustment and other aspects of performance data collection and reporting, on performance obje CTS in Overview the performance monitoring in this book. |
logicaldisk| physicaldisk\% Disk Write Time |
Reports The percentage of time this selected disk drive is busy servicing write requests. |
logicaldisk| physicaldisk\% Disk Read Time |
Reports The percentage of time this selected disk drive is busy servicing read requests. |
logicaldisk| physicaldisk\% Idle Time |
Reports The percentage of time this disk system is not processing requests and no work was queued. Notice that this counter, when added to% Disk time, might not equal percent, because% Disk time can exaggerate disk utilization. |
Memory Monitor
To determine a baseline for your system, use the following counters to create logs of memory An extended period (from several weeks to a month).
\memory\pages/sec
\memory\available Bytes
\paging File (_total) \% Usage
CPU
To Determine the baseline, use the following counters to create logs of processor usage over a extended period (from several Weeks to a month).
Processor\% Processor time
System\Processor Queue Length