2009-08-21 22:21:05 +02: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 17:11:33 +02:00
|
|
|
/** @file debug.h Functions related to debugging. */
|
2007-03-01 02:24:44 +01:00
|
|
|
|
2005-02-05 16:58:59 +01:00
|
|
|
#ifndef DEBUG_H
|
|
|
|
#define DEBUG_H
|
|
|
|
|
2014-01-02 09:45:28 +01:00
|
|
|
#include "cpu.h"
|
2019-02-28 12:18:06 +01:00
|
|
|
#include <chrono>
|
2021-06-11 21:17:07 +02:00
|
|
|
#include "3rdparty/fmt/format.h"
|
2014-01-02 09:45:28 +01:00
|
|
|
|
2006-12-26 18:36:18 +01:00
|
|
|
/* Debugging messages policy:
|
2021-06-12 11:21:41 +02:00
|
|
|
* These should be the severities used for direct Debug() calls
|
2006-12-26 18:36:18 +01:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-06-11 21:17:07 +02:00
|
|
|
/**
|
|
|
|
* Ouptut a line of debugging information.
|
|
|
|
* @param name The category of debug information.
|
|
|
|
* @param level The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown.
|
|
|
|
* @param format_string The formatting string of the message.
|
|
|
|
*/
|
2021-06-12 11:32:57 +02:00
|
|
|
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) DebugPrint(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
|
|
|
|
void DebugPrint(const char *level, const std::string &message);
|
2021-06-11 21:17:07 +02:00
|
|
|
|
2018-04-11 22:07:21 +02: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;
|
|
|
|
extern int _debug_freetype_level;
|
|
|
|
extern int _debug_script_level;
|
|
|
|
extern int _debug_sl_level;
|
|
|
|
extern int _debug_gamelog_level;
|
|
|
|
extern int _debug_desync_level;
|
|
|
|
extern int _debug_console_level;
|
2012-01-26 18:24:56 +01:00
|
|
|
#ifdef RANDOM_DEBUG
|
2018-04-11 22:07:21 +02:00
|
|
|
extern int _debug_random_level;
|
2012-01-26 18:24:56 +01:00
|
|
|
#endif
|
2005-02-05 16:58:59 +01:00
|
|
|
|
2012-04-07 22:55:55 +02:00
|
|
|
char *DumpDebugFacilityNames(char *buf, char *last);
|
2005-02-05 16:58:59 +01:00
|
|
|
void SetDebugString(const char *s);
|
2007-03-07 12:47:46 +01:00
|
|
|
const char *GetDebugString();
|
2005-02-05 16:58:59 +01:00
|
|
|
|
2010-06-05 14:16:12 +02:00
|
|
|
/* Shorter form for passing filename and linenumber */
|
|
|
|
#define FILE_LINE __FILE__, __LINE__
|
|
|
|
|
2007-06-08 20:23:26 +02: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 23:46:42 +01:00
|
|
|
* --Do your code--
|
2007-06-08 20:23:26 +02:00
|
|
|
* TOC("A name", 5);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* Is the correct usage for multiple TIC() / TOC() calls.
|
|
|
|
*
|
2010-04-12 16:12:47 +02:00
|
|
|
* TIC() / TOC() creates its own block, so make sure not the mangle
|
2010-01-01 19:45:40 +01:00
|
|
|
* it with another block.
|
2019-02-28 12:18:06 +01:00
|
|
|
*
|
2019-09-29 22:27:32 +02:00
|
|
|
* The output is counted in CPU cycles, and not comparable across
|
2019-02-28 12:18:06 +01:00
|
|
|
* machines. Mainly useful for local optimisations.
|
2007-06-08 20:23:26 +02:00
|
|
|
**/
|
2006-03-26 23:15:09 +02:00
|
|
|
#define TIC() {\
|
2008-11-26 02:03:34 +01:00
|
|
|
uint64 _xxx_ = ottd_rdtsc();\
|
2019-03-02 10:50:50 +01:00
|
|
|
static uint64 _sum_ = 0;\
|
|
|
|
static uint32 _i_ = 0;
|
2006-03-26 23:15:09 +02:00
|
|
|
|
|
|
|
#define TOC(str, count)\
|
2019-03-02 10:50:50 +01:00
|
|
|
_sum_ += ottd_rdtsc() - _xxx_;\
|
|
|
|
if (++_i_ == count) {\
|
2021-06-12 09:10:17 +02:00
|
|
|
Debug(misc, 0, "[{}] {} [avg: {:.1f}]", str, _sum_, _sum_/(double)_i_);\
|
2019-03-02 10:50:50 +01:00
|
|
|
_i_ = 0;\
|
|
|
|
_sum_ = 0;\
|
2006-03-26 23:15:09 +02:00
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
2019-02-28 12:18:06 +01: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_) {\
|
2021-06-12 09:10:17 +02:00
|
|
|
Debug(misc, 0, "[{}] {} us [avg: {:.1f} us]", str, _sum_, _sum_/(double)_i_);\
|
2019-02-28 12:18:06 +01:00
|
|
|
_i_ = 0;\
|
|
|
|
_sum_ = 0;\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-25 12:26:07 +01:00
|
|
|
void ShowInfo(const char *str);
|
2009-05-10 19:27:25 +02:00
|
|
|
void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
|
2007-12-25 12:26:07 +01:00
|
|
|
|
2009-09-09 17:11:46 +02:00
|
|
|
const char *GetLogPrefix();
|
|
|
|
|
2021-07-23 22:36:17 +02:00
|
|
|
void DebugSendRemoteMessages();
|
|
|
|
void DebugReconsiderSendRemoteMessages();
|
|
|
|
|
2005-09-18 22:56:44 +02:00
|
|
|
#endif /* DEBUG_H */
|