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
|
|
|
|
|
2014-01-02 08:45:28 +00:00
|
|
|
#include "cpu.h"
|
2019-02-28 11:18:06 +00:00
|
|
|
#include <chrono>
|
2019-05-21 00:49:40 +00:00
|
|
|
#include <string>
|
2014-01-02 08:45:28 +00:00
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2018-04-11 20:07:21 +00:00
|
|
|
/**
|
|
|
|
* Output a line of debugging information.
|
|
|
|
* @param name Category
|
|
|
|
* @param level Debugging level, higher levels means more detailed information.
|
|
|
|
*/
|
|
|
|
#define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
|
2005-02-05 15:58:59 +00:00
|
|
|
|
2018-04-11 20:07:21 +00:00
|
|
|
extern int _debug_driver_level;
|
|
|
|
extern int _debug_grf_level;
|
|
|
|
extern int _debug_map_level;
|
|
|
|
extern int _debug_misc_level;
|
|
|
|
extern int _debug_net_level;
|
|
|
|
extern int _debug_sprite_level;
|
|
|
|
extern int _debug_oldloader_level;
|
|
|
|
extern int _debug_npf_level;
|
|
|
|
extern int _debug_yapf_level;
|
2022-09-15 17:21:27 +00:00
|
|
|
extern int _debug_fontcache_level;
|
2018-04-11 20:07:21 +00:00
|
|
|
extern int _debug_script_level;
|
|
|
|
extern int _debug_sl_level;
|
|
|
|
extern int _debug_gamelog_level;
|
|
|
|
extern int _debug_desync_level;
|
2018-04-27 01:42:20 +00:00
|
|
|
extern int _debug_yapfdesync_level;
|
2018-04-11 20:07:21 +00:00
|
|
|
extern int _debug_console_level;
|
2018-04-27 01:42:20 +00:00
|
|
|
extern int _debug_linkgraph_level;
|
|
|
|
extern int _debug_sound_level;
|
2012-01-26 17:24:56 +00:00
|
|
|
#ifdef RANDOM_DEBUG
|
2018-04-11 20:07:21 +00:00
|
|
|
extern int _debug_random_level;
|
2021-01-18 00:58:43 +00:00
|
|
|
extern int _debug_statecsum_level;
|
2012-01-26 17:24:56 +00:00
|
|
|
#endif
|
2005-02-05 15:58:59 +00:00
|
|
|
|
2019-05-21 00:49:40 +00:00
|
|
|
extern const char *_savegame_DBGL_data;
|
|
|
|
extern std::string _loadgame_DBGL_data;
|
2020-04-21 17:17:13 +00:00
|
|
|
extern bool _save_DBGC_data;
|
|
|
|
extern std::string _loadgame_DBGC_data;
|
2019-05-21 00:49:40 +00:00
|
|
|
|
2018-04-11 20:07:21 +00:00
|
|
|
void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
|
2023-03-03 23:59:49 +00:00
|
|
|
void debug_print(const char *dbg, const char *buf);
|
2005-02-05 15:58:59 +00:00
|
|
|
|
2012-04-07 20:55:55 +00:00
|
|
|
char *DumpDebugFacilityNames(char *buf, char *last);
|
2022-08-26 10:08:47 +00:00
|
|
|
void SetDebugString(const char *s, void (*error_func)(const char *));
|
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__
|
|
|
|
|
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.
|
2019-02-28 11:18:06 +00:00
|
|
|
*
|
2019-09-29 20:27:32 +00:00
|
|
|
* The output is counted in CPU cycles, and not comparable across
|
2019-02-28 11:18:06 +00:00
|
|
|
* machines. Mainly useful for local optimisations.
|
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();\
|
2019-03-02 09:50:50 +00:00
|
|
|
static uint64 _sum_ = 0;\
|
|
|
|
static uint32 _i_ = 0;
|
2006-03-26 21:15:09 +00:00
|
|
|
|
|
|
|
#define TOC(str, count)\
|
2019-03-02 09:50:50 +00:00
|
|
|
_sum_ += ottd_rdtsc() - _xxx_;\
|
|
|
|
if (++_i_ == count) {\
|
|
|
|
DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, _sum_, _sum_/(double)_i_);\
|
|
|
|
_i_ = 0;\
|
|
|
|
_sum_ = 0;\
|
2006-03-26 21:15:09 +00:00
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
2019-02-28 11:18:06 +00:00
|
|
|
/* Chrono based version. The output is in microseconds. */
|
|
|
|
#define TICC() {\
|
|
|
|
auto _start_ = std::chrono::high_resolution_clock::now();\
|
|
|
|
static uint64 _sum_ = 0;\
|
|
|
|
static uint32 _i_ = 0;
|
|
|
|
|
|
|
|
#define TOCC(str, _count_)\
|
|
|
|
_sum_ += (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - _start_)).count();\
|
|
|
|
if (++_i_ == _count_) {\
|
|
|
|
DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " us [avg: %.1f us]", str, _sum_, _sum_/(double)_i_);\
|
|
|
|
_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();
|
|
|
|
|
2019-05-22 18:57:16 +00:00
|
|
|
void ClearDesyncMsgLog();
|
|
|
|
void LogDesyncMsg(std::string msg);
|
|
|
|
char *DumpDesyncMsgLog(char *buffer, const char *last);
|
|
|
|
|
2021-07-23 20:36:17 +00:00
|
|
|
void DebugSendRemoteMessages();
|
|
|
|
void DebugReconsiderSendRemoteMessages();
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* DEBUG_H */
|