<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Determine CPU usage of current process (C++ and C#)</title>
	<atom:link href="http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/</link>
	<description>Code and musings by Ben Watson</description>
	<lastBuildDate>Sat, 04 Feb 2012 04:16:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Adam Smith</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-246334</link>
		<dc:creator>Adam Smith</dc:creator>
		<pubDate>Tue, 29 Nov 2011 02:27:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-246334</guid>
		<description>Hi Ben,

THANKS for the code!  Some machines don&#039;t have perf counters installed correctly so this is great!

Some quick tips:
* Instead of using DateTime.Now, .UtcNow would be better as it&#039;s both faster and less dependent on user settings.  But even better is Environment.TickCount since it is not dependent on the user not touching their clock.

* SubtractTimes can be static.

* I rolled the two properties into the code, inline, since they were only used once.  Probably personal preference but the code seemed more readable for me that way.

But mostly THANKS again for the code!

Adam</description>
		<content:encoded><![CDATA[<p>Hi Ben,</p>
<p>THANKS for the code!  Some machines don&#8217;t have perf counters installed correctly so this is great!</p>
<p>Some quick tips:<br />
* Instead of using DateTime.Now, .UtcNow would be better as it&#8217;s both faster and less dependent on user settings.  But even better is Environment.TickCount since it is not dependent on the user not touching their clock.</p>
<p>* SubtractTimes can be static.</p>
<p>* I rolled the two properties into the code, inline, since they were only used once.  Probably personal preference but the code seemed more readable for me that way.</p>
<p>But mostly THANKS again for the code!</p>
<p>Adam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nisar</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-236365</link>
		<dc:creator>nisar</dc:creator>
		<pubDate>Fri, 30 Sep 2011 23:54:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-236365</guid>
		<description>Hi, 

the conversion in C# SubtractTimes (&lt;code&gt;((UInt64)(a.dwHighDateTime &lt;&lt; 32)) &#124; (UInt64)a.dwLowDateTime&lt;/code&gt;) is incorrect. The correct conversion is &lt;code&gt;(((UInt64)f.dwHighDateTime) &lt;&lt; 32) &#124; (UInt32)f.dwLowDateTime&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>the conversion in C# SubtractTimes (<code>((UInt64)(a.dwHighDateTime &lt;&lt; 32)) | (UInt64)a.dwLowDateTime</code>) is incorrect. The correct conversion is <code>(((UInt64)f.dwHighDateTime) &lt;&lt; 32) | (UInt32)f.dwLowDateTime</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: susheel</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-232938</link>
		<dc:creator>susheel</dc:creator>
		<pubDate>Thu, 15 Sep 2011 06:41:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-232938</guid>
		<description>Hi All,
I am looking code to find out processes which have been idle for a long time and want to kill them like javaw processes.

any help

thanks</description>
		<content:encoded><![CDATA[<p>Hi All,<br />
I am looking code to find out processes which have been idle for a long time and want to kill them like javaw processes.</p>
<p>any help</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ike</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-228900</link>
		<dc:creator>Ike</dc:creator>
		<pubDate>Mon, 22 Aug 2011 15:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-228900</guid>
		<description>The concept of calculating CPU% is really useful for my need at the moment. Thanks for sharing!!!</description>
		<content:encoded><![CDATA[<p>The concept of calculating CPU% is really useful for my need at the moment. Thanks for sharing!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fedot</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-183890</link>
		<dc:creator>Fedot</dc:creator>
		<pubDate>Tue, 11 Jan 2011 15:18:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-183890</guid>
		<description>Our testers found problem with
method GetTickCount64()
at Win x86 OS.
and now we use
method GetTickCount()
:-)</description>
		<content:encoded><![CDATA[<p>Our testers found problem with<br />
method GetTickCount64()<br />
at Win x86 OS.<br />
and now we use<br />
method GetTickCount()<br />
 <img src='http://www.philosophicalgeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vaishali</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-143678</link>
		<dc:creator>vaishali</dc:creator>
		<pubDate>Thu, 08 Jul 2010 10:20:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-143678</guid>
		<description>Deekshit,

As you have mentioned that your code is working for single process or program ,
please let me know what i need to add to the exiting code.
please!! :cry: 
i want a code that takes a program name as argument and gives it cpu utilization as output.

thank u.</description>
		<content:encoded><![CDATA[<p>Deekshit,</p>
<p>As you have mentioned that your code is working for single process or program ,<br />
please let me know what i need to add to the exiting code.<br />
please!! <img src='http://www.philosophicalgeek.com/wp-includes/images/smilies/icon_cry.gif' alt=':cry:' class='wp-smiley' /><br />
i want a code that takes a program name as argument and gives it cpu utilization as output.</p>
<p>thank u.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: P.C.</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-136057</link>
		<dc:creator>P.C.</dc:creator>
		<pubDate>Sat, 27 Mar 2010 20:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-136057</guid>
		<description>I would disagree to sentence &quot;Kernel, User, and Idle sum to total time, which is approximately wall-time.&quot;

Idle time returned from GetSystemTimes is most probably a part of the Kernel time. 

GetProcessTimes returns Kernel time without any Idle time periods because they belong to a different process.

So, the calculation takes the Idle time into account but I would say, it is correct.</description>
		<content:encoded><![CDATA[<p>I would disagree to sentence &#8220;Kernel, User, and Idle sum to total time, which is approximately wall-time.&#8221;</p>
<p>Idle time returned from GetSystemTimes is most probably a part of the Kernel time. </p>
<p>GetProcessTimes returns Kernel time without any Idle time periods because they belong to a different process.</p>
<p>So, the calculation takes the Idle time into account but I would say, it is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-134571</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Mon, 08 Mar 2010 21:35:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-134571</guid>
		<description>Remy, GetTickCount() is supported by Windows 2000 (http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx), but GettickCount64 is not supported until Vista/2008.

For GetSystemTimes(), I think your only solution is to use the officially-unsupported function NtQuerySystemInformation  (http://msdn.microsoft.com/en-us/library/ms724509(VS.85).aspx, look for SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION). I would put usage of this inside some #ifdef so it&#039;s only used in Windows 2000/XP, because this method could change or be removed in future versions of Windows.</description>
		<content:encoded><![CDATA[<p>Remy, GetTickCount() is supported by Windows 2000 (<a href="http://msdn.microsoft.com/en-us/library/ms724408(VS.85" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724408(VS.85</a>).aspx), but GettickCount64 is not supported until Vista/2008.</p>
<p>For GetSystemTimes(), I think your only solution is to use the officially-unsupported function NtQuerySystemInformation  (<a href="http://msdn.microsoft.com/en-us/library/ms724509(VS.85" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724509(VS.85</a>).aspx, look for SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION). I would put usage of this inside some #ifdef so it&#8217;s only used in Windows 2000/XP, because this method could change or be removed in future versions of Windows.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Remy</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-134455</link>
		<dc:creator>Remy</dc:creator>
		<pubDate>Sun, 07 Mar 2010 23:50:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-134455</guid>
		<description>Hi Ben, 

I wanted to use your program for my project, but the code uses GetSystemTimes() and GetTickCounts() which don&#039;t seem to be supported by XP/2000.  Is there a quick fix for that?

Thanks ,
Remy</description>
		<content:encoded><![CDATA[<p>Hi Ben, </p>
<p>I wanted to use your program for my project, but the code uses GetSystemTimes() and GetTickCounts() which don&#8217;t seem to be supported by XP/2000.  Is there a quick fix for that?</p>
<p>Thanks ,<br />
Remy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kao</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-109665</link>
		<dc:creator>kao</dc:creator>
		<pubDate>Mon, 03 Aug 2009 01:33:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-109665</guid>
		<description>Oh, I see. Thanks for the answer.  

p/s: Nice to meet you. :)</description>
		<content:encoded><![CDATA[<p>Oh, I see. Thanks for the answer.  </p>
<p>p/s: Nice to meet you. <img src='http://www.philosophicalgeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-109609</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Sun, 02 Aug 2009 16:10:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-109609</guid>
		<description>That code is just test code to use the processor as much as possible, in multiple threads, in order to test the processor usage code.

I would not expect it to match task manager exactly--they are measuring the program at different times, so there will be a little difference. Over time, they should average out to the same, though.</description>
		<content:encoded><![CDATA[<p>That code is just test code to use the processor as much as possible, in multiple threads, in order to test the processor usage code.</p>
<p>I would not expect it to match task manager exactly&#8211;they are measuring the program at different times, so there will be a little difference. Over time, they should average out to the same, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kao</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-109582</link>
		<dc:creator>kao</dc:creator>
		<pubDate>Sun, 02 Aug 2009 10:02:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-109582</guid>
		<description>Hi Ben, I don&#039;t understand every detail why you use thread method &quot;EatItThreadProc&quot;, and every thread method was used 2 times (in your code):

        static void Main(string[] args)
        {
            Console.WriteLine(&quot;Input:&quot;);
            string processName = Console.ReadLine();
            usage.setProcessName(processName);
            
            ThreadPool.QueueUserWorkItem(EatItThreadProc);
            ThreadPool.QueueUserWorkItem(EatItThreadProc);

            ThreadPool.QueueUserWorkItem(WatchItThreadProc);
            ThreadPool.QueueUserWorkItem(WatchItThreadProc);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }

Can you explain for me?

Moreoverer, I try to compare your program and Task manager of Window, they have a little difference. So, your program ran exactly?

Thanks for your reply!</description>
		<content:encoded><![CDATA[<p>Hi Ben, I don&#8217;t understand every detail why you use thread method &#8220;EatItThreadProc&#8221;, and every thread method was used 2 times (in your code):</p>
<p>        static void Main(string[] args)<br />
        {<br />
            Console.WriteLine(&#8220;Input:&#8221;);<br />
            string processName = Console.ReadLine();<br />
            usage.setProcessName(processName);</p>
<p>            ThreadPool.QueueUserWorkItem(EatItThreadProc);<br />
            ThreadPool.QueueUserWorkItem(EatItThreadProc);</p>
<p>            ThreadPool.QueueUserWorkItem(WatchItThreadProc);<br />
            ThreadPool.QueueUserWorkItem(WatchItThreadProc);</p>
<p>            while (true)<br />
            {<br />
                Thread.Sleep(1000);<br />
            }<br />
        }</p>
<p>Can you explain for me?</p>
<p>Moreoverer, I try to compare your program and Task manager of Window, they have a little difference. So, your program ran exactly?</p>
<p>Thanks for your reply!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101444</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:58:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101444</guid>
		<description>&#039;GetProcessesByName&#039;: identifier not found</description>
		<content:encoded><![CDATA[<p>&#8216;GetProcessesByName&#8217;: identifier not found</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101439</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:15:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101439</guid>
		<description>Hi Ben, Sorry about the previous two messages but i am trying to use this program to monitor a particular process so I replaced GetCurrentProcess() by GetProcessesByName(&quot;notepad&quot;) but I am getting an error</description>
		<content:encoded><![CDATA[<p>Hi Ben, Sorry about the previous two messages but i am trying to use this program to monitor a particular process so I replaced GetCurrentProcess() by GetProcessesByName(&#8220;notepad&#8221;) but I am getting an error</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101438</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101438</guid>
		<description>sorry got it working</description>
		<content:encoded><![CDATA[<p>sorry got it working</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101437</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sun, 31 May 2009 19:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101437</guid>
		<description>hi Ben, i tried building the solution it said it is successfull but i dont get any executable.</description>
		<content:encoded><![CDATA[<p>hi Ben, i tried building the solution it said it is successfull but i dont get any executable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bharath</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-101291</link>
		<dc:creator>bharath</dc:creator>
		<pubDate>Sat, 30 May 2009 22:36:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-101291</guid>
		<description>Hi Ben thats a great program, But how do I make it to monitor a particular process. I still didnot run the code but just want to make sure if we can monitor any process or not.

Thanks,
Bharath</description>
		<content:encoded><![CDATA[<p>Hi Ben thats a great program, But how do I make it to monitor a particular process. I still didnot run the code but just want to make sure if we can monitor any process or not.</p>
<p>Thanks,<br />
Bharath</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-95729</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 21 Apr 2009 14:32:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-95729</guid>
		<description>Peter, look at the documentation for this function on MSDN, specifically the requirements section: http://msdn.microsoft.com/en-us/library/ms724411.aspx</description>
		<content:encoded><![CDATA[<p>Peter, look at the documentation for this function on MSDN, specifically the requirements section: <a href="http://msdn.microsoft.com/en-us/library/ms724411.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms724411.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-95634</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Mon, 20 Apr 2009 21:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-95634</guid>
		<description>I have tried to run this program but always get entry point not fount GetTickCount64. I am using xp sp2 and tried to debug the source code from VS2008. do you know the reason?</description>
		<content:encoded><![CDATA[<p>I have tried to run this program but always get entry point not fount GetTickCount64. I am using xp sp2 and tried to debug the source code from VS2008. do you know the reason?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohan</title>
		<link>http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/comment-page-1/#comment-92797</link>
		<dc:creator>Rohan</dc:creator>
		<pubDate>Mon, 30 Mar 2009 17:43:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/#comment-92797</guid>
		<description>Good Article Ben</description>
		<content:encoded><![CDATA[<p>Good Article Ben</p>
]]></content:encoded>
	</item>
</channel>
</rss>

