{"id":1963,"date":"2011-04-12T16:50:04","date_gmt":"2011-04-12T14:50:04","guid":{"rendered":"http:\/\/glandium.org\/blog\/?p=1963"},"modified":"2011-04-15T09:40:45","modified_gmt":"2011-04-15T07:40:45","slug":"how-to-get-the-hard-page-fault-count-on-windows","status":"publish","type":"post","link":"https:\/\/glandium.org\/blog\/?p=1963","title":{"rendered":"How to get the hard page fault count on Windows"},"content":{"rendered":"<p>Dear Lazyweb,<\/p>\n<p>One of the improvements I want to make in an upcoming version of the <a href=\"https:\/\/addons.mozilla.org\/addon\/about-startup\">About Startup<\/a> 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.<\/p>\n<p>On UNIX systems, their count for a given process can be obtained with the <code>getrusage<\/code> function, which works on both Linux and MacOSX systems.<\/p>\n<p>Under Windows, that is another story, and so far I haven't found anything satisfactory.<\/p>\n<p>My first attempt was to see how cygwin, which brings UNIXish libraries to Windows, was doing for its own <code>getrusage<\/code>. And the answer to that is that it <a href=\"http:\/\/cygwin.com\/cgi-bin\/cvsweb.cgi\/src\/winsup\/cygwin\/resource.cc?rev=1.32&amp;content-type=text\/x-cvsweb-markup&amp;cvsroot=src\">gives the wrong data<\/a>. <i>sigh<\/i>. It uses <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms683219%28v=vs.85%29.aspx\"><code>GetProcessMemoryInfo<\/code><\/a> to fill the hard page faults field (<code>ru_majflt<\/code>), and nothing for the soft page faults field (<code>ru_minflt<\/code>). Except <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms683219%28v=vs.85%29.aspx\"><code>GetProcessMemoryInfo<\/code><\/a> returns the number of soft page faults.<\/p>\n<p>The best I could find on MSDN is the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394268.aspx\"><code>Win32_PerfFormattedData_PerfOS_Memory<\/code> class<\/a> 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.<\/p>\n<p>So, dear lazyweb, do you have any idea?<\/p>\n<p><b>Update<\/b>: Taras suggested to use <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms683218%28v=vs.85%29.aspx\">GetProcessIOCounters<\/a>, 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 <a href=\"\/blog\/?p=1476\">some systemtap and dtrace scripts you can find on the net<\/a>: from my experiments, it looks like it only tracks active <code>read()<\/code> and <code>write()<\/code> 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[23],"class_list":["post-1963","post","type-post","status-publish","format-standard","hentry","category-planet-mozilla","tag-en"],"_links":{"self":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1963"}],"version-history":[{"count":8,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1963\/revisions"}],"predecessor-version":[{"id":1972,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1963\/revisions\/1972"}],"wp:attachment":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}