OpenTTD Source: src/debug.h File Reference

OpenTTD Source 1.11.0-RC1

Macros | Functions | Variables
debug.h File Reference
`#include "cpu.h"`
`#include <chrono>`

Go to the source code of this file.

## Macros
#define | DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
| Output a line of debugging information. More...
#define | FILE_LINE __FILE__, __LINE__
#define | TIC()
#define | TOC(str, count)
#define | TICC()
#define | TOCC(str, _count_)

## Functions
void CDECL | debug (const char *dbg, const char *format,...) WARN_FORMAT(2
void CDECL char * | DumpDebugFacilityNames (char *buf, char *last)
| Dump the available debug facility names in the help text. More...
void | SetDebugString (const char *s)
| Set debugging levels by parsing the text in s. More...
const char * | GetDebugString ()
| Print out the current debug-level. More...
void | ShowInfo (const char *str)
void CDECL | ShowInfoF (const char *str,...) WARN_FORMAT(1
void CDECL const char * | GetLogPrefix ()
| Get the prefix for logs; if show_date_in_logs is enabled it returns the date, otherwise it returns nothing. More...

## Variables
int | _debug_driver_level
int | _debug_grf_level
int | _debug_map_level
int | _debug_misc_level
int | _debug_net_level
int | _debug_sprite_level
int | _debug_oldloader_level
int | _debug_npf_level
int | _debug_yapf_level
int | _debug_freetype_level
int | _debug_script_level
int | _debug_sl_level
int | _debug_gamelog_level
int | _debug_desync_level
int | _debug_console_level

## Detailed Description

Functions related to debugging.

Definition in file debug.h.

## Macro Definition Documentation

## ◆ DEBUG

#define DEBUG | ( |  | name,
|  |  | level,
|  |  | ...
| ) |  | if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)

Output a line of debugging information.

Parameters

  name | Category
  level | Debugging level, higher levels means more detailed information.

Definition at line 35 of file debug.h.

## ◆ TIC

#define TIC | ( |  | ) |

Value:
{\
uint64 _xxx_ = ottd_rdtsc();\
static uint64 _sum_ = 0;\
static uint32 _i_ = 0;

Definition at line 89 of file debug.h.

## ◆ TICC

#define TICC | ( |  | ) |

Value:
{\
auto _start_ = std::chrono::high_resolution_clock::now();\
static uint64 _sum_ = 0;\
static uint32 _i_ = 0;

Definition at line 104 of file debug.h.

## ◆ TOC

#define TOC | ( |  | str,
|  |  | count
| ) |  |

Value:
_sum_ += ottd_rdtsc() - _xxx_;\
if (++_i_ == count) {\
DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, _sum_, _sum_/(double)_i_);\
_i_ = 0;\
_sum_ = 0;\
}\
}

Definition at line 94 of file debug.h.

## ◆ TOCC

#define TOCC | ( |  | str,
|  |  | _count_
| ) |  |

Value:
_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;\
}\
}

Definition at line 109 of file debug.h.

## Function Documentation

## ◆ DumpDebugFacilityNames()

void CDECL char* DumpDebugFacilityNames | ( | char * | buf,
|  | char * | last
| ) |  |

Dump the available debug facility names in the help text.

Parameters

  buf | Start address for storing the output.
  last | Last valid address for storing the output.

Returns
  Next free position in the output.

Definition at line 82 of file debug.cpp.

## ◆ GetDebugString()

const char* GetDebugString | ( |  | ) |

Print out the current debug-level.

Just return a string with the values of all the debug categories.

Returns
  string with debug-levels

Definition at line 224 of file debug.cpp.

## ◆ GetLogPrefix()

void CDECL const char* GetLogPrefix | ( |  | ) |

Get the prefix for logs; if show_date_in_logs is enabled it returns the date, otherwise it returns nothing.

Returns
  the prefix for logs (do not free), never nullptr

Definition at line 247 of file debug.cpp.

References _settings_client, ClientSettings::gui, and GUISettings::show_date_in_logs.

## ◆ SetDebugString()

void SetDebugString | ( | const char * | s | ) |

Set debugging levels by parsing the text in s.

For setting individual levels a string like `"net=3,grf=6"` should be used. If the string starts with a number, the number is used as global debugging level.

Parameters

  s | Text describing the wanted debugging levels.

Definition at line 170 of file debug.cpp.

ottd_rdtsc
uint64 ottd_rdtsc()
Get the tick counter from the CPU (high precision timing).
Definition: cpu.cpp:86