Translations update
[openttd/fttd.git] / src / debug.h
blob0da67a06ac9c92188d4f7e5157f92d88e3b73781
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file debug.h Functions related to debugging. */
12 #ifndef DEBUG_H
13 #define DEBUG_H
15 #include "cpu.h"
16 #include "string.h"
18 /* Debugging messages policy:
19 * These should be the severities used for direct DEBUG() calls
20 * maximum debugging level should be 10 if really deep, deep
21 * debugging is needed.
22 * (there is room for exceptions, but you have to have a good cause):
23 * 0 - errors or severe warnings
24 * 1 - other non-fatal, non-severe warnings
25 * 2 - crude progress indicator of functionality
26 * 3 - important debugging messages (function entry)
27 * 4 - debugging messages (crude loop status, etc.)
28 * 5 - detailed debugging information
29 * 6.. - extremely detailed spamming
32 #ifdef NO_DEBUG_MESSAGES
33 #define DEBUG(name, level, ...) { }
34 #else /* NO_DEBUG_MESSAGES */
35 /**
36 * Output a line of debugging information.
37 * @param name Category
38 * @param level Debugging level, higher levels means more detailed information.
40 #define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
42 extern int _debug_driver_level;
43 extern int _debug_grf_level;
44 extern int _debug_map_level;
45 extern int _debug_misc_level;
46 extern int _debug_net_level;
47 extern int _debug_sprite_level;
48 extern int _debug_oldloader_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 #ifdef RANDOM_DEBUG
57 extern int _debug_random_level;
58 #endif
60 void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
61 #endif /* NO_DEBUG_MESSAGES */
63 void DumpDebugFacilityNames (stringb *buf);
64 void SetDebugString(const char *s);
65 const char *GetDebugString();
67 /* Shorter form for passing filename and linenumber */
68 #define FILE_LINE __FILE__, __LINE__
70 /* Used for profiling
72 * Usage:
73 * TIC();
74 * --Do your code--
75 * TOC("A name", 1);
77 * When you run the TIC() / TOC() multiple times, you can increase the '1'
78 * to only display average stats every N values. Some things to know:
80 * for (int i = 0; i < 5; i++) {
81 * TIC();
82 * --Do your code--
83 * TOC("A name", 5);
84 * }
86 * Is the correct usage for multiple TIC() / TOC() calls.
88 * TIC() / TOC() creates its own block, so make sure not the mangle
89 * it with another block.
90 **/
91 #define TIC() {\
92 uint64 _xxx_ = ottd_rdtsc();\
93 static uint64 __sum__ = 0;\
94 static uint32 __i__ = 0;
96 #define TOC(str, count)\
97 __sum__ += ottd_rdtsc() - _xxx_;\
98 if (++__i__ == count) {\
99 DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
100 __i__ = 0;\
101 __sum__ = 0;\
105 void ShowInfo(const char *str);
106 void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
108 const char *GetLogPrefix();
110 /** The real time in the game. */
111 extern uint32 _realtime_tick;
113 #endif /* DEBUG_H */