<p>I suspect that one of my applications eats more CPU cycles than I want it to. The problem is - it happens in bursts, and just looking at the task manager doesn't help me as it shows immediate usage only.</p>

<p>Is there a way (on Windows) to track the history of CPU &amp; Memory usage for some process. E.g. I will start tracking "firefox", and after an hour or so will see a graph of its CPU &amp; memory usage during that hour.</p>

<p>I'm looking for either a ready-made tool or a programmatic way to achieve this.</p>

[{'answer_id': 69343, 'author': 'Eli Bendersky', 'author_id': 8206, 'author_profile': 'https://Stackoverflow.com/users/8206', 'pm_score': 1, 'selected': False, 'text': '<p>Hmm, I see that <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="nofollow noreferrer">Process Explorer</a> can do it, although its graphs are not too convenient. Still looking for alternative / better ways to do it.</p>\n'}, {'answer_id': 69344, 'author': 'SaaS Developer', 'author_id': 7215, 'author_profile': 'https://Stackoverflow.com/users/7215', 'pm_score': 1, 'selected': False, 'text': '<p>Perfmon.exe is built into windows.</p>\n'}, {'answer_id': 69353, 'author': 'Niall', 'author_id': 6049, 'author_profile': 'https://Stackoverflow.com/users/6049', 'pm_score': 6, 'selected': False, 'text': '<p><a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="noreferrer">Process Explorer</a> can show total CPU time taken by a process, as well as a history graph per process.</p>\n'}, {'answer_id': 69364, 'author': 'Ady Romantika', 'author_id': 67775, 'author_profile': 'https://Stackoverflow.com/users/67775', 'pm_score': 3, 'selected': False, 'text': '<p>I agree, perfmon.exe allows you to add counters (right click on the right panel) for any process you want to monitor.</p>\n\n<p>Performance Object: Process\nCheck "Select instances from list" and select firefox.</p>\n'}, {'answer_id': 69373, 'author': 'doflynn', 'author_id': 10791, 'author_profile': 'https://Stackoverflow.com/users/10791', 'pm_score': 3, 'selected': False, 'text': "<p>WMI is Windows Management Instrumentation, and it's built into all recent versions of Windows. It allows you to programmatically track things like CPU usage, disk I/O, and memory usage.</p>\n\n<p>Perfmon.exe is a GUI front-end to this interface, and can monitor a process, write information to a log, and allow you to analyze the log after the fact. It's not the world's most elegant program, but it does get the job done. </p>\n"}, {'answer_id': 69400, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>You might want to have a look at <a href="http://www.bitsum.com/prolasso.php" rel="nofollow noreferrer">Process Lasso</a>.</p>\n'}, {'answer_id': 69416, 'author': 'Martin08', 'author_id': 8203, 'author_profile': 'https://Stackoverflow.com/users/8203', 'pm_score': 9, 'selected': True, 'text': "<p>Press <kbd>Win</kbd>+<kbd>R</kbd>, type <code>perfmon</code> and press <kbd>Enter</kbd>. When the Performance window is open, click on the <strong>+</strong> sign to add new counters to the graph. The counters are different aspects of how your PC works and are grouped by similarity into groups called &quot;Performance Object&quot;.</p>\n<p>For your questions, you can choose the &quot;Process&quot;, &quot;Memory&quot; and &quot;Processor&quot; performance objects. You then can see these counters in real time</p>\n<p>You can also specify the utility to save the performance data for your inspection later. To do this, select &quot;Performance Logs and Alerts&quot; in the left-hand panel. (It's right under the System Monitor console which provides us with the above mentioned counters. If it is not there, click &quot;File&quot; &gt; &quot;Add/remove snap-in&quot;, click Add and select &quot;Performance Logs and Alerts&quot; in the list&quot;.) From the &quot;Performance Logs and Alerts&quot;, create a new monitoring configuration under &quot;Counter Logs&quot;. Then you can add the counters, specify the sampling rate, the log format (binary or plain text) and log location.</p>\n"}, {'answer_id': 3798591, 'author': 'dyasta', 'author_id': 191514, 'author_profile': 'https://Stackoverflow.com/users/191514', 'pm_score': 2, 'selected': False, 'text': '<p>Process Lasso is designed more for process automation and priority class optimization, not graphs. That said, it <em>does</em> offer per-process CPU utilization history (drawn as a white line on the graph) but it does <em>NOT</em> offer per-process memory utilization history. </p>\n\n<p>DISCLAIMER: I am the author of Process Lasso, but am not actually endorsing it here - as there are better solutions (perfmon being the best).</p>\n\n<p>The best thing ever is Windows Vista+ Resource and Performance Monitor. It can track usage of CPU, Memory, Network, and Disk accesses by processes over time. It is a great overall system information utility that should have been created long ago. Unless I am mistaken, it can track per-process CPU and memory utilization over time (amongst the other things listed).</p>\n'}, {'answer_id': 8012150, 'author': 'CppNoob', 'author_id': 422131, 'author_profile': 'https://Stackoverflow.com/users/422131', 'pm_score': 5, 'selected': False, 'text': '<p>Using perfmon.exe, I have tried using the "Private Bytes" counter under "Process" counters for tracking memory usage and it works well.</p>\n'}, {'answer_id': 10515335, 'author': 'Rich Kreider', 'author_id': 1384476, 'author_profile': 'https://Stackoverflow.com/users/1384476', 'pm_score': 4, 'selected': False, 'text': '<p>maybe you can use this.  It should work for you and will report processor time for the specified process.</p>\n\n<pre><code>@echo off\n: Rich Kreider &lt;rjk@techish.net&gt;\n: report processor time for given process until process exits (could be expanded to use a PID to be more\n: precise)\n: Depends:  typeperf\n: Usage:  foo.cmd &lt;processname&gt;\n\nset process=%~1\necho Press CTRL-C To Stop...\n:begin\nfor /f "tokens=2 delims=," %%c in (\'typeperf "\\Process(%process%)\\%% Processor Time" -si 1 -sc 1 ^| find /V "\\\\"\') do (\nif %%~c==-1 (\ngoto :end\n) else (\necho %%~c%%\ngoto begin\n)\n)\n\n:end\necho Process seems to have terminated.\n</code></pre>\n'}, {'answer_id': 14196383, 'author': 'sean', 'author_id': 82371, 'author_profile': 'https://Stackoverflow.com/users/82371', 'pm_score': 2, 'selected': False, 'text': '<p>Although I have not tried this out, <a href="http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx" rel="nofollow noreferrer">ProcDump</a> seems like a better solution.</p>\n\n<p>Description from site:</p>\n\n<blockquote>\n  <p>ProcDump is a command-line utility whose primary purpose is monitoring an application for CPU spikes and generating crash dumps during a spike that an administrator or developer can use to determine the cause of the spike. ProcDump also includes hung window monitoring (using the same definition of a window hang that Windows and Task Manager use), unhandled exception monitoring and can generate dumps based on the values of system performance counters. It also can serve as a general process dump utility that you can embed in other scripts.</p>\n</blockquote>\n'}, {'answer_id': 48192332, 'author': 'Terrik', 'author_id': 717043, 'author_profile': 'https://Stackoverflow.com/users/717043', 'pm_score': 0, 'selected': False, 'text': '<p>I use taskinfo for history graph of CPU/RAM/IO speed.\n<a href="http://www.iarsn.com/taskinfo.html" rel="nofollow noreferrer">http://www.iarsn.com/taskinfo.html</a></p>\n\n<p>But bursts of unresponsiveness, sounds more like interrupt time due to a falty HD/SS drive. </p>\n'}, {'answer_id': 50368360, 'author': 'Kaarthikeyan', 'author_id': 2092251, 'author_profile': 'https://Stackoverflow.com/users/2092251', 'pm_score': 2, 'selected': False, 'text': '<p>You can also try using a C#/Perl/Java script get the utilization data using WMI Commands, and below is the steps for it.</p>\n\n<p>We need to execute 2 WMI Select Queries and apply CPU% utilization formula</p>\n\n<p><strong>1. To retrieve the total number of logical process</strong> </p>\n\n<pre><code>select NumberOfLogicalProcessors from Win32_ComputerSystem\n</code></pre>\n\n<p><strong>2. To retrieve the values of PercentProcessorTime, TimeStamp_Sys100NS ( CPU utilization formula has be applied get the actual utilization percentage)and WorkingSetPrivate ( RAM ) minimum of 2 times with a sleep interval of 1 second</strong></p>\n\n<pre><code>select * from Win32_PerfRawData_PerfProc_Process where IDProcess=1234\n</code></pre>\n\n<p><strong>3. Apply CPU% utilization formula</strong></p>\n\n<pre><code>CPU%= ((p2-p1)/(t2-t1)*100)/NumberOfLogicalProcessors\n</code></pre>\n\n<p>p2 indicated PercentProcessorTime retrieved for the second time, and p1 indicateds the PercentProcessorTime retrieved for the first time, t2 and t1 is for TimeStamp_Sys100NS.</p>\n\n<p>A sample Perl code for this can be found in the link <a href="http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/" rel="nofollow noreferrer">http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/</a></p>\n\n<p>This logic applies for all programming language which supports WMI queries</p>\n'}, {'answer_id': 52653812, 'author': 'Bryce', 'author_id': 311364, 'author_profile': 'https://Stackoverflow.com/users/311364', 'pm_score': 0, 'selected': False, 'text': '<p>Under Windows 10, the Task Manager can show you cumulative CPU hours.  Just head to the "App history" tab and "Delete usage history".  Now leave things running for an hour or two:</p>\n\n<p><a href="https://i.stack.imgur.com/mV0UA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mV0UA.png" alt="Windows 10 Cumulative CPU time"></a></p>\n\n<p>What this does NOT do is break down usage in browsers by tab.  Quite often inactive tabs will do a tremendous amount of work, with each open tab using energy and slowing your PC.</p>\n'}, {'answer_id': 58649113, 'author': 'Prosenjit Sen', 'author_id': 11408288, 'author_profile': 'https://Stackoverflow.com/users/11408288', 'pm_score': 2, 'selected': False, 'text': '<p>There was a requirement to get status and cpu / memory usage of some specific windows servers. I used below script:</p>\n\n<p>This is an example of Windows Search Service.  </p>\n\n<pre><code>  $cpu = Get-WmiObject win32_processor\n  $search = get-service "WSearch"\n  if ($search.Status -eq \'Running\')\n  {\n  $searchmem = Get-WmiObject Win32_Service -Filter "Name = \'WSearch\'"\n  $searchid = $searchmem.ProcessID\n  $searchcpu1 = Get-WmiObject Win32_PerfRawData_PerfProc_Process | Where {$_.IDProcess -eq $searchid}\n  Start-Sleep -Seconds 1\n  $searchcpu2 = Get-WmiObject Win32_PerfRawData_PerfProc_Process | Where {$_.IDProcess -eq $searchid}\n  $searchp2p1 = $searchcpu2.PercentProcessorTime - $searchcpu1.PercentProcessorTime\n  $searcht2t1 = $searchcpu2.Timestamp_Sys100NS - $searchcpu1.Timestamp_Sys100NS\n  $searchcpu = [Math]::Round(($searchp2p1 / $searcht2t1 * 100) /$cpu.NumberOfLogicalProcessors, 1)\n  $searchmem = [Math]::Round($searchcpu1.WorkingSetPrivate / 1mb,1)\n  Write-Host \'Service is\' $search.Status\', Memory consumed: \'$searchmem\' MB, CPU Usage: \'$searchcpu\' %\'\n  }\n\n  else\n  {\n  Write-Host Service is $search.Status -BackgroundColor Red\n  }\n</code></pre>\n'}, {'answer_id': 64888649, 'author': 'saeed eivazi', 'author_id': 6498792, 'author_profile': 'https://Stackoverflow.com/users/6498792', 'pm_score': 0, 'selected': False, 'text': '<p>Download <a href="https://learn.microsoft.com/en-us/sysinternals/downloads/procmon" rel="nofollow noreferrer">process monitor</a></p>\n<ol>\n<li><p>Start Process Monitor</p>\n</li>\n<li><p>Set a filter if required</p>\n</li>\n<li><p>Enter menu Options &gt; Profiling Events</p>\n</li>\n<li><p>Click &quot;Generate thread prof\u200ciling events&quot;, choose the frequency, and click OK.</p>\n</li>\n<li><p>To see the collected historical data at any time, enter menu Tools &gt; Process Activity Summary</p>\n</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/69332', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8206/']