Profiling is a process of gathering application features, such as an execution time of its individual fragments (functions, lines). MetaEditor has integrated means of code profiling allowing a programmer to optimize a source code.
To launch code profiling, open an application source code (mq4 or mq5) and execute " Start profiling" command in the "Debug" menu or on the "Standard" toolbar.
A special version of the application will be compiled for profiling after that. The trading terminal will then be opened automatically and the application will be launched there.
The application is launched on EURUSD H1 chart by default. To select another symbol and period, specify them on "Debugging" tab of MetaEditor options.
After the application has been launched, you should work with it for some time using all its functions to the maximum possible extent. That is necessary to allow profiler to measure functions and application lines execution time.
Next, the profiling should be stopped using " Stop profiling" command in the "Debug" menu or on the "Standard" toolbar.
To get more accurate results of profiling, remove the program from the chart manually instead of using command " Stop profiling".
View Profiling Results
After profiling completion, its results will be displayed in the special "Profiler" tab of "Toolbox" window. Two modes of viewing the results are available. It is possible to switch between them using the context menu.
"Functions by Calls" Mode
In this mode, the profiling results are presented by functions:
- Function — class function or method name.
- Line — the line, at which the function is called. If the function is called at several locations of the application, its icon will be marked by the special symbol . Clicking on it will open the data on each call.
- Count — number of function calls during the whole time of the application operation.
- Time — function execution time in microseconds and percentage values relative to all functions execution time. Function execution time is a sum of execution times of all functions called within it.
- Graph — functions execution time graph.
The functions types are displayed using the icons:
- — custom function;
- — system function;
- — event handling function (On*);
- — class method.
Apart from the mentioned functions types, the profiler also displays:
- @global_initializations — data on all global variables initialization;
- @global_deinitializations — data on all global variables deinitialization;
To view a function in a file, double left click on it.
The profiler displays only the functions that have been called during the application operation.
"Functions by Lines" Mode
In this mode, the data on the application operation time is represented by lines. The lines are grouped by the application functions.
- Function — function name.
- Line — index of the line, for which the data is displayed. To view the data on each function line execution time, click the icon .
- Count — the number of times a code was executed in a specified line.
- Time — code execution time in a specified line in microseconds and percentage values. Percentage values are displayed for each line relative to the function execution time. Percentage values for functions are displayed relative to the whole application execution time.
- Graph — execution time graph.
To view a line in a file, double left click on it.
The following commands are available in the context menu:
- Open — move to a line or a function in a source code file. The same action can be executed by double clicking or pressing Enter.
- Expand All — expand all collapsed functions;
- Collapse All — collapse all expanded functions;
- Functions by Lines — switch to viewing profiling results by lines;
- Functions by Calls — switch to viewing profiling results by calls;
- Export — export profiling results in Open XML (MS Office Excel), HTML (Internet Explorer) or CSV (Text file).
- Auto Arrange — enable/disable automatic sizing of fields. The same action can be done by pressing "A";
- Grid — show/hide grid to separate fields. The same action can be done by pressing "G".