Dynamics 365 Business Central: introducing the AL profiler

With the Dynamics 365 Business Central 2021 Wave 2 release (version 19), silently a new hidden feature was introduced: the AL profiler.

I’ve mentioned this feature on a blog post announcing my top new features for the v19 release and someone of you asked me for more infos. What is this feature? How can I use it?

Snapshot captures now include a performance profile of the executed code that is captured in the snapshot. Using a new performance profiling editor view in the AL Visual Studio Code extension, developers can then investigate the time spent on execution, either using top-down or bottom-up call stack views.

The new AL profiler can be launched directly from Visual Studio Code and it’s linked to the snapshot debugging feature.

From Visual Studio Code, you can start a snapshot debugging by creating a snapshot configuration file. There are two template configurations for a snapshot, which are accessed by selecting Add Configuration in Visual Studio Code:

  • AL: Initialize a snapshot debugging session locally
  • AL: Initialize a snapshot debugging session on cloud

This adds a new configuration section in your launch.json file like the following:

Here you can now add a new parameter called executionContext with the following values:

  • DebugAndProfile: both debugging and profiling is performed
  • Profile: only a profiling session is performed, snappoints will be ignored.

When a configuration is defined, a snapshot debugging session can be initialized by pressing Ctrl+Shift+P and then selecting AL:Initialize Snapshot Debugging or by pressing F7.

You can then perform your actions and you finish a snapshot debugging session by pressing Alt+F7. This brings up all snapshot sessions that have been started. Choosing one will close the session debugging on the server and download the snapshot file.

When you have a downloaded snapshot, you can then execute the new AL: generate profile file from Visual Studio Code:

This new command permits you to select a downloaded snapshot created with a profile-enabled execution context and then it creates a .alcpuprofile file displayed like in the following image:

As you can see, here you have the complete trace of your snapshot execution (events, procedures etc.). For each procedure and/or event you can see the amount of time spent in this function, the amount of time spent in this function and on the functions it calls and the number of calls. The analysis can be conducted top-down or bottom-up.

This is nice feature for checking if your code is performing in a good manner and then for discovering performance problems.

Please remember that only v19 snapshots can contain profile data (it doesn’t work with version 18.x). Start using it… 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.