37#define Debug(facility, severity, format_string, ...) do { if ((severity) == Severity::Critical || IsVisibleSeverity((facility), (severity))) DebugPrint(facility, severity, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)
41using SetDebugStringErrorFunc = void(std::string_view);
42void SetDebugString(std::string_view s, SetDebugStringErrorFunc error_func);
59 const std::string_view name;
60 const std::optional<uint32_t> max_count;
62 uint64_t chrono_sum = 0;
64 using States = std::vector<State *>;
66 State(std::string_view name, std::optional<uint32_t> max_count = {}) : name(name), max_count(max_count)
68 GetStates().push_back(
this);
75 if (!GetStates().empty()) std::erase(GetStates(),
this);
78 static States &GetStates()
80 thread_local static States s_states;
84 void OutputAndReset(
const std::string_view prefix =
"")
86 Debug(
Facility::Misc,
Severity::Critical,
"[{}] [{}] {} calls in {} us [avg: {:.1f} us]", prefix, this->name, this->count, this->chrono_sum, this->chrono_sum /
static_cast<double>(this->count));
95 inline TicToc(
State &state) : state(state),
chrono_start(std::chrono::high_resolution_clock::now()) { }
100 this->state.chrono_sum += (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - this->chrono_start)).count();
102 if (this->state.max_count.has_value() && this->state.count == this->state.max_count.value()) {
103 this->state.OutputAndReset(
"MaxCount");
107 static void Tick(
const std::string_view prefix)
109 for (
auto state : State::GetStates()) {
110 if (state->max_count.has_value() || state->count == 0)
continue;
111 state->OutputAndReset(prefix);
116void ShowInfoI(std::string_view str);
117#define ShowInfo(format_string, ...) ShowInfoI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
Functions related to CPU specific instructions.
EnumIndexArray< Severity, Facility, Facility::End > _debug_level
Severity level for each debug facility.
void SetDebugString(std::string_view s, SetDebugStringErrorFunc error_func)
Set debugging levels by parsing the text in s.
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
bool IsVisibleSeverity(Facility facility, Severity severity)
Test if debug severity is visible for the given facility.
std::string GetLogPrefix(bool force=false)
Get the prefix for logs.
void DumpDebugFacilityNames(std::back_insert_iterator< std::string > &output_iterator)
Dump the available debug facility names in the help text.
std::string GetDebugString()
Print out the current debug-level.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
void DebugSendRemoteMessages()
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop threa...
void DebugPrint(Facility facility, Severity severity, std::string &&message)
Internal function for outputting the debug line.
Types related to debugging.
Facility
Debug facilities.
@ Misc
Misc message facility.
Severity
Debug message severity levels.
@ Critical
Critical, user should know about this.
Type (helpers) for enums.
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
Persistent state for TicToc profiling.
~State()
Remove ourselves from the thread local states.
std::chrono::high_resolution_clock::time_point chrono_start
real time count.
~TicToc()
Update the state with the time since the constructor call.