MQLplus/lib_debug/example/lib_debug_CustomConfig.mqh
super.admin 466f9ca5c5 convert
2025-05-30 16:09:52 +02:00

418 lines
16 KiB
MQL5

#ifndef LIB_DBG_DEBUG_MQLAPI_CUSTOMCONFIG_MQH_INCLUDED
#define LIB_DBG_DEBUG_MQLAPI_CUSTOMCONFIG_MQH_INCLUDED
#property version "5.10"
/**********************************************************************************
* No Copyright (C) applied.
* No Lisence applied.
*
* This file is the lib_debug custom config include file.
*
**********************************************************************************
*
* Version: 5.10
* State: public
*
* File information
* ================
*
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// !!! NOTE !!!
//
// In case you have reached this file because you would like to exclude some functions from being
// traced by the library, following suggestion to not edit the distribution-file, you are looking at
// right now.
//
//
// Make a copy of this file.
//
// Copy the file to your project and make your required changes in the copy, instead of this file.
// It is quite unlikely this file will change much in the future, therefore making copies will
// not interfere with any updates to lib_debug. - This way you can update to any newer version
// without loosing your changes.
//
//
// Handle project specifics
//
// After making a copy of this file rename it to your convenience.
// Now change the include in your main project from:
//
// #include <MQLplus/lib_debug.mqh>
//
// to >this copied file<, ie:
//
// #include "my_renamed_lib_debug_CustomConfig.mqh"
//
// Note the enclosure used, but I guess, since you reached this file, you are familiar with this.
// Rename it to whatever you like. - You should include the name of the project, (for your future self...)
// I.E: lib_debug_CustomConfig.mqh >>> lib_debug_MyProjectname.mqh
//
//
// Use this file for your project
//
// Now you just use this file as if it were the original include file from the distribution (lib_debug.mqh).
// Apply your switches and changes as they are required for your project.
// Integration is seemless and you will have a project specific lib_debug configuration.
//
// Make changes to this file as required.
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LIB_DEBUG custom project configuration settings
//
//#define LIB_DEBUG
//#define LIB_DEBUG_AUTOENABLE
//#define LIB_DEBUG_LOGFILE
//#define LIB_DEBUG_NO_JOURNAL_OUTPUT
//#define LIB_DEBUG_MQLAPI_TRACE
//#define LIB_MQLAPI_TRACE
#define LIB_MQLAPI_TRACE_CUSTOM_EXTENSION
//#define LIB_PERF_PROFILING
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// MT4/5 API remove function from the MQLAPI tracer
//
//
// You can exclude any function from the tracer as your project needs it.
//
// Use DBG_MQLAPI_NOTRACE_*** to remove a function from the tracer module.
// You can remove any function from the tracer this way.
//
// See example below.
//
// For a complete list of all traced functions, see file
// "MQLplus/lib_debug/lib_debug_mqlapi_tracer_overwrite_macros.mqh"
//
// This will remove 'Alert' function from the tracer module
//#define DBG_MQLAPI_NOTRACE_Alert
// This will remove 'round' function from the tracer module
//#define DBG_MQLAPI_NOTRACE_round
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LIB_DEBUG customize the API-Tracer to trace your own functions
//
//
// 1. Your function definition must be included first.
//
// #include "your_custom_function_definitions.mqh"
//
// // Now include this file instead of "lib_debug.mqh"
// #include ">this...file<"
//
//
// 2. Inform the library of your custom extensions
//
// If this is not defined, your custom extensions will not be loaded
// this way you can turn them on and off as required. You can also
// define this in your main file, outside of this file. Do so before you
// include this file.
// #define LIB_MQLAPI_TRACE_CUSTOM_EXTENSION
//
//
// 3. Write the tracer code as required
//
// Now add your functions to this class for which you want tracing code to be injected
// Follow the examle below to see how it is done.
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Include trace code wrapper
#include <MQLplus/lib_debug/lib_debug_mqlapi_definitions.mqh>
#ifdef LIB_MQLAPI_TRACE_CUSTOM_EXTENSION
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Custom extension begin
//
#ifdef __MQL5__
namespace dbg_lib {
#endif
// API Tracer Object
class LIB_DBG_MQLAPI_TRACER_CUSTOM_OBJECT
{ public:
/********************************************************************************************************************************************************************
*
*
* YOUR CUSTOM CODE BEGINS HERE...
*
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Define the functions you want to trace
//
// Function name must begin with
// "dbg_userapi_trace_func_"
// and then add your actual function name.
//
//
// Example, this is your function you would like to trace
//
// This function is defined somewhere in before included
// include file. "your_custom_function_definitions.mqh"
//
// template <typename T>
// bool MyArraySort(T& array[]) { /* your function code body here */ };
//
// Important is parameter signatures of the functions
// are the same, see below.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Custom function with a return value
//
////////////////////////////////////////////////////////
//
// Define the function wrapper
//
// Wrapper function name must start with
// "dbg_userapi_trace_func_"
//
// Here we will use a templated function, you could use also normal functions.
template <typename T>
// The functino name must begin with "dbg_userapi_trace_func_", followed by your actual function name
bool dbg_userapi_trace_func_MyArraySort(T& array[])
{
// Define the return value of your function
DBG_USERAPI_RETURN_TYPE(bool);
// Call the setup-macro for code tracing
// Takes in one argument, a name to identify your API.
DBG_USERAPI_TRACE_SETUP("MyAPI");
// Load the input parameters onto the tracer output stack,
// The macro must be filled with all 8 parameters.
// The first parameter is the count of arguments (1-7).
DBG_USERAPI_PARAMS(1, array, 0, 0, 0, 0, 0, 0);
// Now call your actual function, just as you would do in your normal code.
retval = MyArraySort(array);
// Load the output parameters onto the tracer output stack
// The macro must be filled with all 8 parameters.
// The first parameter is the count of arguments (1-7).
DBG_USERAPI_RESULTS(1, array, 0, 0, 0, 0, 0, 0);
// Output will be printed in case _LastError is not ERR_SUCCES / ERR_NO_ERROR
//
// For customization, it is possible to force printing, regardless of _LastError
// Insert the macro "DBG_USERAPI_PRINT_PARAMS" for printing input parameters.
// Insert the macro "DBG_USERAPI_PRINT_RESULT" for printing results.
//
// If omitted, the default settings will apply.
//DBG_USERAPI_PRINT_PARAMS;
//DBG_USERAPI_PRINT_RESULT;
// Call the finalize-macro for code tracing
DBG_USERAPI_TRACE_FINALIZE;
// Return the result from your function
return(retval);
};
////////////////////////////////////////////////////////
//
// Define the function replacement macro
//
// If this is not defined, tracing will be disabled.
// The macro takes in one argument.
//
// NOTE
// Define this after the wrapper function,
// else you will receive a 'Stack overflow'
// error.
//
#define MyArraySort DBG_USERAPI_TRACE_FUNCTION(MyArraySort)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Custom function of VOID-Type
//
////////////////////////////////////////////////////////
//
// Define the function wrapper
//
// Wrapper function name must start with
// "dbg_userapi_trace_func_"
//
void dbg_userapi_trace_func_MyPersonalVoidFunc(int arg01, int arg02, int arg03, int arg04, int arg05, int arg06, datetime arg07, string& arg08, color arg09, double arg10)
{
// Define the return value to be of type void.
DBG_USERAPI_RETURN_TYPE_VOID;
// Call the setup-macro for code tracing
// Takes in one argument, a name to identify your API
DBG_USERAPI_TRACE_SETUP("MyAPI");
// Load the input parameters onto the tracer output stack,
// The macro must be filled with all 8 parameters.
// The first parameter is the count of arguments.
//
// Note the ordering of calls, the pushing to the stack
// is in reverse order, last arguments first.
//
// arg08 is omitted here, because it is used as the output
// and therefore not relevant to us as an input to the function.
//
DBG_USERAPI_PARAMS(2, arg09, arg10, 0, 0, 0, 0, 0);
DBG_USERAPI_PARAMS(7, arg01, arg02, arg03, arg04, arg05, arg06, arg07);
// Some custom code, which will be part of the tracer output.
// As an example, we will measure the runtime of this function
// and print the result as part of the output stack.
ulong runtime = GetMicrosecondCount();
// Now call your actual function, just as you would do in your normal code.
MyPersonalVoidFunc(arg01, arg02, arg03, arg04, arg05, arg06, arg07, arg08, arg09, arg10);
// Finalize runtime measurement
runtime = GetMicrosecondCount() - runtime;
// Load the output parameters onto the tracer output stack.
// Here we will push the result in arg08 from a reference to the output stack
// In case your function has no output at all, this macro can be omitted.
//
// We will add the runtime as well to the output, so we can see the time
// we measured.
DBG_USERAPI_RESULTS(2, arg08, runtime, 0, 0, 0, 0, 0);
// Output will be printed in case _LastError is not ERR_SUCCES / ERR_NO_ERROR
//
// For customization, it is possible to force printing, regardless of _LastError
// Insert the macro "DBG_USERAPI_PRINT_PARAMS" for printing input parameters.
// Insert the macro "DBG_USERAPI_PRINT_RESULT" for printing results.
//
// If omitted, the default will apply.
DBG_USERAPI_PRINT_PARAMS;
DBG_USERAPI_PRINT_RESULT;
// Call the finalize-macro for code tracing
DBG_USERAPI_TRACE_FINALIZE;
// Return void
return;
};
////////////////////////////////////////////////////////
//
// Define the function replacement macro
//
// If this is not defined, tracing will be disabled.
// The macro takes in one argument.
//
// NOTE
// Define this after the wrapper function,
// else you will receive a 'Stack overflow'
// error.
//
#define MyPersonalVoidFunc DBG_USERAPI_TRACE_FUNCTION(MyPersonalVoidFunc)
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
/*
*
...YOUR CUSTOM CODE ENDS HERE *
*
*
*********************************************************************************************************************************************************************/
};
#ifdef __MQL5__
}; // Namespace dbg_lib
#endif
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
#endif // Custom extensions
// Close custom trace wrapper and include distribution library
#include <MQLplus/lib_debug.mqh>
// Include function overwrite macros
#include <MQLplus/lib_debug/lib_debug_mqlapi_tracer_overwrite_macros.mqh>
//
// END Debugging support
//*********************************************************************************************************************************************************/
#endif // LIB_DBG_DEBUG_MQLAPI_CUSTOMCONFIG_MQH_INCLUDED