# debug.h

Go to the documentation of this file.

    00001 /* $Id: debug.h 19080 2010-02-10 16:12:54Z smatz $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef DEBUG_H
    00013 #define DEBUG_H
    00014
    00015 /* Debugging messages policy:
    00016  * These should be the severities used for direct DEBUG() calls
    00017  * maximum debugging level should be 10 if really deep, deep
    00018  * debugging is needed.
    00019  * (there is room for exceptions, but you have to have a good cause):
    00020  * 0   - errors or severe warnings
    00021  * 1   - other non-fatal, non-severe warnings
    00022  * 2   - crude progress indicator of functionality
    00023  * 3   - important debugging messages (function entry)
    00024  * 4   - debugging messages (crude loop status, etc.)
    00025  * 5   - detailed debugging information
    00026  * 6.. - extremely detailed spamming
    00027  */
    00028
    00029 #ifdef NO_DEBUG_MESSAGES
    00030   #define DEBUG(name, level, ...) { }
    00031 #else /* NO_DEBUG_MESSAGES */
    00032   #define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
    00033
    00034   extern int _debug_ai_level;
    00035   extern int _debug_driver_level;
    00036   extern int _debug_grf_level;
    00037   extern int _debug_map_level;
    00038   extern int _debug_misc_level;
    00039   extern int _debug_net_level;
    00040   extern int _debug_sprite_level;
    00041   extern int _debug_oldloader_level;
    00042   extern int _debug_npf_level;
    00043   extern int _debug_yapf_level;
    00044   extern int _debug_freetype_level;
    00045   extern int _debug_sl_level;
    00046   extern int _debug_gamelog_level;
    00047   extern int _debug_desync_level;
    00048   extern int _debug_console_level;
    00049
    00050   void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
    00051 #endif /* NO_DEBUG_MESSAGES */
    00052
    00053 void SetDebugString(const char *s);
    00054 const char *GetDebugString();
    00055
    00056 /* Used for profiling
    00057  *
    00058  * Usage:
    00059  * TIC();
    00060  *   --Do your code--
    00061  * TOC("A name", 1);
    00062  *
    00063  * When you run the TIC() / TOC() multiple times, you can increase the '1'
    00064  *  to only display average stats every N values. Some things to know:
    00065  *
    00066  * for (int i = 0; i < 5; i++) {
    00067  *   TIC();
    00068  *     --Do yuor code--
    00069  *   TOC("A name", 5);
    00070  * }
    00071  *
    00072  * Is the correct usage for multiple TIC() / TOC() calls.
    00073  *
    00074  * TIC() / TOC() creates it's own block, so make sure not the mangle
    00075  *  it with another block.
    00076  **/
    00077 #define TIC() {\
    00078   extern uint64 ottd_rdtsc();\
    00079   uint64 _xxx_ = ottd_rdtsc();\
    00080   static uint64 __sum__ = 0;\
    00081   static uint32 __i__ = 0;
    00082
    00083 #define TOC(str, count)\
    00084   __sum__ += ottd_rdtsc() - _xxx_;\
    00085   if (++__i__ == count) {\
    00086     DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
    00087     __i__ = 0;\
    00088     __sum__ = 0;\
    00089   }\
    00090 }
    00091
    00092 void ShowInfo(const char *str);
    00093 void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
    00094
    00095 const char *GetLogPrefix();
    00096
    00097 #endif /* DEBUG_H */