OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
21 std::vector<NewGRFProfiler> _newgrf_profilers;
22 Date _newgrf_profile_end_date;
47 using namespace std::chrono;
50 this->
cur_call.
time = (uint32)time_point_cast<microseconds>(high_resolution_clock::now()).time_since_epoch().count();
62 using namespace std::chrono;
63 this->
cur_call.
time = (uint32)time_point_cast<microseconds>(high_resolution_clock::now()).time_since_epoch().count() - this->
cur_call.
time;
65 if (result ==
nullptr) {
67 }
else if (result->type == SGT_CALLBACK) {
69 }
else if (result->type == SGT_RESULT) {
86 void NewGRFProfiler::Start()
93 uint32 NewGRFProfiler::Finish()
95 if (!this->
active)
return 0;
97 if (this->
calls.empty()) {
108 uint32 total_microseconds = 0;
110 fputs(
"Tick,Sprite,Feature,Item,CallbackID,Microseconds,Depth,Result\n", f);
111 for (
const Call &c : this->
calls) {
112 fprintf(f,
"%u,%u,0x%X,%u,0x%X,%u,%u,%u\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result);
113 total_microseconds += c.time;
118 return total_microseconds;
121 void NewGRFProfiler::Abort()
133 char timestamp[16] = {};
136 char filepath[MAX_PATH] = {};
139 return std::string(filepath);
142 uint32 NewGRFProfiler::FinishAll()
145 uint32 total_microseconds = 0;
148 total_microseconds += pr.Finish();
149 max_ticks = std::max(max_ticks,
_tick_counter - pr.start_tick);
153 if (total_microseconds > 0 && max_ticks > 0) {
154 IConsolePrint(
CC_DEBUG,
"Total NewGRF callback processing: {} microseconds over {} ticks.", total_microseconds, max_ticks);
157 _newgrf_profile_end_date =
MAX_DAY;
159 return total_microseconds;
std::vector< Call > calls
All calls collected so far.
const GRFFile * grffile
Which GRF is being profiled.
Interface for SpriteGroup-s to access the gamestate.
void RecursiveResolve()
Capture a recursive sprite group resolution.
NewGRFProfiler(const GRFFile *grffile)
Create profiler object and begin profiling session.
#define MAX_DAY
The number of days till the last day.
virtual GrfSpecFeature GetFeature() const
Get the feature number being resolved for.
virtual uint32 GetDebugID() const
Get an identifier for the item being resolved.
void EndResolve(const SpriteGroup *result)
Capture the completion of a sprite group resolution.
Auto-close a file upon scope exit.
void BeginResolve(const ResolverObject &resolver)
Capture the start of a sprite group resolution.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
~NewGRFProfiler()
Complete profiling session and write data to file.
int32 Date
The type to store our dates in.
GrfSpecFeature feat
GRF feature being resolved for.
uint32 result
Result of callback.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
uint32 item
Local ID of item being resolved for.
std::string GetOutputFilename() const
Get name of the file that will be written.
static const TextColour CC_DEBUG
Colour for debug output.
uint32 subs
Sub-calls to other sprite groups.
static size_t Format(char *buffer, const char *last, const char *format) NOACCESS(2) WARN_TIME_FORMAT(3)
Format the current time with the given strftime format specifiers.
bool active
Is this profiler collecting data.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Call cur_call
Data for current call in progress.
Callback profiler for NewGRF development.
@ NO_DIRECTORY
A path without any base directory.
uint16 start_tick
Tick number this profiler was started on.
uint32 GetSpriteLocalID(SpriteID sprite)
Get the GRF-local sprite id of a given sprite.
CallbackID callback
Callback being resolved.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
uint32 root_sprite
Pseudo-sprite index in GRF file.
uint32 time
Time taken for resolution (microseconds)
#define lastof(x)
Get the last element of an fixed size array.
CallbackID cb
Callback ID.
Dynamic data of a loaded NewGRF.
const char * FiosGetScreenshotDir()
Get the directory for screenshots.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.