A Brief Overview of Performance Code Profiling

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.

It is a form of dynamic program analysis that can provide information on the following to aid program performance/optimization;

  1. How long a method/routine takes to execute? (Duration)
  2. How often a routine is called? (Frequency)
  3. Tracks memory allocations and garbage collections (Memory)
  4. How often SQL statements and web services are called? (Frequency)

Bbbe0ab2 5545 439c A1b5 B2b1a5a2fda2

Different Types of Code Profilers

There are two different types of code profilers:

  1. Server-side Profilers and
  2. Desktop Profilers.

Server-side 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.

Desktop Profilers

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;

  1. CPU issues
  2. Memory issues and
  3. 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; 

  1. Instrumentation
  2. Sampling
  3. Concurrency
  4. .NET Memory
  5. Tier Allocation

Instrumentation

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.

Sampling

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.

Concurrency

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.

.NET Memory

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.

Tier Allocation

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.

https://docs.microsoft.com/en-us/visualstudio/profiling/understanding-performance-collection-methods?view=vs-2017

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.

Get In Touch

Technology Consulting Partners