# debug.h

Go to the documentation of this file.

    00001 /* $Id: debug.h 26195 2014-01-02 08:45:28Z rubidium $ */
    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 #include "cpu.h"
    00016
    00017 /* Debugging messages policy:
    00018  * These should be the severities used for direct DEBUG() calls
    00019  * maximum debugging level should be 10 if really deep, deep
    00020  * debugging is needed.
    00021  * (there is room for exceptions, but you have to have a good cause):
    00022  * 0   - errors or severe warnings
    00023  * 1   - other non-fatal, non-severe warnings
    00024  * 2   - crude progress indicator of functionality
    00025  * 3   - important debugging messages (function entry)
    00026  * 4   - debugging messages (crude loop status, etc.)
    00027  * 5   - detailed debugging information
    00028  * 6.. - extremely detailed spamming
    00029  */
    00030
    00031 #ifdef NO_DEBUG_MESSAGES
    00032   #define DEBUG(name, level, ...) { }
    00033 #else /* NO_DEBUG_MESSAGES */
    00034
    00039   #define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
    00040
    00041   extern int _debug_driver_level;
    00042   extern int _debug_grf_level;
    00043   extern int _debug_map_level;
    00044   extern int _debug_misc_level;
    00045   extern int _debug_net_level;
    00046   extern int _debug_sprite_level;
    00047   extern int _debug_oldloader_level;
    00048   extern int _debug_npf_level;
    00049   extern int _debug_yapf_level;
    00050   extern int _debug_freetype_level;
    00051   extern int _debug_script_level;
    00052   extern int _debug_sl_level;
    00053   extern int _debug_gamelog_level;
    00054   extern int _debug_desync_level;
    00055   extern int _debug_console_level;
    00056 #ifdef RANDOM_DEBUG
    00057   extern int _debug_random_level;
    00058 #endif
    00059
    00060   void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
    00061 #endif /* NO_DEBUG_MESSAGES */
    00062
    00063 char *DumpDebugFacilityNames(char *buf, char *last);
    00064 void SetDebugString(const char *s);
    00065 const char *GetDebugString();
    00066
    00067 /* Shorter form for passing filename and linenumber */
    00068 #define FILE_LINE __FILE__, __LINE__
    00069
    00070 /* Used for profiling
    00071  *
    00072  * Usage:
    00073  * TIC();
    00074  *   --Do your code--
    00075  * TOC("A name", 1);
    00076  *
    00077  * When you run the TIC() / TOC() multiple times, you can increase the '1'
    00078  *  to only display average stats every N values. Some things to know:
    00079  *
    00080  * for (int i = 0; i < 5; i++) {
    00081  *   TIC();
    00082  *     --Do your code--
    00083  *   TOC("A name", 5);
    00084  * }
    00085  *
    00086  * Is the correct usage for multiple TIC() / TOC() calls.
    00087  *
    00088  * TIC() / TOC() creates its own block, so make sure not the mangle
    00089  *  it with another block.
    00090  **/
    00091 #define TIC() {\
    00092   uint64 _xxx_ = ottd_rdtsc();\
    00093   static uint64 __sum__ = 0;\
    00094   static uint32 __i__ = 0;
    00095
    00096 #define TOC(str, count)\
    00097   __sum__ += ottd_rdtsc() - _xxx_;\
    00098   if (++__i__ == count) {\
    00099     DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
    00100     __i__ = 0;\
    00101     __sum__ = 0;\
    00102   }\
    00103 }
    00104
    00105 void ShowInfo(const char *str);
    00106 void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
    00107
    00108 const char *GetLogPrefix();
    00109
    00111 extern uint32 _realtime_tick;
    00112
    00113 #endif /* DEBUG_H */