2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/** @file debug.h */
|
|
|
|
|
2005-02-05 15:58:59 +00:00
|
|
|
#ifndef DEBUG_H
|
|
|
|
#define DEBUG_H
|
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
/* Debugging messages policy:
|
|
|
|
* These should be the severities used for direct DEBUG() calls
|
|
|
|
* maximum debugging level should be 10 if really deep, deep
|
|
|
|
* debugging is needed.
|
|
|
|
* (there is room for exceptions, but you have to have a good cause):
|
|
|
|
* 0 - errors or severe warnings
|
|
|
|
* 1 - other non-fatal, non-severe warnings
|
|
|
|
* 2 - crude progress indicator of functionality
|
|
|
|
* 3 - important debugging messages (function entry)
|
|
|
|
* 4 - debugging messages (crude loop status, etc.)
|
|
|
|
* 5 - detailed debugging information
|
|
|
|
* 6.. - extremely detailed spamming
|
|
|
|
*/
|
|
|
|
|
2005-02-05 15:58:59 +00:00
|
|
|
#ifdef NO_DEBUG_MESSAGES
|
2008-01-24 18:47:05 +00:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
2006-12-28 19:38:09 +00:00
|
|
|
#define DEBUG(name, level, args...)
|
|
|
|
#else
|
|
|
|
#define DEBUG(name, level, ...)
|
|
|
|
#endif
|
|
|
|
#else /* NO_DEBUG_MESSAGES */
|
2008-01-24 18:47:05 +00:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ < 3)
|
2006-12-27 14:51:55 +00:00
|
|
|
#define DEBUG(name, level, args...) if ((level == 0) || ( _debug_ ## name ## _level >= level)) debug(#name, args)
|
|
|
|
#else
|
|
|
|
#define DEBUG(name, level, ...) if (level == 0 || _debug_ ## name ## _level >= level) debug(#name, __VA_ARGS__)
|
|
|
|
#endif
|
2005-02-05 15:58:59 +00:00
|
|
|
|
|
|
|
extern int _debug_ai_level;
|
2005-07-27 19:57:12 +00:00
|
|
|
extern int _debug_driver_level;
|
2005-02-05 15:58:59 +00:00
|
|
|
extern int _debug_grf_level;
|
|
|
|
extern int _debug_map_level;
|
|
|
|
extern int _debug_misc_level;
|
|
|
|
extern int _debug_ms_level;
|
|
|
|
extern int _debug_net_level;
|
2006-12-26 17:36:18 +00:00
|
|
|
extern int _debug_sprite_level;
|
2005-02-06 18:28:35 +00:00
|
|
|
extern int _debug_oldloader_level;
|
2005-07-19 11:42:40 +00:00
|
|
|
extern int _debug_ntp_level;
|
2005-04-11 19:53:44 +00:00
|
|
|
extern int _debug_npf_level;
|
2006-05-27 16:12:16 +00:00
|
|
|
extern int _debug_yapf_level;
|
2006-11-16 22:05:33 +00:00
|
|
|
extern int _debug_freetype_level;
|
2006-12-26 17:36:18 +00:00
|
|
|
extern int _debug_sl_level;
|
2007-01-14 19:13:36 +00:00
|
|
|
extern int _debug_station_level;
|
2005-02-05 15:58:59 +00:00
|
|
|
|
2008-01-24 18:47:05 +00:00
|
|
|
void CDECL debug(const char *dbg, ...);
|
2006-12-28 19:38:09 +00:00
|
|
|
#endif /* NO_DEBUG_MESSAGES */
|
2005-02-05 15:58:59 +00:00
|
|
|
|
|
|
|
void SetDebugString(const char *s);
|
2007-03-07 11:47:46 +00:00
|
|
|
const char *GetDebugString();
|
2005-02-05 15:58:59 +00:00
|
|
|
|
2006-05-15 22:32:27 +00:00
|
|
|
/* MSVCRT of course has to have a different syntax for long long *sigh* */
|
|
|
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
2006-12-28 19:38:09 +00:00
|
|
|
#define OTTD_PRINTF64 "I64"
|
2006-03-26 21:15:09 +00:00
|
|
|
#else
|
2006-12-28 19:38:09 +00:00
|
|
|
#define OTTD_PRINTF64 "ll"
|
2006-03-26 21:15:09 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-08 18:23:26 +00:00
|
|
|
/* Used for profiling
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* TIC();
|
|
|
|
* --Do your code--
|
|
|
|
* TOC("A name", 1);
|
|
|
|
*
|
|
|
|
* When you run the TIC() / TOC() multiple times, you can increase the '1'
|
|
|
|
* to only display average stats every N values. Some things to know:
|
|
|
|
*
|
|
|
|
* for (int i = 0; i < 5; i++) {
|
|
|
|
* TIC();
|
|
|
|
* --Do yuor code--
|
|
|
|
* TOC("A name", 5);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Is the correct usage for multiple TIC() / TOC() calls.
|
|
|
|
*
|
|
|
|
* TIC() / TOC() creates it's own block, so make sure not the mangle
|
|
|
|
* it with an other block.
|
|
|
|
**/
|
2006-03-26 21:15:09 +00:00
|
|
|
#define TIC() {\
|
2007-03-07 11:47:46 +00:00
|
|
|
extern uint64 _rdtsc();\
|
2006-03-26 21:15:09 +00:00
|
|
|
uint64 _xxx_ = _rdtsc();\
|
|
|
|
static uint64 __sum__ = 0;\
|
|
|
|
static uint32 __i__ = 0;
|
|
|
|
|
|
|
|
#define TOC(str, count)\
|
|
|
|
__sum__ += _rdtsc() - _xxx_;\
|
|
|
|
if (++__i__ == count) {\
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\
|
2006-03-26 21:15:09 +00:00
|
|
|
__i__ = 0;\
|
|
|
|
__sum__ = 0;\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
2007-12-25 11:26:07 +00:00
|
|
|
void ShowInfo(const char *str);
|
|
|
|
void CDECL ShowInfoF(const char *str, ...);
|
|
|
|
|
2008-01-11 00:30:32 +00:00
|
|
|
#ifdef DEBUG_DUMP_COMMANDS
|
|
|
|
void CDECL DebugDumpCommands(const char *s, ...);
|
|
|
|
#else /* DEBUG_DUMP_COMMANDS */
|
|
|
|
static inline void DebugDumpCommands(const char *s, ...) {}
|
|
|
|
#endif /* DEBUG_DUMP_COMMANDS */
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* DEBUG_H */
|