Maintain a circular buffer of recent commands, add to crashlog.
[openttd-joker.git] / src / debug.h
blobd3b2fbdd65516b6b4330c3a0a2e7f514e45a96ee
1 /* $Id: debug.h 26195 2014-01-02 08:45:28Z rubidium $ */
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"
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 */
34 /**
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 #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 char *DumpDebugFacilityNames(char *buf, char *last);
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 */