# debug.h

Go to the documentation of this file.

    00001 /* $Id: debug.h 11979 2008-01-24 18:47:05Z 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
    00051   void CDECL debug(const char *dbg, ...);
    00052 #endif /* NO_DEBUG_MESSAGES */
    00053
    00054 void SetDebugString(const char *s);
    00055 const char *GetDebugString();
    00056
    00057 /* MSVCRT of course has to have a different syntax for long long *sigh* */
    00058 #if defined(_MSC_VER) || defined(__MINGW32__)
    00059   #define OTTD_PRINTF64 "I64"
    00060 #else
    00061   #define OTTD_PRINTF64 "ll"
    00062 #endif
    00063
    00064 /* Used for profiling
    00065  *
    00066  * Usage:
    00067  * TIC();
    00068  *   --Do your code--
    00069  * TOC("A name", 1);
    00070  *
    00071  * When you run the TIC() / TOC() multiple times, you can increase the '1'
    00072  *  to only display average stats every N values. Some things to know:
    00073  *
    00074  * for (int i = 0; i < 5; i++) {
    00075  *   TIC();
    00076  *     --Do yuor code--
    00077  *   TOC("A name", 5);
    00078  * }
    00079  *
    00080  * Is the correct usage for multiple TIC() / TOC() calls.
    00081  *
    00082  * TIC() / TOC() creates it's own block, so make sure not the mangle
    00083  *  it with an other block.
    00084  **/
    00085 #define TIC() {\
    00086   extern uint64 _rdtsc();\
    00087   uint64 _xxx_ = _rdtsc();\
    00088   static uint64 __sum__ = 0;\
    00089   static uint32 __i__ = 0;
    00090
    00091 #define TOC(str, count)\
    00092   __sum__ += _rdtsc() - _xxx_;\
    00093   if (++__i__ == count) {\
    00094     DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
    00095     __i__ = 0;\
    00096     __sum__ = 0;\
    00097   }\
    00098 }
    00099
    00100 void ShowInfo(const char *str);
    00101 void CDECL ShowInfoF(const char *str, ...);
    00102
    00103 #ifdef DEBUG_DUMP_COMMANDS
    00104   void CDECL DebugDumpCommands(const char *s, ...);
    00105 #else /* DEBUG_DUMP_COMMANDS */
    00106   static inline void DebugDumpCommands(const char *s, ...) {}
    00107 #endif /* DEBUG_DUMP_COMMANDS */
    00108
    00109 #endif /* DEBUG_H */