mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Debug: Move TicToc struct to separate header
This commit is contained in:
parent
e2fbd8aa0e
commit
612551a228
@ -128,6 +128,7 @@ add_files(
|
||||
debug.h
|
||||
debug_desync.h
|
||||
debug_settings.h
|
||||
debug_tictoc.h
|
||||
dedicated.cpp
|
||||
departures.cpp
|
||||
departures_func.h
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "32bpp_anim.hpp"
|
||||
#include "32bpp_sse2.hpp"
|
||||
#include "../cpu.h"
|
||||
|
||||
/** A partially 32 bpp blitter with palette animation. */
|
||||
class Blitter_32bppSSE2_Anim : public Blitter_32bppAnim {
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "32bpp_anim.hpp"
|
||||
#include "32bpp_anim_sse2.hpp"
|
||||
#include "32bpp_sse4.hpp"
|
||||
#include "../cpu.h"
|
||||
|
||||
#undef MARGIN_NORMAL_THRESHOLD
|
||||
#define MARGIN_NORMAL_THRESHOLD 4
|
||||
|
@ -25,6 +25,7 @@
|
||||
#endif
|
||||
|
||||
#include "32bpp_sse_type.h"
|
||||
#include "../cpu.h"
|
||||
|
||||
/** Base methods for 32bpp SSE blitters. */
|
||||
class Blitter_32bppSSE_Base {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#endif
|
||||
|
||||
#include "32bpp_ssse3.hpp"
|
||||
#include "../cpu.h"
|
||||
|
||||
/** The SSE4 32 bpp blitter (without palette animation). */
|
||||
class Blitter_32bppSSE4 : public Blitter_32bppSSSE3 {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#endif
|
||||
|
||||
#include "32bpp_sse2.hpp"
|
||||
#include "../cpu.h"
|
||||
|
||||
/** The SSSE3 32 bpp blitter (without palette animation). */
|
||||
class Blitter_32bppSSSE3 : public Blitter_32bppSSE2 {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../debug.h"
|
||||
#include <atomic>
|
||||
#include <bit>
|
||||
#include <chrono>
|
||||
|
||||
#ifdef RANDOM_DEBUG
|
||||
#include "../network/network.h"
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "console_func.h"
|
||||
#include "debug.h"
|
||||
#include "debug_fmt.h"
|
||||
#include "debug_tictoc.h"
|
||||
#include "string_func.h"
|
||||
#include "fileio_func.h"
|
||||
#include "settings_type.h"
|
||||
|
36
src/debug.h
36
src/debug.h
@ -10,8 +10,6 @@
|
||||
#ifndef DEBUG_H
|
||||
#define DEBUG_H
|
||||
|
||||
#include "cpu.h"
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
/* Debugging messages policy:
|
||||
@ -73,40 +71,6 @@ std::string GetDebugString();
|
||||
/* Shorter form for passing filename and linenumber */
|
||||
#define FILE_LINE __FILE__, __LINE__
|
||||
|
||||
/** TicToc profiling.
|
||||
* Usage:
|
||||
* static TicToc::State state("A name", 1);
|
||||
* TicToc tt(state);
|
||||
* --Do your code--
|
||||
*/
|
||||
struct TicToc {
|
||||
/** Persistent state for TicToc profiling. */
|
||||
struct State {
|
||||
const std::string_view name;
|
||||
const uint32_t max_count;
|
||||
uint32_t count = 0;
|
||||
uint64_t chrono_sum = 0;
|
||||
|
||||
constexpr State(std::string_view name, uint32_t max_count) : name(name), max_count(max_count) { }
|
||||
};
|
||||
|
||||
State &state;
|
||||
std::chrono::high_resolution_clock::time_point chrono_start; ///< real time count.
|
||||
|
||||
inline TicToc(State &state) : state(state), chrono_start(std::chrono::high_resolution_clock::now()) { }
|
||||
|
||||
inline ~TicToc()
|
||||
{
|
||||
this->state.chrono_sum += (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - this->chrono_start)).count();
|
||||
if (++this->state.count == this->state.max_count) {
|
||||
this->PrintAndReset();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void PrintAndReset();
|
||||
};
|
||||
|
||||
void ShowInfoI(const char *str);
|
||||
void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
|
||||
|
||||
|
51
src/debug_tictoc.h
Normal file
51
src/debug_tictoc.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/** @file debug.h TicToc functionality for debugging. */
|
||||
|
||||
#ifndef DEBUG_TICTOC_H
|
||||
#define DEBUG_TICTOC_H
|
||||
|
||||
#include "debug.h"
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
/** TicToc profiling.
|
||||
* Usage:
|
||||
* static TicToc::State state("A name", 1);
|
||||
* TicToc tt(state);
|
||||
* --Do your code--
|
||||
*/
|
||||
struct TicToc {
|
||||
/** Persistent state for TicToc profiling. */
|
||||
struct State {
|
||||
const std::string_view name;
|
||||
const uint32_t max_count;
|
||||
uint32_t count = 0;
|
||||
uint64_t chrono_sum = 0;
|
||||
|
||||
constexpr State(std::string_view name, uint32_t max_count) : name(name), max_count(max_count) { }
|
||||
};
|
||||
|
||||
State &state;
|
||||
std::chrono::high_resolution_clock::time_point chrono_start; ///< real time count.
|
||||
|
||||
inline TicToc(State &state) : state(state), chrono_start(std::chrono::high_resolution_clock::now()) { }
|
||||
|
||||
inline ~TicToc()
|
||||
{
|
||||
this->state.chrono_sum += (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - this->chrono_start)).count();
|
||||
if (++this->state.count == this->state.max_count) {
|
||||
this->PrintAndReset();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void PrintAndReset();
|
||||
};
|
||||
|
||||
#endif /* DEBUG_TICTOC_H */
|
Loading…
Reference in New Issue
Block a user