logging optimization.
-
Hi Friends, My product has a feature of logging. Currently it is simple MACRO based where during release build compiler removes logging function calls. Now I am planning to make logging available during release build as well. As a result user will simply pass some command line parameter during process start and things will start logging. Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost. Is there any way to optimize these checks? Are there any way where I can bypass these checks during normal functional behavior. Assembly, C, C++ compiler/code specific suggestions are welcome. - Vikram S
-
Hi Friends, My product has a feature of logging. Currently it is simple MACRO based where during release build compiler removes logging function calls. Now I am planning to make logging available during release build as well. As a result user will simply pass some command line parameter during process start and things will start logging. Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost. Is there any way to optimize these checks? Are there any way where I can bypass these checks during normal functional behavior. Assembly, C, C++ compiler/code specific suggestions are welcome. - Vikram S
-
Hi Friends, My product has a feature of logging. Currently it is simple MACRO based where during release build compiler removes logging function calls. Now I am planning to make logging available during release build as well. As a result user will simply pass some command line parameter during process start and things will start logging. Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost. Is there any way to optimize these checks? Are there any way where I can bypass these checks during normal functional behavior. Assembly, C, C++ compiler/code specific suggestions are welcome. - Vikram S
vikrams wrote:
Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost.
You mean you cant even check like this too? if( bLogEnabled ) { // code for logging... }
- ns ami -
-
vikrams wrote:
Now as logging code will be present in my binary during release time, this will enforce some types of checks even if the logging is not enabled which will lead to CPU cost.
You mean you cant even check like this too? if( bLogEnabled ) { // code for logging... }
- ns ami -
I can do this. But When there are hundreds of checks at runtime, will this be not an issue? - Vikram S
-
I can do this. But When there are hundreds of checks at runtime, will this be not an issue? - Vikram S
AFAIK, this 'if' check will not bring any noticable change in the performance. I know even more complex logging mechanisms are used in professional softwares. Also you can avoid logs (if that much necessary) in some extremely performance oriented functions. Note: You may simplyfy the code (only look) using by using macros, so that repeated if blocks can be avoided. Eg.
#define LOG(x) if( bLogEnabled ) { LogString( x ); }
- ns ami -