How to do Code and Performance Analysis using Visual Studio
set of tools for code and performance analysis is essential for the developers
if they need to develop reliable and robust software. These tools should be capable
of detecting the errors and the defects in the coding and the performance errors
so that they are corrected at an earlier stage in the development.
This is essential to reduce the overall cost of developing that application.
In the earlier versions of the Visual Studio there were no Analysis tools available.
Hence the developers have to depend on the third party tools or create their own
custom analysis tools or ship the code without analysis.
This is overcome
in the latest version of the Visual Studio Team System. With the integration of
the Analysis Tools in the Visual Studio environment it is possible to work efficiently
in building the application.
analysis tools in the Visual Studio 2005 Team System can be categorized into two
types. They are the Code Analysis Tools and the Performance Analysis Tools. These
tools are integrated in the Visual Studio environment itself. If needed, you can
also use these tools from the command line.
Studio 2005 Team System has two tools for code analysis. They are PREfast and
FxCop. PREfast is a tool that is used for static analysis. It analysis the code
(C/C++) and gives you the defects that are likely to appear in the code.
of the defects that could be indicated by the use of PREfast are null pointer
reference, memory leaks, resource leaks, un-initialized memory and buffer overrun.
This tool is integrated in the Visual Studio 2005 Team System and you can enable
or disable this tool as you wish.
You can access this from the property
pages of the project. If you enable PREfast and if there is any error that is
detected by PREfast then it appears in the Error list. If you double click the
warning given by PREfast in the error list, it will take you to the actual code
that causes error in the code editor. It is also possible to treat those warning
as errors or ignore the warning. This is achieved by using the directive called
#pragma. The code to treat warning as error is,
warning (error: 6260)
code to ignore or disable warning is,
warning (disable: 6011)
tool also supports annotation where you can get the information on conditions
before function parameter is used and after a function parameter is used. You
can also get information on return types. You can also use the PREfast tool in
the command line.
tool FxCop is used to analyze the code for the violation in design rules and programming.
It also gives you information on the assemblies. The violation of the design and
programming rules are compared to the rules given in the Design Guidelines of
Microsoft .Net Framework.
You can also refer these guidelines in MSDN
website. If possible this tool also gives information on how to fix the violation
that is found by the FxCop tool. Since the tool is integrated with the Visual
Studio 2005 Team System you can access this tool from the Property Pages of the
project. You can use the checkbox option Run FxCop in the property pages. Just
click the checkbox to enable running this tool.
can select the configuration properties and then select the Rules option to enable
the different types of Rules. You can select Rules like ComRules, NamingRules,
and SecurityRules using the checkboxes available for that purpose.
addition to selecting the Rules that you want to enable, you can also set whether
you want those Rules to be treated as Errors or Warnings when they are violated.
When the Project is build the rule violation are reported in the Error List as
Warnings or Errors as selected by you. You can navigate to the exact code of violation
by double clicking the Warning or the Error in the Error List that is displayed.
Performance related problems in the code are identified using the Performance
Tools available in the Visual Studio 2005 Team System. These tools allow you to
measure and evaluate the issues related to performance. Two types of profiling
are done with these performance tools.
They are Sampling and Instrumentation.
Data is collected periodically by interrupting the application in the sampling
method. The data thus collected is used to create a report file which can be analyzed
later using the features available for reporting. The data in sampling method
is collected after the application exits. One of the advantages of using Sampling
method is that the application is interrupted only periodically.
the drawbacks of this method is that you get information based on random sampling.
Instrumentation is a method that gets data for a section of the application. Probes
are inserted which signals the start and stop of collecting data. The data collected
are store for later analysis. The users can get the exact data that were used
during the execution.
the Performance Session Wizard available in Visual Studio 2005 Team System you
can create profiling for the applications. You can begin with sampling and then
based on the results of sampling you can use instrumentation for a specific portion
of the application.
The profiling environment can be setup using the Performance
Session Wizard. Support for ASP.Net, EXE, and DLL applications are provided by
the Performance Session Wizard. You can go to Tools -> Performance Tools ->
Performance Wizard to start a new Performance Session. Instead you can also use
the New Performance Session option to create it manually.
You can use
the Performance Explorer to get more information about the Performance Session.
Performance Reports are automatically added to the Reports node in the Performance
Explorer after the application has finished running.
types of views are available for viewing the reports. Summary, Functions, Caller/Callee,
CallStack and Type are the views that are available for the reports. The Summary
view is used as the starting point of the analysis.
The Functions view
gives the functions that were executed when the application was run. The functions
that are displayed depend on the method of profiling used. To get information
on the functions that are listed you have to use the Caller/Callee view.
more information on the tools used for the code analysis and performance analysis
you can always refer to the MSDN website. Its no wonder that these tools
are used for building reliable and robust applications.
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
: We never rent, trade, or sell my email lists to
We assure that your privacy is respected
.NET Programming Tutorial Homepage