{"id":94565,"date":"2016-10-21T07:00:00","date_gmt":"2016-10-21T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=94565"},"modified":"2019-03-13T10:32:51","modified_gmt":"2019-03-13T17:32:51","slug":"20161021-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20161021-00\/?p=94565","title":{"rendered":"Is there anything better than GetThreadTimes for obtaining per-thread CPU usage information?"},"content":{"rendered":"<p>A customer was using the <code>Get&shy;Thread&shy;Times<\/code> function for high-resolution profiling of performance-sensitive code, but found that its accuracy is rather poor. They were hoping there would be something more along the lines of a <code>Query&shy;Performance&shy;Counter<\/code> that reported only CPU time consumed by a particular thread, rather than by the system in general. <\/p>\n<p>Fortunately, there is. <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms684943(v=vs.85).aspx\">The <code>Query&shy;Thread&shy;Cycle&shy;Time<\/code> function<\/a> gives you the CPU cycles consumed by a particular thread. This includes time spent both in user mode and in kernel mode. <\/p>\n<p>Note, however, that these values are reported directly from the CPU using mechanisms like RDTSC or <a HREF=\"http:\/\/infocenter.arm.com\/help\/topic\/com.arm.doc.ddi0290g\/Bihcjbaa.html\">the performance monitor control register<\/a>. This means that the actual results are at the mercy of whatever the CPU manufacturer decides the CPU cycle counter means. Maybe they correspond to wall clock time; maybe they don&#8217;t. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>QueryThreadCycleTime.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-94565","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>QueryThreadCycleTime.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=94565"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94565\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=94565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=94565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=94565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}