Optimizing Performance Using Code Profilers

Download Report

Transcript Optimizing Performance Using Code Profilers

Optimizing Performance Using
Code Profilers
Phil Wolfe, MCSD, MCAD, MCDBA
RAD .NET Architect
Werner Enterprises
Agenda
•
•
•
•
•
•
•
•
Overview
Why Profile Code
Code Profilers
Where to Profile
How to Profile
Windows Example
Conclusion
Resources
Overview
• Profilers measure performance
• Not a test suite
• Compare to sphygnometer not
stethoscope
• Types of profilers:
– Code – Watching lines of code
– Memory – Watching memory use and
management
– Hardware – Comparing output to standard
Why Profile Code
• Developers don’t always write code in the
most efficient way.
• 4GL code doesn’t always translate down in
the most efficient or expected way.
• Frameworks are built to support many
solutions not optimized for any specific
one.
• Like tuning a musical instrument.
Code Profilers
• Measure code performance by:
– Counts (Hit Count)
• Source Code Lines
• Methods
• Modules
– Time
• First hit vs. subsequent hits
• Per method/parent/child(ren) in milli/micro-seconds
• Time in application vs. time in .NET Framework
Short List of Code Profilers
• ANTS 1.3 – www.red-gate.com
• AQTime 4 – www.automatedqa.com
• DevPartner Profiler Community Edition –
www.compuware.com
• NCover – ncover.sourceforge.net
• NProf – nprof.sourceforge.net
Phil’s Profiler Picks
• AQTime 4 – AutomatedQA Corp.
– Price: $599.99
– Profiles: Windows, Web, Serviced
Components, Services
– Displays Source Code
– Integrates with Visual Studio.NET or
Standalone
– Overall: best interface, easiest to use, most
fully-featured, very customizable, and
documented
Phil’s Profiler Picks
• ANTS Profiler – Red Gate Software
– Price: $295
– Profiles: Windows, Web, & Serviced
Component
– Displays Source Code
– Does not integrate with Visual Studio.NET
– Can not profile Windows Service applications
Phil’s Profiler Picks
• DevPartner Community - Compuware
– Price: Free (Pro Ed. $1,700.00)
– Profile: Windows, Web (Serviced Component
& Windows Services with Pro Ed.)
– Displays Source Code
– Integrates with VS.NET
– Needs Framework 1.0 to install (see
resources)
Where to Profile
•
•
•
•
•
•
Slow Calls
“Main” Logic
“Messy” Logic
Everything
New Operating Systems
New .NET Framework Versions
How to Profile
•
•
•
•
•
•
•
Compile in debug
Use the profiler to launch the application
Get a baseline
Start changing code
Start experimenting with other settings
Read the tutorials
Keep in mind while profiling:
– The code is compiled in debug
– JIT happens the first method call
– Other processes on the machine
Windows Example
• Maze application – Dan Fontanesi, Mike
Gold, http://www.gamespp.com/csharp/mazeSolverUsingMultipleThreads.html
• Get a Baseline
• Make modifications
• Test performance
• Examine MSIL
• Make more modifications
• And on and on…
Conclusion
• Performance TUNE your applications by
enhancing code
• More hardware is not always the answer
• Develop baselines and expectations
• Perform code reviews in conjunction with
code profilers
• Choose the right profiler. A free one may
cost more time in the end.
Resources
• See Profilers Slide
• DevPartner installation workaround: To avoid installing the .NET
Framework v1.0 on machines that do not have it installed, copy a
v1.0 mscorlib.dll file to <root drive>\<windows
folder>\Microsoft.NET\Framework\v1.0.3705\mscorlib.dll