2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file debug.h Functions related to debugging. */
|
2007-03-01 01:24:44 +00:00
|
|
|
|
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
|
2009-06-01 11:49:46 +00:00
|
|
|
#define DEBUG(name, level, ...) { }
|
2006-12-28 19:38:09 +00:00
|
|
|
#else /* NO_DEBUG_MESSAGES */
|
2009-06-01 11:49:46 +00:00
|
|
|
#define DEBUG(name, level, ...) if (level == 0 || _debug_ ## name ## _level >= level) debug(#name, __VA_ARGS__)
|
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;
|
2008-06-03 18:35:58 +00:00
|
|
|
extern int _debug_gamelog_level;
|
2008-12-29 21:50:25 +00:00
|
|
|
extern int _debug_desync_level;
|
2005-02-05 15:58:59 +00:00
|
|
|
|
2009-05-10 17:27:25 +00:00
|
|
|
void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
|
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
|
|
|
|
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() {\
|
2008-11-26 01:03:34 +00:00
|
|
|
extern uint64 ottd_rdtsc();\
|
|
|
|
uint64 _xxx_ = ottd_rdtsc();\
|
2006-03-26 21:15:09 +00:00
|
|
|
static uint64 __sum__ = 0;\
|
|
|
|
static uint32 __i__ = 0;
|
|
|
|
|
|
|
|
#define TOC(str, count)\
|
2008-11-26 01:03:34 +00:00
|
|
|
__sum__ += ottd_rdtsc() - _xxx_;\
|
2006-03-26 21:15:09 +00:00
|
|
|
if (++__i__ == count) {\
|
2009-06-25 00:06:06 +00:00
|
|
|
DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [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);
|
2009-05-10 17:27:25 +00:00
|
|
|
void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
|
2007-12-25 11:26:07 +00:00
|
|
|
|
2009-09-09 15:11:46 +00:00
|
|
|
const char *GetLogPrefix();
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* DEBUG_H */
|