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