# debug.h

Go to the documentation of this file.

    00001 /* $Id: debug.h 14772 2008-12-29 21:50:25Z rubidium $ */
    00002
    00005 #ifndef DEBUG_H
    00006 #define DEBUG_H
    00007
    00008 /* Debugging messages policy:
    00009  * These should be the severities used for direct DEBUG() calls
    00010  * maximum debugging level should be 10 if really deep, deep
    00011  * debugging is needed.
    00012  * (there is room for exceptions, but you have to have a good cause):
    00013  * 0   - errors or severe warnings
    00014  * 1   - other non-fatal, non-severe warnings
    00015  * 2   - crude progress indicator of functionality
    00016  * 3   - important debugging messages (function entry)
    00017  * 4   - debugging messages (crude loop status, etc.)
    00018  * 5   - detailed debugging information
    00019  * 6.. - extremely detailed spamming
    00020  */
    00021
    00022 #ifdef NO_DEBUG_MESSAGES
    00023   #if defined(__GNUC__) && (__GNUC__ < 3)
    00024     #define DEBUG(name, level, args...) { }
    00025   #else
    00026     #define DEBUG(name, level, ...) { }
    00027   #endif
    00028 #else /* NO_DEBUG_MESSAGES */
    00029   #if defined(__GNUC__) && (__GNUC__ < 3)
    00030     #define DEBUG(name, level, args...) if ((level == 0) || ( _debug_ ## name ## _level >= level)) debug(#name, args)
    00031   #else
    00032     #define DEBUG(name, level, ...) if (level == 0 || _debug_ ## name ## _level >= level) debug(#name, __VA_ARGS__)
    00033   #endif
    00034
    00035   extern int _debug_ai_level;
    00036   extern int _debug_driver_level;
    00037   extern int _debug_grf_level;
    00038   extern int _debug_map_level;
    00039   extern int _debug_misc_level;
    00040   extern int _debug_ms_level;
    00041   extern int _debug_net_level;
    00042   extern int _debug_sprite_level;
    00043   extern int _debug_oldloader_level;
    00044   extern int _debug_ntp_level;
    00045   extern int _debug_npf_level;
    00046   extern int _debug_yapf_level;
    00047   extern int _debug_freetype_level;
    00048   extern int _debug_sl_level;
    00049   extern int _debug_station_level;
    00050   extern int _debug_gamelog_level;
    00051   extern int _debug_desync_level;
    00052
    00053   void CDECL debug(const char *dbg, ...);
    00054 #endif /* NO_DEBUG_MESSAGES */
    00055
    00056 void SetDebugString(const char *s);
    00057 const char *GetDebugString();
    00058
    00059 /* MSVCRT of course has to have a different syntax for long long *sigh* */
    00060 #if defined(_MSC_VER) || defined(__MINGW32__)
    00061   #define OTTD_PRINTF64 "I64"
    00062 #else
    00063   #define OTTD_PRINTF64 "ll"
    00064 #endif
    00065
    00066 /* Used for profiling
    00067  *
    00068  * Usage:
    00069  * TIC();
    00070  *   --Do your code--
    00071  * TOC("A name", 1);
    00072  *
    00073  * When you run the TIC() / TOC() multiple times, you can increase the '1'
    00074  *  to only display average stats every N values. Some things to know:
    00075  *
    00076  * for (int i = 0; i < 5; i++) {
    00077  *   TIC();
    00078  *     --Do yuor code--
    00079  *   TOC("A name", 5);
    00080  * }
    00081  *
    00082  * Is the correct usage for multiple TIC() / TOC() calls.
    00083  *
    00084  * TIC() / TOC() creates it's own block, so make sure not the mangle
    00085  *  it with an other block.
    00086  **/
    00087 #define TIC() {\
    00088   extern uint64 ottd_rdtsc();\
    00089   uint64 _xxx_ = ottd_rdtsc();\
    00090   static uint64 __sum__ = 0;\
    00091   static uint32 __i__ = 0;
    00092
    00093 #define TOC(str, count)\
    00094   __sum__ += ottd_rdtsc() - _xxx_;\
    00095   if (++__i__ == count) {\
    00096     DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
    00097     __i__ = 0;\
    00098     __sum__ = 0;\
    00099   }\
    00100 }
    00101
    00102 void ShowInfo(const char *str);
    00103 void CDECL ShowInfoF(const char *str, ...);
    00104
    00105 #endif /* DEBUG_H */