Apex Log Analyzer, a tool designed with Salesforce developers in mind, is here to simplify and accelerate your performance analysis. With its intuitive Flame charts and Call Trees, you can effortlessly visualise code execution, gaining clear insights into the flow and performance of your code. This powerful tool also features Method and Database Analysis, which helps in identifying and resolving performance issues, as well as SOQL and DML problems.
By highlighting inefficiencies and bottlenecks, Apex Log Analyzer empowers you to optimise your code more effectively, ensuring smoother and more reliable application performance. Integrating this tool into your development workflow can save valuable time, enhance productivity, and improve overall code quality.
Apex debug logs provide a detailed record of the execution flow of your Apex code, capturing events such as method invocations, database operations (SOQL/DML), and system debug statements. They reveal your code’s performance and behaviour, highlighting issues like CPU time consumption and memory usage.
By analysing these logs, developers can identify inefficiencies and pinpoint the exact location of errors, enabling more effective troubleshooting and optimisation.
We can all relate to this common scenario where we are expected to find the cause of bottlenecks in the application’s performance due to the code we recently pushed to meet the delivery schedule. However, it is causing the application to crawl at a snail’s pace. To illustrate this, I created three Apex classes with their respective methods, which are better than each other relatively.
Then I made them run in my developer edition org and analysed the logs to see what insights it gathered for me to present my tech lead with the cause of slowness and any solutions or workaround we can find. You will be surprised to see that it actually tells us the time in milliseconds visually in various colours so that anyone can deduce the crux of the matter and start planning the next steps for resolution.
Here is the sample code and how I ran it:
public class InefficientClass {
public static void inefficientMethod() {
// Simulating an inefficient operation: Nested loops causing high CPU usage
Integer result = 0;
for (Integer i = 0; i < 1000; i++) {
for (Integer j = 0; j < 1000; j++) {
result += i * j;
}
}
System.debug('Result: ' + result);
}
}
public class EfficientClass {
public static void efficientMethod() {
// Optimized operation: Single loop with more efficient computation
Integer result = 0;
for (Integer i = 0; i < 100000; i++) {
result += i * 2; // Simplified operation
}
System.debug('Result: ' + result);
}
}
public class LighterClass {
public static void lighterMethod() {
// Optimized operation: Direct computation without unnecessary loops
Integer n = 1000000;
Integer result = (n * (n - 1)) / 2;
System.debug('Result: ' + result);
}
}
Once the above Classes are deployed to the org, now is the time to run all of them in one go so that the Log Analyzer can gather the stats and show in one unit of work with times taken by each method.
// Execute the inefficient method
InefficientClass.inefficientMethod();
// Execute the efficient method
EfficientClass.efficientMethod();
// Execute the lighter method
LighterClass.lighterMethod()
Now is the time to run the open command palette, run
sfdx turn on apex debug logs
Which will start collecting and recording for the next 30 minutes by default. Then run
sfdx get debug logs
which should open the Apex Debug Log. Now is the time for the moment of truth! Hit the
Log: Show Apex Log Analysis
Written at the top of an Apex Debug Log file you will start seeing the visual analysis with meaningful information about SOQL and DMLs done if there were any in your apex code. In this case, I realised that lighterMethod was a simpler version of all the other versions I wrote since it was the fastest and took less than 0.2 ms. On the other hand, efficientMethod took 1367ms whereas inefficientMethod took 13855ms.
That was the call tree’s output, but the Analysis tab is even better since it shows the Total Time needed, which is around 15000 ms.
Apex Log Analyzer is a game-changer for Salesforce developers, turning the often daunting task of debugging and performance analysis into a more manageable and even enjoyable experience. By providing a clear, visual representation of code execution through Flame charts and Call Trees, it demystifies complex logs and brings hidden issues to light. The ability to quickly identify and resolve performance bottlenecks, SOQL/DML inefficiencies, and other critical problems means that developers can spend less time troubleshooting and more time building robust, efficient applications.
The satisfaction of pinpointing the exact cause of a bottleneck and optimising the code brings a genuine smile to a developer’s face, making their job less stressful and more rewarding.
In essence, Apex Log Analyzer truly saves the day by enhancing productivity, improving code quality, and empowering developers to deliver top-notch solutions with confidence and ease.
https://youtu.be/L13KBdQ0JHM?si=Ag-CxR3OCE30cD1C