How to get the hard page fault count on Windows

Dear Lazyweb,

One of the improvements I want to make in an upcoming version of the About Startup extension is to allow to distinguish between cold and hot startups. One way to do so is to check how many page faults actually led to reading off a disk. They are called hard page faults.

On UNIX systems, their count for a given process can be obtained with the getrusage function, which works on both Linux and MacOSX systems.

Under Windows, that is another story, and so far I haven't found anything satisfactory.

My first attempt was to see how cygwin, which brings UNIXish libraries to Windows, was doing for its own getrusage. And the answer to that is that it gives the wrong data. sigh. It uses GetProcessMemoryInfo to fill the hard page faults field (ru_majflt), and nothing for the soft page faults field (ru_minflt). Except GetProcessMemoryInfo returns the number of soft page faults.

The best I could find on MSDN is the Win32_PerfFormattedData_PerfOS_Memory class from Windows Management Instrumentation, except is it system-wide instead of per-process information, and only gives rates (hard page faults per second, which it calls page reads per second). The corresponding raw data doesn't seem very satisfactory either.

So, dear lazyweb, do you have any idea?

Update: Taras suggested to use GetProcessIOCounters, which, despite not giving hard page faults count, looked promising as a way to distinguish between cold and warm startup, but it turns out it is as useless as some systemtap and dtrace scripts you can find on the net: from my experiments, it looks like it only tracks active read() and write() system calls, meaning it doesn't track mapped memory accesses, and more importantly, it only tracks the system calls, not when actually doing I/O, thus hitting the disk.

2011-04-12 16:50:04+0900

p.m.o

You can leave a response, or trackback from your own site.

6 Responses to “How to get the hard page fault count on Windows”

  1. Archaeopteryx Says:

    The simplest approach: Get Windows boot time with ‘systeminfo’ command and compare to a timestamp you store in a preference and update on each startup. If your addon needs restart, compare boot time against the created timestamp of the xpi.

  2. Shawn Wilsher Says:

    I suppose running xperf to get that data wouldn’t be acceptable, would it? xperf breaks it down on a per file basis (within the process).

  3. glandium Says:

    Shawn: I want to get that programmatically, and with the least overhead possible. And the most difficult part is that I need to get the info after the fact (I don’t want to need a wrapper for that)
    xperf obviously uses some API to do that, most probably the WMI ones, but I haven’t found what I need there yet. Note that xperf may be tracking all I/O directly, instead of some hard page fault counter, and it probably doesn’t track things that happened before it was started (though I haven’t tried yet, so that’s only an hypothesis)

  4. Neil Rashbrook Says:

    pfmon.exe claims to be able to do this but I’ve no idea how.

  5. p3 Says:

    I’m not sure if it’s possible to use etw for this in windows, I only know that you can get some metric called hard page faults from there, but I don’t know if it’s rate or not. My experience with etw is fairly limited, as I’ve used etw only for .Net application and for quite different purpose. Some links that that might get you started:
    http://blog.mozilla.com/sfink/tag/etw/
    http://msdn.microsoft.com/en-us/magazine/cc163437.aspx
    http://msdn.microsoft.com/en-us/library/bb968803.aspx

  6. Paul Biggar Says:

    I’d recommend asking on StackOverflow.

Leave a Reply