docs/logging_and_performance_metrics.md
OpenTTD is a complex program, and together with NewGRF, it may show a buggy behaviour. But not only bugs in code can cause problems. There are several ways to affect game state possibly resulting in program crash or multiplayer desyncs.
Easier way would be to forbid all these unsafe actions, but that would affect game usability for many players. We certainly do not want that. However, we receive bug reports because of this. To reduce time spent with solving these problems, these potentially unsafe actions are logged in the savegame (including crash.sav). Log is stored in crash logs, too.
Information logged:
No personal information is stored.
You can show the game log by typing 'gamelog' in the console or by running OpenTTD in debug mode.
The Help menu in-game has a function to open the Frame rate window. This window shows various real-time performance statistics, measuring what parts of the game require the most processing power currently.
A summary of the statistics can also be retrieved from the console with the
fps command. This is especially useful on dedicated servers, where the
administrator might want to determine what's limiting performance in a slow
game.
The frame rate is given as two figures, the simulation rate and the graphics frame rate. Usually these are identical, as the screen is rendered exactly once per simulated tick, but in the future there might be support for graphics and simulation running at different rates. When the game is paused, the simulation rate drops to zero.
In addition to the simulation rate, a game speed factor is also calculated. This is based on the target simulation speed, which is 30 milliseconds per game tick. At that speed, the expected frame rate is 33.33 frames/second, and the game speed factor is how close to that target the actual rate is. When the game is in fast forward mode, the game speed factor shows how much speed up is achieved.
The lower part of the window shows timing statistics for individual parts of the game. The times shown are short-term and long-term averages of how long it takes to process one tick of game time, all figures are in milliseconds.
Clicking a line in the lower part of the window opens a graph window, giving detailed readings on each tick simulated by the game.
The following is an explanation of the different statistics:
If the frame rate window is shaded, the title bar will instead show just the current simulation rate and the game speed factor.
NewGRF developers can profile callback chains via the newgrf_profile
console command. The command controls a profiling mode where every sprite
request is measured and logged, and written to a CSV file in the end.
The NewGRF developer tools need to be enabled for the command to function.
View the syntax for the command in-game with the console command
help newgrf_profile.
Profiling only works during game or in the editor, it's not possible to profile across the main menu, world generation, or loading savegames.
The CSV files contain one line per sprite request during the profiling. They can get very large, especially on large games with many objects from the GRF. Start profiling short periods such as 3 or 7 days, and watch the file sizes.
The produced CSV file contains the following fields:
newgrf_callbacks.h file in the OpenTTD source code for the
full list of callback IDs.