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 */
|
2010-09-11 11:48:37 +00:00
|
|
|
/**
|
|
|
|
* Output a line of debugging information.
|
|
|
|
* @param name Category
|
|
|
|
* @param level Debugging level, higher levels means more detailed information.
|
|
|
|
*/
|
2009-11-14 11:57:55 +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
|
|
|
|
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_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-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;
|
2011-12-01 12:04:10 +00:00
|
|
|
extern int _debug_script_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;
|
2010-02-10 16:10:05 +00:00
|
|
|
extern int _debug_console_level;
|
2012-01-26 17:24:56 +00:00
|
|
|
#ifdef RANDOM_DEBUG
|
|
|
|
extern int _debug_random_level;
|
|
|
|
#endif
|
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
|
|
|
|
2012-04-07 20:55:55 +00:00
|
|
|
char *DumpDebugFacilityNames(char *buf, char *last);
|
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
|
|
|
|
2010-06-05 12:16:12 +00:00
|
|
|
/* Shorter form for passing filename and linenumber */
|
|
|
|
#define FILE_LINE __FILE__, __LINE__
|
|
|
|
|
2011-05-02 16:14:23 +00:00
|
|
|
/**
|
|
|
|
* Get the tick counter from the CPU (high precision timing).
|
|
|
|
* @return The count.
|
|
|
|
*/
|
|
|
|
uint64 ottd_rdtsc();
|
|
|
|
|
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();
|
2013-01-08 22:46:42 +00:00
|
|
|
* --Do your code--
|
2007-06-08 18:23:26 +00:00
|
|
|
* TOC("A name", 5);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Is the correct usage for multiple TIC() / TOC() calls.
|
|
|
|
*
|
2010-04-12 14:12:47 +00:00
|
|
|
* TIC() / TOC() creates its own block, so make sure not the mangle
|
2010-01-01 18:45:40 +00:00
|
|
|
* it with another block.
|
2007-06-08 18:23:26 +00:00
|
|
|
**/
|
2006-03-26 21:15:09 +00:00
|
|
|
#define TIC() {\
|
2008-11-26 01:03:34 +00:00
|
|
|
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-10-15 20:15:12 +00:00
|
|
|
DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", 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();
|
|
|
|
|
2010-07-19 16:21:49 +00:00
|
|
|
/** The real time in the game. */
|
|
|
|
extern uint32 _realtime_tick;
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* DEBUG_H */
|