# debug.h

Go to the documentation of this file.

    00001 /* $Id: debug.h 16273 2009-05-10 21:33:55Z 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, const char *format, ...) WARN_FORMAT(2, 3);
    00054 #endif /* NO_DEBUG_MESSAGES */
    00055
    00056 void SetDebugString(const char *s);
    00057 const char *GetDebugString();
    00058
    00059 /* Used for profiling
    00060  *
    00061  * Usage:
    00062  * TIC();
    00063  *   --Do your code--
    00064  * TOC("A name", 1);
    00065  *
    00066  * When you run the TIC() / TOC() multiple times, you can increase the '1'
    00067  *  to only display average stats every N values. Some things to know:
    00068  *
    00069  * for (int i = 0; i < 5; i++) {
    00070  *   TIC();
    00071  *     --Do yuor code--
    00072  *   TOC("A name", 5);
    00073  * }
    00074  *
    00075  * Is the correct usage for multiple TIC() / TOC() calls.
    00076  *
    00077  * TIC() / TOC() creates it's own block, so make sure not the mangle
    00078  *  it with an other block.
    00079  **/
    00080 #define TIC() {\
    00081   extern uint64 ottd_rdtsc();\
    00082   uint64 _xxx_ = ottd_rdtsc();\
    00083   static uint64 __sum__ = 0;\
    00084   static uint32 __i__ = 0;
    00085
    00086 #define TOC(str, count)\
    00087   __sum__ += ottd_rdtsc() - _xxx_;\
    00088   if (++__i__ == count) {\
    00089     DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
    00090     __i__ = 0;\
    00091     __sum__ = 0;\
    00092   }\
    00093 }
    00094
    00095 void ShowInfo(const char *str);
    00096 void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
    00097
    00098 #endif /* DEBUG_H */