1 /* $Id: debug.h 26195 2014-01-02 08:45:28Z rubidium $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file debug.h Functions related to debugging. */
17 /* Debugging messages policy:
18 * These should be the severities used for direct DEBUG() calls
19 * maximum debugging level should be 10 if really deep, deep
20 * debugging is needed.
21 * (there is room for exceptions, but you have to have a good cause):
22 * 0 - errors or severe warnings
23 * 1 - other non-fatal, non-severe warnings
24 * 2 - crude progress indicator of functionality
25 * 3 - important debugging messages (function entry)
26 * 4 - debugging messages (crude loop status, etc.)
27 * 5 - detailed debugging information
28 * 6.. - extremely detailed spamming
31 #ifdef NO_DEBUG_MESSAGES
32 #define DEBUG(name, level, ...) { }
33 #else /* NO_DEBUG_MESSAGES */
35 * Output a line of debugging information.
36 * @param name Category
37 * @param level Debugging level, higher levels means more detailed information.
39 #define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
41 extern int _debug_driver_level
;
42 extern int _debug_grf_level
;
43 extern int _debug_map_level
;
44 extern int _debug_misc_level
;
45 extern int _debug_net_level
;
46 extern int _debug_sprite_level
;
47 extern int _debug_oldloader_level
;
48 extern int _debug_npf_level
;
49 extern int _debug_yapf_level
;
50 extern int _debug_freetype_level
;
51 extern int _debug_script_level
;
52 extern int _debug_sl_level
;
53 extern int _debug_gamelog_level
;
54 extern int _debug_desync_level
;
55 extern int _debug_console_level
;
56 extern int _debug_sound_level
;
58 extern int _debug_random_level
;
61 void CDECL
debug(const char *dbg
, const char *format
, ...) WARN_FORMAT(2, 3);
62 #endif /* NO_DEBUG_MESSAGES */
64 char *DumpDebugFacilityNames(char *buf
, char *last
);
65 void SetDebugString(const char *s
);
66 const char *GetDebugString();
68 /* Shorter form for passing filename and linenumber */
69 #define FILE_LINE __FILE__, __LINE__
78 * When you run the TIC() / TOC() multiple times, you can increase the '1'
79 * to only display average stats every N values. Some things to know:
81 * for (int i = 0; i < 5; i++) {
87 * Is the correct usage for multiple TIC() / TOC() calls.
89 * TIC() / TOC() creates its own block, so make sure not the mangle
90 * it with another block.
93 uint64 _xxx_ = ottd_rdtsc();\
94 static uint64 __sum__ = 0;\
95 static uint32 __i__ = 0;
97 #define TOC(str, count)\
98 __sum__ += ottd_rdtsc() - _xxx_;\
99 if (++__i__ == count) {\
100 DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
106 void ShowInfo(const char *str
);
107 void CDECL
ShowInfoF(const char *str
, ...) WARN_FORMAT(1, 2);
109 const char *GetLogPrefix();
111 /** The real time in the game. */
112 extern uint32 _realtime_tick
;