MetaEditor Hilfe

Code Profiling

Code Profiling

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.

Profiling can be performed on the normal chart of the trading platform, as well as using history data in the Strategy Tester. In the first case, a program is launched on a chart that is updated in real time. You can check the program behavior in real conditions. In the second case, the program is launched in the Strategy Tester in the visual mode. The advantage of this method is that you do not need to wait for real data from a trade server.

Many programs, especially indicators, only perform calculations at the arrival of a new tick (OnTick, OnCalculate). Thus, in order to evaluate performance, you have to wait for new ticks in real time. When profiling using history data, you can immediately provide the required load and test the program performance even on weekends when markets are closed.

Profiling Launch

To launch code profiling, open an application source code (mq4 or mq5). In the "Debug" menu or on the "Standard" toolbar, click "Start Profiling on Real Data Start Profiling on Real Data" or "Start Profiling on History Data Start Profiling on History Data".

After that, a special program version for profiling will be compiled automatically. Depending on the selected profiling type, the program will be launched on a normal chart in the trading terminal or in the Strategy Tester (in the visual mode).

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 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 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

Profiling results

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 Expand. 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—  custom function;
  • System function — system function;
  • Event handling function— event handling function (On*);
  • Class method— class method.

Apart from the mentioned functions types, the profiler also displays:

  • System function@global_initializations — data on all global variables initialization;
  • System function@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

Profiling results

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 Expand.
  • 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.

Context menu

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".