Thursday, December 29, 2011

PerfMonitor primer

Perfmonitor is a ETW based tool for 'profiling' managed code, it can be downloaded from CodePlex. The December issue of MSDN magazine has a nice article to get you started: Performance Diagnostics of .NET Applications Using ETW. It works best on .NET 4.0 but some features also work on CLR2.x/.NET 3.5.

One of the great things about PerfMonitor (besides being a free download) is that it is easy to install on a target system (no installers just copy the exe). Just carry it along on your USB drive and within minutes your are ready to gather data which can help you solve a performance problem.

The tool has a build in manual, running the tool without a commandline parameters will start your browser and will show the user guide.

There are two steps to using the tool
1. Collect data
2. Post processing of the data and generating a report.

A typical scenario might look like this:
  1. Get the process ID of the process your are monitoring (tasklist)
  2. start the collection: perfmonitor.exe collect
  3. <perform use case>
  4. <stop collection>
  5. Merge the ETL files that have been generard: performonitor.exe merge
  6. Generate the report: performonitor.exe /process:<ProcID> analyze 
  7. Evaluate the report
A list of command line options and qualifiers can be found below.

Data collection
To collect the data there are a number of options (the complete overview can be found in the table below):
  1. Explicitly start and stop the data collection (perfmonitor.exe start [<filename.etl>] / performonitor.exe stop)
  2. perfmonitor.exe collect
  3. perfmonitor.exe. runAnalyze <executable>
    The 'runAnalyze' option collects the data and automatically generates a report.

Data CollectionDescription
runAnalyze CommandAndArgs ...Performs a run command then the analyze command.
run CommandAndArgs ...Starts data collection, runs a command and stops.
collect [DataFile]Starts data logging, then displays a messagebox. When dismissed, it then stops collection.
start [DataFile]Starts machine wide profile data collection.
stopStop collecting profile data (machine wide).
abortInsures that any active PerfMonitor sessions are stopped.
listSessionsLists active ETW sessions.
Listen Providers ...Turns on ETW logging for EventSources (providers), and then writes text file (by default to stdout).
runDump CommandAndArgs ...Performs a run command then the Dump command.
monitor CommandAndArgs ...Turns on all event sources, performs a run command.
monitorDump CommandAndArgs ...Turns on all event sources, performs a run command then the Dump command.
monitorPrint CommandAndArgs ...Turns on all event sources, performs a run command then the PrintSources command.

Reporting
 After the data has been collected a report can be generated. This can be done using the following command: perfmonitor analyze [<filename.etl>]

There are several options that can be used when generating the report, here is a list of all the options.

ReportingDescription
analyzeCreates a general performance report report (CPU, GC, JIT ...).
merge [DataFile]Combine separate ETL files into a single ETL file (that can be decoded on another machine).
stats [DataFile]Produce an XML report of what events are in an ETL file.
procs [DataFile]Display the processes that started in the trace.
GCTimeCreates a Report on .NET garbage collection
CpuTimeCreates a Report on CPU usage time.
JitTimeCreates a Report on .NET Just In Time compilation.
etlx [DataFile]Create a ETLX file from the ETL files.
PrintSourcesTakes an ETL file and generates a text file that prints EventSource events as formatted strings.
dump [DataFile]Convert the events to an XML file.
rawDump [DataFile]Convert the events with no preprocessing (thus stacks are individual events, and rundown events are shown.

MiscDescription
UsersGuideDisplays the users Guide.
cpuTestRun a simple, CPU bound routine. Useful as a tutorial example.
listSources ExeFileLists all System.Diagnostics.EventSources in a executable (or its static dependencies)
monitorProcsEXPERIMENTAL: Monitor process creation in real time.


Here is an overview of all the qualifiers
Qualifiers Description
-BufferSize:INT32(64)The size the buffers (in MB) the OS should use. Increase this if PerfMonitor warns you that the log lost events.
-Circular:INT32(0)Do Circular logging with a file size in MB. Zero means non-circular.
-MergeDo a merge after stopping collection.
-EtlxConvert to etlx (contains symbolic information) after stopping collection.
-NoRundownDon't request CLR Rundown events.
-RundownTimeout:INT32(30)Maximum number of seconds to wait for CLR rundown to complete.
-MinRundownTime:INT32(0)Minimum number of seconds to wait for CLR rundown to complete.
-SymbolsForDlls:STRING,...A comma separated list of DLL names (without extension) for which to look up symbolic information (PDBs).
-PrimeSymbolsNormally only machine local paths are searched for symbol info. This indicates symbol servers should be searched too.
-DataFile:STRINGFileName of the profile data to generate.
-AdditionalProviders:STRING,...Providers in ADDITION to the kernel and CLR providers. This is comma separated list of ProviderGuid:Keywords:Level specs.
-Providers:STRING,...Providers to turn on INSTEAD of the kernel and CLR providers. This is comma separated list of Provider:Keywords:Level specs were Provider is either a GUID, or @FileName#EventSourceName.
-ClrEvents:KEYWORDS(Default)A comma separated list of .NET CLR events to turn on. Legal values: None, GC, Binder, Loader, Jit, NGen, StartEnumeration, StopEnumeration, Security, AppDomainResourceManagement, JitTracing, Interop, Contention, Exception, Threading, Default, Stack.
-KernelEvents:KEYWORDS(Default)A comma separated list of windows OS kernel events to turn on. See Users guide for details. Legal values: None, Process, Thread, ImageLoad, ProcessCounters, ContextSwitch, DeferedProcedureCalls, Interrupt, SystemCall, DiskIO, DiskFileIO, DiskIOInit, Dispatcher, MemoryPageFaults, MemoryHardFaults, VirtualAlloc, NetworkTCPIP, Registry, AdvancedLocalProcedureCalls, SplitIO, Driver, OS, Profile, Default, FileIO, FileIOInit, Verbose, All.
-NoBrowserDon't launch a browser on an HTML report.
-Process:STRINGFilter events to just one process with the given name (exe without extension) or numeric process ID.
-StartTime:DOUBLE(0)Filter events happening before this time (msec from start of trace.
-EndTime:DOUBLE(Infinity)Filter events happening after this time (msec from start of trace.
-Threshold:SINGLE(5)Stack items less than this % threshold are folded into their parent node.
-NoOSGroupingTurn off the grouping of OS functions in stack traces.
-NoBrowserDon't launch a browser on an HTML report.
-WriteXmlWrite an XML report as well as the HTML report.

Ok, I hope that this gets you started with this great tool!

No comments:

Post a Comment