I use this macro, which should allow it to remove the 'server_print(...)'
statements completely from the code:
Code:
/** * This is to view internal... * * ... * 31 - Levels 1, 2, 4 and 8. * * Default value: 0 */#define DEBUG_LEVEL 0/** * Setup the debugging tools when they are used/necessary. */#if DEBUG_LEVEL & ( DEBUG_LEVEL_NORMAL | DEBUG_LEVEL_CRITICAL_MODE )#define DEBUG#define LOGGER(%1) debugMesssageLogger( %1 )/** * ... * 128 - Functions entrances messages. * 255 - Enables all debug logging levels. */new g_debug_level =1+4+8+16;
/** * Write debug messages accordantly with the 'g_debug_level' variable. * * @param mode the debug mode level, see the variable 'g_debug_level' for the levels. * @param text the debug message, if omitted its default value is "" * @param any the variable number of formatting parameters * * @see the stock writeToTheDebugFile( log_file[], formated_message[] ) for the output log "_galileo.log". */stock debugMesssageLogger(const mode, const message[]="", any:... ){if( mode & g_debug_level ){static formated_message[ MAX_BIG_BOSS_STRING ];
vformat( formated_message, charsmax( formated_message ), message, 3);
writeToTheDebugFile("_galileo.log", formated_message );
}}#else#define LOGGER(%1) allowToUseSemicolonOnMacrosEnd()stock allowToUseSemicolonOnMacrosEnd(){}#endif
Now the options
1st
When disabling the debug, we need to set the '#define LOGGER(%1)' to something. On the above code,
it is being setted to 'allowToUseSemicolonOnMacrosEnd()'. But is not what we want to, when disabling
the debug, because it still inserting instructions on the binary code. More precisely, this assembly instructions:
Does not look good enough, thought. It is supposed to be nothing, instead of 'load.pri 0'.
And this is very pain in the ass, as the compiler shows to each use a dawn warning:
Code:
: warning 215: expression has no effect
4th
Using a increment operation would remove the warning:
Code:
new g_dummy_value;
public cmd_go(){
g_dummy_value++;
}
The difference from this to the 3rd option which was 'load.pri 0', is 'inc 0'. So, instead of
just placing zeros on the 'pri' register, we are now incrementing a variable on the '0' address.
Ending
Would be awesome if I could use something like this:
Code:
#define LOGGER(%1) //
or
#define LOGGER(%1)
When disabling macros for the 'DEBUG_LEVEL' 0. But it does not work, and it is ignored. The compiler
keeps throwing the error:
Code:
: error 036: empty statement
This is happening because every line on the code, including the 'LOGGER' macros ending, are using
semicolons, then when the preprocessor removes the macros for the 'DEBUG_LEVEL' 0, the several lines
end up with the empty statement error.
Here are the profiler timing for the macros alternatives:
Code:
date: Tue Jul 1922:36:01 2016 map: de_dust2
type | name | calls | time/min/max-------------------------------------------------------------------
n | register_plugin | 1 | 0.000005/0.000005/0.000005
n | register_srvcmd | 1 | 0.000036/0.000036/0.000036
n | server_cmd | 1 | 0.000005/0.000005/0.000005
p | cmd_go | 1 | 0.000002/0.000002/0.000002
p | plugin_init | 1 | 0.000002/0.000002/0.000002
f | callOnlyMacro | 1 | 0.079895/0.079895/0.079895
f | callMother_fuke | 1 | 0.089007/0.089007/0.089007
f | callOnMacrosEnd | 1 | 0.897962/0.897962/0.897962
f | allowToUseSemicolonOnMacrosEnd | 10000000 | 0.890177/0.000000/0.0010220 natives, 0public callbacks, 2 function calls were not executed.
'callOnMacrosEnd' is the 1st above option.
'callOnlyMacro' is the 2nd above option.
'callMother_fuke' is the 4th above option.
This was the source code used:
Spoiler
Code:
#include <amxmodx>#include <amxmisc>#define PLUGIN "Benchmark"#define AUTHOR "addons zz"#define VERSION "1.0"newconst MAX_TO_LOOP_INTO =10000000newbool:g_dummy_value =false;
new mother_fuker;
public plugin_init(){register_plugin(PLUGIN, VERSION, AUTHOR)register_srvcmd("go", "cmd_go")}public cmd_go(){
callMother_fuke();
callOnMacrosEnd();
callOnlyMacro();
server_cmd("restart")}stock callOnlyMacro(){for(new index =0; index < MAX_TO_LOOP_INTO; index++){do{}while( g_dummy_value );
}}stock callMother_fuke(){for(new index =0; index < MAX_TO_LOOP_INTO; index++){
mother_fuker--;
}}stock callOnMacrosEnd(){for(new index =0; index < MAX_TO_LOOP_INTO; index++){
allowToUseSemicolonOnMacrosEnd();
}}stock allowToUseSemicolonOnMacrosEnd(){}
Results
I can remove the semicolons from the macros ending, then the option:
Code:
#define LOGGER(%1)
Will work just fine, because there will be any ': error 036: empty statement'.
I want to keep adding semicolons to the macros ending to keep a pattern on the source code,
putting everything which looks like instructions under the same design.
If I keep the semicolon on the macros ending, I need to use one of the options 1, 2, 3 and 4 above.
I want to keep the semicolons, then it is acceptable to use some the those options?
Or do you know something I am missing and could allow to add semicolons to the macros
ending, allowing them to be enabled or disabled by the 'DEBUG_LEVEL' variable?