OpenTTD Source: src/newgrf_profiling.h Source File

OpenTTD Source 15.3

newgrf_profiling.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef NEWGRF_PROFILING_H
11#define NEWGRF_PROFILING_H
12
13#include "timer/timer_game_calendar.h"
14#include "newgrf.h"
15#include "newgrf_callbacks.h"
16#include "newgrf_spritegroup.h"
17
18
22 struct NewGRFProfiler {
23 NewGRFProfiler(const GRFFile *grffile);
24 ~NewGRFProfiler();
25
26 void BeginResolve(const ResolverObject &resolver);
27 void EndResolve(const ResolverResult &result);
28 void RecursiveResolve();
29
30 void Start();
31 uint32_t Finish();
32 void Abort();
33 std::string GetOutputFilename() const;
34
35 static void StartTimer(uint64_t ticks);
36 static void AbortTimer();
37 static uint32_t FinishAll();
38
40 struct Call {
41 uint32_t root_sprite;
42 uint32_t item;
43 uint32_t result;
44 uint32_t subs;
45 uint32_t time;
46 uint64_t tick;
47 CallbackID cb;
48 GrfSpecFeature feat;
49 };
50
51 const GRFFile *grffile = nullptr;
52 bool active = false;
53 uint64_t start_tick = 0;
54 Call cur_call{};
55 std::vector<Call> calls{};
56};
57
58extern std::vector<NewGRFProfiler> _newgrf_profilers;
59
60#endif /* NEWGRF_PROFILING_H */
newgrf.h
Base for the NewGRF implementation.
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
newgrf_spritegroup.h
Action 2 handling.
ResolverResult
std::variant< std::monostate, CallbackResult, const ResultSpriteGroup *, const TileLayoutSpriteGroup *, const IndustryProductionSpriteGroup * > ResolverResult
Result of resolving sprite groups:
Definition newgrf_spritegroup.h:37
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
NewGRFProfiler::Call
Measurement of a single sprite group resolution.
Definition newgrf_profiling.h:40
NewGRFProfiler::Call::feat
GrfSpecFeature feat
GRF feature being resolved for.
Definition newgrf_profiling.h:48
NewGRFProfiler::Call::time
uint32_t time
Time taken for resolution (microseconds)
Definition newgrf_profiling.h:45
NewGRFProfiler::Call::subs
uint32_t subs
Sub-calls to other sprite groups.
Definition newgrf_profiling.h:44
NewGRFProfiler::Call::tick
uint64_t tick
Game tick.
Definition newgrf_profiling.h:46
NewGRFProfiler::Call::root_sprite
uint32_t root_sprite
Pseudo-sprite index in GRF file.
Definition newgrf_profiling.h:41
NewGRFProfiler::Call::cb
CallbackID cb
Callback ID.
Definition newgrf_profiling.h:47
NewGRFProfiler::Call::item
uint32_t item
Local ID of item being resolved for.
Definition newgrf_profiling.h:42
NewGRFProfiler::Call::result
uint32_t result
Result of callback.
Definition newgrf_profiling.h:43
NewGRFProfiler
Callback profiler for NewGRF development.
Definition newgrf_profiling.h:22
NewGRFProfiler::RecursiveResolve
void RecursiveResolve()
Capture a recursive sprite group resolution.
Definition newgrf_profiling.cpp:98
NewGRFProfiler::StartTimer
static void StartTimer(uint64_t ticks)
Start the timeout timer that will finish all profiling sessions.
Definition newgrf_profiling.cpp:188
NewGRFProfiler::EndResolve
void EndResolve(const ResolverResult &result)
Capture the completion of a sprite group resolution.
Definition newgrf_profiling.cpp:63
NewGRFProfiler::~NewGRFProfiler
~NewGRFProfiler()
Complete profiling session and write data to file.
Definition newgrf_profiling.cpp:40
NewGRFProfiler::cur_call
Call cur_call
Data for current call in progress.
Definition newgrf_profiling.h:54
NewGRFProfiler::active
bool active
Is this profiler collecting data.
Definition newgrf_profiling.h:52
NewGRFProfiler::grffile
const GRFFile * grffile
Which GRF is being profiled.
Definition newgrf_profiling.h:51
NewGRFProfiler::start_tick
uint64_t start_tick
Tick number this profiler was started on.
Definition newgrf_profiling.h:53
NewGRFProfiler::AbortTimer
static void AbortTimer()
Abort the timeout timer, so the timer callback is never called.
Definition newgrf_profiling.cpp:196
NewGRFProfiler::BeginResolve
void BeginResolve(const ResolverObject &resolver)
Capture the start of a sprite group resolution.
Definition newgrf_profiling.cpp:48
NewGRFProfiler::calls
std::vector< Call > calls
All calls collected so far.
Definition newgrf_profiling.h:55
NewGRFProfiler::GetOutputFilename
std::string GetOutputFilename() const
Get name of the file that will be written.
Definition newgrf_profiling.cpp:152
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
timer_game_calendar.h
Definition of the game-calendar-timer.