One method used in the development process to improve the performance of code is called ‘performance code profiling’, this article will attempt to explain the types and the data collection methods of profiling available in Visual Studio.
What is Performance Code Profiling?
Performance code profiling is used by developers to help identify and analyse the performance of applications, for instance, to help improve poorly performing sections of code.
- How long a method/routine takes to execute? (Duration)
- How often a routine is called? (Frequency)
- Tracks memory allocations and garbage collections (Memory)
- How often SQL statements and web services are called? (Frequency)
Different Types of Code Profilers
There are two different types of code profilers:
- Server-side Profilers and
- Desktop Profilers.
For server-side code profiling, most organisations have a tendency to use APMs (application management tools) i.e. these profilers can track the performance of transactions, such as tracing how long a web request takes, how long a query takes, whilst also giving you expanded views into the errors and logs that occur.
For desktop code profilers examples include Visual Studio refer to https://docs.microsoft.com/en-us/visualstudio/profiling/?view=vs-2017, NProfiler
Desktop code profiling can track the performance of every line of code to find;
- CPU issues
- Memory issues and
- Garbage collection (memory leaks) issues.
A desktop profiler can also figure out every single method that’s being called and identify what uses the most CPU.
Profiling collection methods
There are different ways to measure the performance of an application. Depending on the collection method used, the profiler results will be different.
In Visual Studio at a high level, profiling can fall into the following different collection methods;
- .NET Memory
- Tier Allocation
The instrumentation profiling method collects detailed information about the work that is performed by an application during a profiling run. It does this by inserting code at the beginning and the end of each routine to record when the routine starts and when it exits. The method can also identify when a function calls into the operating system e.g. writing to a file.
The sampling profiling method collects statistical data about the work that an application does during a profiling run. It works by collecting information on the application at a regular interval or sampling frequency and then analysing this data to create a model of where time was spent in the application.
The concurrency profiling method collects information about multithreaded applications. For example, it collects detailed call stack information each time competing threads in an application are forced to wait for access to a shared resource.
The .NET Memory profiling method collects detailed information about .NET memory allocation and garbage collection. For example, it collects information about the type, size, and number of objects created in an allocation or destroyed in garbage collection.
The Tier Allocation profiling method collects information about synchronous ADO.NET function calls to a SQL Server database. This profiling data can be added to the data collected by the instrumentation, sampling, concurrency or .NET memory methods.
Feel free to refer to the following link for more detail on the above collection methods.
In summary, to accurately and successfully isolate bottlenecks in your code, you should use a combination of performance code profilers during the development phase.
To see how SQA Consulting can help and assist your company to isolate bottlenecks by using performance code profilers, please contact us.