Tuesday, March 6, 2012

How to Record CPU and Memory Usage Over Time in Windows?

Whenever the computer is lagging or some application is taking too long to respond, we usually fire up task manager and look under the Performance tab or under Processes to check on processor utilization or the amount of free memory available. The task manager is ideal for real-time analysis of CPU and memory utilization. It even displays a short history of CPU utilization in the form of a graph. You get a small time-window, about 30 seconds or so, depending on how large the viewing area is.

task-manager

However, 30 seconds is rather short to make any meaningful analysis of the performance of a process or the system as a whole. Some users lament that there is no data logging feature in Task Manager to plot CPU usage over a longer time duration. Truth is, the task manager isn’t meant to be used as a performance analysis tool. For this purpose there is another more powerful tool called Performance Monitor. It is a part of Windows and it has the ability to record CPU and memory utilization and a host of other parameters for a long period of time.

To launch Performance Monitor, press Win+R on your keyboard and in the Run dialog box type perfmon and press Enter.

To get an immediate and real-time view of CPU utilization, click on Performance Monitor on the left-hand Console Tree. The color scheme of the graph is different (red over white), but it is the same graph you can see under Task Manager.

To enable logging you have to create a new Data Collector Set. On the navigation panel on the left, expand Data Collector Set and right click on User Defined. From the New menu click Data Collector Set.

perfmon1

Give a name to the set that you can recognize later, and choose the radio button Create manually. Click Next.

perfmon2 (3)

Under type of data, choose Create Data Log and check the box Performance counter. Click Next.

perfmon2 (4)

Here I want to add a quick note on the different types of data log available and what each of them does.

  • Performance counters are measurements of system state or activity. This option polls the requested parameters at specified time intervals and records the data returned.
  • Event trace data only logs the event when something happens. The data is collected from trace providers, which are components of the operating system or of individual applications that report actions or events.
  • Configuration information is collected from key values in the Windows registry. Windows Performance Monitor can record the value of a registry key at a specified time or interval.

Now is the time to choose the performance counters which you would like to log. Click on the Add button and choose one of the many available counters. You can log processor utilization, processor idle time or interrupt time, memory usage, USB activity and dozens of other counters. In this example, we chose Processor Time.

perfmon2 (6)

Adjust the poll interval. 5 seconds should do.

perfmon2 (1)

At this step, you can either click the Finish button or progress though the next few steps where you can specify the location of the log file or configure the Data Collector Set to run as a specific user.

Once the data set is created, run it. The Data Collector Set will start recording data from the chosen performance monitor, in our case, CPU utilization. Reports aren’t available when the data set is running. After you stop it, you can see your report under the Reports directory in the navigation panel.

perfmon12

Here is our CPU utilization graph recorded over a period of 3 minutes.

perfmon14

Aside from CPU utilization you can record memory usage, disk activity, network activity, system events, and several other things.

14 comments:

  1. This is absolutely fantastic. I've been looking all over for a resource monitoring tool and this works just great. Thanks

    ReplyDelete
  2. I'm usually troubleshooting linux boxes and was looking for something like sar. Having this right out the box in Win7 is great. Thanks for the article, helped loads!

    ReplyDelete
  3. how to monitor multiple instances of IE 8 in Perfmon? IE 8 creates a new process every time a tab is created. will the new process will be automatically monitored?

    ReplyDelete
  4. I'm not sure about IE8's multiple processes monitoring. Why don't you try it out and report your findings here?

    ReplyDelete
  5. But I don't think processor time tells the CPU usage as I'm doing performance test. I googled it and somebody said there is a calculation between processor time and CPU usage.

    ReplyDelete
  6. Hi, How to view CPU Usage for a particular application instance or object

    ReplyDelete
  7. Great. I finally found this useful article.

    ReplyDelete
  8. Thanks, Nice and straight to point tutorial.

    ReplyDelete
  9. Just wanted to second what everyone else is saying that this is a fantastic tutorial that exactly explained what I was looking for.

    ReplyDelete
  10. this is nice for cpu usage analysis on Windows 7 without other external tools.

    ReplyDelete
  11. You mentioned that we can see reports only when the collection is stopped? It means every time we have to stop it to see reports? This somehow does not sound user friendly.

    ReplyDelete
  12. Even though I've specified over all duration as 53 weeks, the data collection seems to be stopping at random; not able to trace why it had stopped. appreciate any support in this regard.

    ReplyDelete
  13. I'm using it right now

    ReplyDelete

Popular Posts