Friday, May 14, 2010

vmstat/iostat replacement for windows ?

I dislike the old perfmon interface and it's unreadable graphs and logs. For a long time I've been searching for a basic vmstat and/or iostat windows port, and one that doesn't rely on that nonsensical cygwin. If anybody knows of one, please leave a comment.


Here's a proof on concept I cooked up in 20 minutes using the PDH (performance data helper) functions. In a nutshell, it queries the PDH counters directly and I'm be free to display
the data however I like.

Here's what I got so far:


proc_q_len pagefile interrupt/s cswitch/s %cpu_user %cpu_sys %cpu_idle %disk_busy %disk_read %disk_write
10 2308780032 2016 2555 64 26 9 100 0 100
3 2308911104 2863 3669 62 13 23 100 1 100
0 2309206016 1857 3057 79 10 9 2 0 2
0 2310217728 2579 3664 64 9 26 100 0 100
1 2309140480 2195 2985 71 3 25 100 0 100
2 2309140480 2241 3042 76 4 18 100 0 100


Not perfect, and I'm still trying to devise a proper layout for the stuff I want to display.
The columns shown correspond to the counters:
  • \System\Processor Queue Length
  • \Process(_Total)\Page File Bytes
  • \Processor(_Total)\Interrupts/sec
  • \System\Context Switches/sec
  • \Processor(_Total)\% User Time
  • \Processor(_Total)\% Privileged Time
  • \Processor(_Total)\% Idle Time
  • \PhysicalDisk(_Total)\% Disk Time
  • \PhysicalDisk(_Total)\% Disk Read Time
  • \PhysicalDisk(_Total)\% Disk Write Time

The general flow of code is like this (there are samples online):

2. PdhAddCounter for each counter
3. for each X seconds:
3.2 PdhGetFormattedCounterValue for each counter
3.3 print the result for each counter



5 comments:

Baron said...

Will you post your code?

Ben said...

When using Windows, For a measure of activity on the physical disk try (1 - (% Idle Time)) rather % Disk Time.
% Disk Time has been broken since win 2000.. ..it's now just a % representation of Avg Disk Queue Length.

wlad said...

Shane, I'm wondering if using WMI and scripting like here http://msdn.microsoft.com/en-us/library/aa392397(VS.85).aspx#wmi_performance_classes

would be easier than Pdh and C code.

sbester said...

windows 7 has "typeperf.exe" that can print these things out. Sample output looks like:

G:\>typeperf.exe -c "\System\Processor Queue Length" "\Process(_Total)\Page File Bytes" "\Processor(_Total)\Interrupts/sec" "\System\Context Switches/sec" "\Processor(_Total)\% User Time" "\Processor(_Total)\% Privileged Time" "\Processor(_Total)\% Idle Time" "\PhysicalDisk(_Total)\% Disk Time" "\P
hysicalDisk(_Total)\% Disk Read Time" "\PhysicalDisk(_Total)\% Disk Write Time"

"(PDH-CSV 4.0)","\\S4RL759\System\Processor Queue Length","\\S4RL759\Process(_Total)\Page File Bytes","\\S4RL759\Processor(_Total)\Interrupts/sec","\\S4RL759\System\Context Switches/sec","\\S4RL759\Processor(_Total)\% User Time","\\S4RL759\Processor(_Total)\% Privileged Time","\\S4RL759\Processor(_T
otal)\% Idle Time","\\S4RL759\PhysicalDisk(_Total)\% Disk Time","\\S4RL759\PhysicalDisk(_Total)\% Disk Read Time","\\S4RL759\PhysicalDisk(_Total)\% Disk Write Time"
"09/04/2012 18:58:37.812","0.000000","1857728512.000000","2455.835767","3794.479768","0.000000","2.323611","98.366399","0.004965","0.000000","0.004965"
"09/04/2012 18:58:38.818","0.000000","1857728512.000000","2553.252878","4034.855971","0.776075","3.104320","95.457851","0.000000","0.000000","0.000000"
"09/04/2012 18:58:39.823","0.000000","1857814528.000000","2605.288808","4188.954245","1.552160","6.208640","93.129597","0.042286","0.000000","0.042286"
"09/04/2012 18:58:40.828","0.000000","1858674688.000000","3042.359832","5484.621166","6.998652","10.109162","82.428513","45.755108","45.740154","0.014954"
"09/04/2012 18:58:41.829","0.000000","1858752512.000000","2673.234725","4753.083267","1.558362","1.558362","96.618465","0.037460","0.000000","0.037460"
"09/04/2012 18:58:42.830","0.000000","1858854912.000000","2748.131859","4936.847564","2.337539","3.895901","93.501750","0.024974","0.000000","0.024974"
"09/04/2012 18:58:43.831","0.000000","1859358720.000000","3279.620928","6342.465207","8.570992","12.466890","78.697238","50.858692","50.858692","0.000000"
"09/04/2012 18:58:44.832","0.000000","1859854336.000000","3007.906029","5719.117242","9.350167","3.895908","88.047407","8.303714","8.151375","0.152339"

sbester said...
This comment has been removed by the author.