Wednesday 31 December 2014

Code Profiler

The Code Profiler measures the execution time of individual lines of code. Use this tool to find performance bottlenecks and to help understand code that was developed by others.

     How to use Code Profiler

Ø  Click Tools > Code profiler to open the Code Profiler tool.
Ø  Navigate to the functionality that you want to test. For example, navigate to the appropriate place in the Navigation Pane.
Ø  To limit the results displayed, check the Trace depth enabled check box, and then type the number of levels that you want to be displayed in the results.
Ø  Click Start. Use the functionality you want to test. When testing is complete, click Stop. The system now saves all logged data to the database. This might take quite some time because a database record is created for each executed line of code.
Ø  Write a description of your code profile in the Summary dialog.
Do not select the Calculate line total check box. If you need to calculate line totals later, use the Profile runs form.
Ø  Click OK.
The Profiler runs form opens. This enables you to view data collected by the profiler.

   To view the data that is collected by the code profiler

Ø  Click Profiler runs.
Ø  Select the data set that you want to view.
Ø  Click the Statistics tab to view a summary of the information for the code profile.
Ø  Click one of the following four buttons to view more detailed data:
Call tree – Shows you a hierarchy of method calls
Profile lines – Shows a list of all lines of code that are executed, making it easy to find which lines of code took the longest to execute.
Traverse – Shows a sorted list of the time that was spent in all methods, combined with the sum of the time spent in sub calls, plus the sum of the time spent in the method, depending on the origin of the call.
Totals – Allows you to select summaries of the time spent in lines, methods, and objects.

    The Call treeProfile lines, and Traverse forms show raw data. Aggregated data is available in                            the Totals options.

  Using code Profiler in X++

As an alternative to the graphical user interface, you can control the code profiler directly from your X++ code. For this purpose there are two macros:
·         #Profilebegin()
·         #ProfileEnd
These two macros have to be in the same level in a method.



static void codeProfilerTest()
{
    int   i, j;
    ;  
    #profileBegin("test")  
    
    for(i=1;   i<=10; i++)
    {  
        j+=   i*i;
    }  
    
    info(strfmt("%1",j));  
    #profileEnd  
}

You will then have to find the collected data under Tools > Code profiler > Profiler runs, and process the data yourself by selecting Totals > Calculate sum.


No comments:

Post a Comment