Locations of visitors to this page

    Blog List       Minimize  
,NET:ASP:MVP
.NET
.NET 3.5
.NET:ACL
.NET:AppDomains
.NET:ASP
.NET:ASP ServerControls
.NET:ASP:Commerce
.NET:ASP:Config
.NET:ASP:JSON
.NET:ASP:Layout
.NET:ASP:Media/Flash
.NET:ASP:Mobile
.NET:ASP:Monitoring
.NET:ASP:MVC
.NET:ASP:Navigation
.NET:ASP:Stress Testing
.NET:ASP:Validation
.NET:ASP:WebParts
.NET:C#-Trig
.NET:CAB
.NET:CAS
.NET:Certification
.NET:CF
.NET:Collections
.NET:Configuration
.NET:Cryptography
.NET:Db
.NET:Delegates
.NET:Deployment
.NET:Diagnostics
.NET:Documentation
.NET:Encoding
.NET:Environment
.NET:Extension Methods
.NET:Globalization
.NET:I/O Streams
.NET:Interop
.NET:IO:Mail
.NET:IsolatedStorage
.NET:LicenseManager
.NET:LINQ
.NET:Metrics/Quality
.NET:Mono
.NET:MSOffice
.NET:Optimization
.NET:Patterns/Practices
.NET:Phone7
.NET:Reflection
.NET:Remoting
.NET:Reverse Engineering
.NET:Serialization
.NET:Silverlight
.NET:Silverlight UserGroup
.NET:Silverlight:Phone7
.NET:Threading
.NET:WCF
.NET:Windows Services
.NET:WinForms
.NET:WPF
.NET:Xml
Admin
Admin:Creating Software
Admin:CruiseControl
Admin:Estimating
Admin:Installers/Packaging
Admin:Methodologies
Admin:PM
Admin:SourceControl
Admin:UnitTesting
Admin:VisualStudio
Arch:Gen
Arch:Patterns
Arch:UML
Blogging
DB:Sqlite
DB:SqlServer
DB:SqlServer CE
DB:VistaDB
Graphs
IT
IT:DNN
IT:DOS
IT:IIS
IT:MailServers
IT:MS Office
IT:OS (XP/Vista/7)
Misc
Misc:Hardware
Misc:Humour
mISV:Accounting
mISV:Marketing
OS:Vista
Personal
Personal:Children
Personal:Faith
Personal:Family
Personal:History
Personal:Politics
Places:New Zealand
Places:Paris
Presentations
Tech:CSS
Tech:Regex
Tech:SQL
Tech:Web:HTML
Tech:XML/XSL
Web:HTML5

             
    Sprouting Synapses       Minimize  

             
Summary:

Bringing up the PerfMon

PerfMon is the system tool we use to view the results -- often as a graph -- garnered from the Performance Counters.

To view the Performance Counters, all you have to do is type is use Start/Run to launch PerfMon.exe, PerfMon.msc, or simply PerfMon (all roads lead to Rome), or click Start/Administration Tools/Performance to launch PerfMon:

image

in order to bring it up:

image

Note:
that every time you launch it, it comes up with a default set of performance counters (Pages/Sec, Avg Disc Queue Length, % Processor Time) being tracked and displayed in real time.

 

What's its Use?

The above default 3 counters, although very useful, will give you a very high level view of what's going on in your system -- but only the tip of the iceberg.
The Windows System has many many more Performance Counters built into it, ranging from tracking Processor performance, to hard-drive performance, to network interface cards, network traffic, memory, Security, etc.)  In addition to these built in Hardware and OS performance counters, many of Microsoft's products also publish performance counters (ASP.NET, SqlServer, etc.). And if that weren't enough, many 3rd party software products also publish custom Performance Counters in their products.

Basically, there are a lot of performance counters you can use -- all you have to do is use them.

How is it Used?

There are two modes: RealTime Performance Counter viewing (aka System Monitoring), or Logging Mode.

Real Time Tracking
If you want to get an instant glimpse of the some performance counter, you can either clear the default 3 performance counters first, using the New Button Set button, or simply add the performance counter of your choosing over the top of them:

image

Either way, to add a counter to the real-time output, Right Click on the right pane, in order to Add Counters:

image

This will bring up the Add Counters Dialog Box, which you use to add new Counters.
This is done, by selecting the Performance Object first ("Processor", "Paging File", "Physical File", etc.) -- which is simply another word for PerformanceCounterCategory  -- which in turn sets the selection of PerformanceCounters you see in the Counters list below it.
As you can see in the screen grabs below, when the Performance Group  is set to "Processor", the list below it contains Counters such as "% Interrupt Time", "% Process Time", etc., whereas the ".NET CLR Memory" Performance Group shows a whole bunch of other Counters ("#GC Handlers", "# Bytes in all Heaps", etc.)

image image etc.

Note:
As stated before, there are a lot of Performance Objects, and each one has a lot of PerformanceCounters -- so there are a lot of Counters for you to discover on your own...

Note:
Don't go banging away at the Add button thinking its doing nothing -- it possibly is.
Although a lot of system counters can only be added once, some counters can be added multiple times, in which case, every time you click Add, it will add another copy of the selected counter to the underlying System Monitor view -- except that you can't see it because the current dialog is covering it.

Notice that you can change the color of lines, etc. by playing around with Settings:

image

Creating Counter Logs

The problem with System Monitoring is that it only shows you a current snapshot of what is going on, and with Peaks everywhere, its pretty hard to know whether what you are looking at is important or not.
What you need is a larger picture -- a day or more's worth of PerformanceCounter settings and graphs to analyse -- except that you can't dedicate your day staring at PerfMon, right?

That's where Counter Logs comes in.

What you want to do is set up a "Counter Log", which is a pre-configured Logging Session definition, containing the specifications of what counters you want to log, when, how it starts, how it ends, etc. Once you've created such a Logging configuration, it gets saved, ready for you to use when ever you want.

Note: difference between Counter and Trace Logs
Counter Logs are used to record the measurements of specific counters. Counter logs record performance data on the selected counters at a specific sample interval. Trace Logs are used to record memory and resource events. Trace logs record performance data whenever events for their source providers occur. A source provider is an application or operating system service that has traceable events.

Let's add a brand new Counter Log:

image

Clicking OK brings up the New Counter Log dialog.
The first thing we want to do here is start adding the Counters we want to have tracked.
To do that, we simply click "Add Counters":

image 

...which brings up the Add Counters dialog, with which we can pick and choose what counters we want to track.
For example, here we are adding from the Processor Category, one Counter (% Processor Time):

image

Once we have one or more counters added to our log, we click the Close button to return to our New Counter Log dialog, in order to configure some other basic settings on the other tabs -- in this case, we are defining when we want our logging to occur:

image

 

Clicking OK brings us back to the main dialog, where we can see our new Counter Log definition listed.

You can start using this log to track data at any point, by clicking the recording Start/Stop buttons.

image

 

 

Recording Data into a Counter Log

 

You'll find that it's created a new log in the c:\PerfLogs directory:

image

Reviewing Logged Data

Now that you've created a Counter Log definition, added Counters to it, and used the Start/Stop buttons to log something to a data file, let's load the data back up into the display, and view what we recorded.

Open another PerfMon (or use the same one) and click the View Log Data button:

image

so that you can load up some data from the c:\PerfLogs directory:

image

but don't click OK just yet. If you do...you'll just see a blank screen.

We've loaded the log data file -- but it contains the data of one or more counters (maybe a dozen) -- and we have to tell the application which one's we want to see on the graph. If we were recording a dozen Performance Counters, we wouldn't want to see them all at once -- too cluttered.

We define which ones to display for now by switching to the Data tab, and clicking the Add button:

image

in order to select from the counters in the file (note that this may appear very similar to the general Add Counter dialog that shows every counter on the system, but this view only shows the Counters that were recorded -- in this simple example, just one):

image

When done, click Close, come back to the main dialog, where we can see the graph of our recorded data:

image

 

Analysing the Data

The whole business of monitoring Performance in order to find problems really boils down to:

  • Using PerfMon or PerfWiz to create useful logs containing the data collected from appropriate PerformanceCounters
  • Differentiating between Performance Spikes and Performance Trends.

Performance spikes represent sudden escalations in values that look dramatic on screen -- but they may or may not indicate a problem. By themselves, generally not.

Performance trends are more long term pictures, and are more useful to uncover problems than freaking out over Spikes. Discovering trends involves getting prepared up front, and collecting a baseline -- a period of time when the application was performing satisfactorily.

 

Alerts

 

Finally, I know this has been a long post, but one last thing you should do is investigate Alerts: it will only take a moment.

Alerts are wonderful, because they allow you track PerformanceCounters -- but instead of logging them, react to them.  In other words, you can send yourself an email (see BLAT) when the hard-drive looks like its choking up.

 

image

 

image image

Clicking Add and closing, brings us back to the My New Alert dialog, where we finish up by specify what value we are looking for...
Here I just specified I want to know when the processor % will be over 95%:

image

Before you click out, now that we have defined what we are looking for, switch to the Action pane, where we can specify what to do if an alert goes off:

 image

That's it -- the Alert has been created, and is currently working away in the background:

image

Which you can see by opening up the Event Viewer, spotting the entry:

image

and viewing it:

image

 

(Note that you can can get all fancy by hooking in scripts and sending emails to yourself rather than just logging errors. If that interests you, check out BLAT).

 

Links:

 

In fact...that's the point -- let's click Start, run it for a minute or so...and then Stop it.

BookMark: Trackback

What now?!?

You've got to the end of the post...now what?

Well...a Comment would be nice... It doesn't have to be long...Will just a take a sec...

Thanks!

And (in a perfect world) if I was able to save you some time on your project:

5 comment(s) so far...

Re: C#: Crash course tutorial on using PerfMon to analyse PerformanceCounters

Very informative Article.. Thanks..

By Balaji Km on   8/27/2009 8:51 PM

Re: C#: Crash course tutorial on using PerfMon to analyse PerformanceCounters

Thank you a very a useful tutorial, but I have a couple of questions.

1. When I name the log it always gives an extension of .etl (I cannot change this)

2. I would like to save it as .CSV - Can I do this?

By Jim M on   11/24/2009 9:00 AM

Re: C#: Crash course tutorial on using PerfMon to analyse PerformanceCounters

Not that I am aware of.

By Sky on   11/24/2009 9:02 AM

Re: C#: Crash course tutorial on using PerfMon to analyse PerformanceCounters

Great article, thanks.

I do the logging as above and then use

tracerpt mylogfile.etl

to extract the log files to a csv which I can then open in excel for analysis. The only thing puzzling me is the 'clock time' column in the csvwhich gives a number like 129185803104131000. Any idea what this represents and how I convert it to a 'useable' time?

By John Daisley on   5/18/2010 3:03 AM

Re: C#: Crash course tutorial on using PerfMon to analyse PerformanceCounters

Great ..it helped me a lot....please do provide the details about windows 2008 server...with screen shots as above...

By Raj on   7/2/2010 3:57 PM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
Copyright 2007 by Sky Sigal