OpenTTD
debug.h
Go to the documentation of this file.
1 /* $Id$ */
2 
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  */
9 
12 #ifndef DEBUG_H
13 #define DEBUG_H
14 
15 #include "cpu.h"
16 
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
29  */
30 
36 #define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
37 
38 extern int _debug_driver_level;
39 extern int _debug_grf_level;
40 extern int _debug_map_level;
41 extern int _debug_misc_level;
42 extern int _debug_net_level;
43 extern int _debug_sprite_level;
44 extern int _debug_oldloader_level;
45 extern int _debug_npf_level;
46 extern int _debug_yapf_level;
47 extern int _debug_freetype_level;
48 extern int _debug_script_level;
49 extern int _debug_sl_level;
50 extern int _debug_gamelog_level;
51 extern int _debug_desync_level;
52 extern int _debug_console_level;
53 #ifdef RANDOM_DEBUG
54 extern int _debug_random_level;
55 #endif
56 
57 void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
58 
59 char *DumpDebugFacilityNames(char *buf, char *last);
60 void SetDebugString(const char *s);
61 const char *GetDebugString();
62 
63 /* Shorter form for passing filename and linenumber */
64 #define FILE_LINE __FILE__, __LINE__
65 
66 /* Used for profiling
67  *
68  * Usage:
69  * TIC();
70  * --Do your code--
71  * TOC("A name", 1);
72  *
73  * When you run the TIC() / TOC() multiple times, you can increase the '1'
74  * to only display average stats every N values. Some things to know:
75  *
76  * for (int i = 0; i < 5; i++) {
77  * TIC();
78  * --Do your code--
79  * TOC("A name", 5);
80  * }
81  *
82  * Is the correct usage for multiple TIC() / TOC() calls.
83  *
84  * TIC() / TOC() creates its own block, so make sure not the mangle
85  * it with another block.
86  **/
87 #define TIC() {\
88  uint64 _xxx_ = ottd_rdtsc();\
89  static uint64 __sum__ = 0;\
90  static uint32 __i__ = 0;
91 
92 #define TOC(str, count)\
93  __sum__ += ottd_rdtsc() - _xxx_;\
94  if (++__i__ == count) {\
95  DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
96  __i__ = 0;\
97  __sum__ = 0;\
98  }\
99 }
100 
101 void ShowInfo(const char *str);
102 void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
103 
104 const char *GetLogPrefix();
105 
107 extern uint32 _realtime_tick;
108 
109 #endif /* DEBUG_H */
void CDECL const char * GetLogPrefix()
Get the prefix for logs; if show_date_in_logs is enabled it returns the date, otherwise it returns no...
Definition: debug.cpp:257
void CDECL debug(const char *dbg, const char *format,...)
Output a debug line.
Definition: debug.cpp:162
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Definition: openttd.cpp:134
const char * GetDebugString()
Print out the current debug-level.
Definition: debug.cpp:234
Functions related to CPU specific instructions.
void SetDebugString(const char *s)
Set debugging levels by parsing the text in s.
Definition: debug.cpp:180
void CDECL char * DumpDebugFacilityNames(char *buf, char *last)
Dump the available debug facility names in the help text.
Definition: debug.cpp:88
uint32 _realtime_tick
The real time in the game.
Definition: debug.cpp:52