MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ConPrintFramerate

Function ConPrintFramerate

src/framerate_gui.cpp:999–1058  ·  view source on GitHub ↗

Print performance statistics to game console */

Source from the content-addressed store, hash-verified

997
998/** Print performance statistics to game console */
999void ConPrintFramerate()
1000{
1001 const int count1 = NUM_FRAMERATE_POINTS / 8;
1002 const int count2 = NUM_FRAMERATE_POINTS / 4;
1003 const int count3 = NUM_FRAMERATE_POINTS / 1;
1004
1005 IConsolePrint(TC_SILVER, "Based on num. data points: {} {} {}", count1, count2, count3);
1006
1007 static const std::array<std::string_view, PFE_MAX> MEASUREMENT_NAMES = {
1008 "Game loop",
1009 " GL station ticks",
1010 " GL train ticks",
1011 " GL road vehicle ticks",
1012 " GL ship ticks",
1013 " GL aircraft ticks",
1014 " GL landscape ticks",
1015 " GL link graph delays",
1016 "Drawing",
1017 " Viewport drawing",
1018 "Video output",
1019 "Sound mixing",
1020 "AI/GS scripts total",
1021 "Game script",
1022 };
1023 std::string ai_name_buf;
1024
1025 bool printed_anything = false;
1026
1027 for (const auto &e : { PFE_GAMELOOP, PFE_DRAWING, PFE_VIDEO }) {
1028 auto &pf = _pf_data[e];
1029 if (pf.num_valid == 0) continue;
1030 IConsolePrint(TC_GREEN, "{} rate: {:.2f}fps (expected: {:.2f}fps)",
1031 MEASUREMENT_NAMES[e],
1032 pf.GetRate(),
1033 pf.expected_rate);
1034 printed_anything = true;
1035 }
1036
1037 for (PerformanceElement e = PFE_FIRST; e < PFE_MAX; e++) {
1038 auto &pf = _pf_data[e];
1039 if (pf.num_valid == 0) continue;
1040 std::string_view name;
1041 if (e < PFE_AI0) {
1042 name = MEASUREMENT_NAMES[e];
1043 } else {
1044 ai_name_buf = fmt::format("AI {} {}", e - PFE_AI0 + 1, GetAIName(e - PFE_AI0));
1045 name = ai_name_buf;
1046 }
1047 IConsolePrint(TC_LIGHT_BLUE, "{} times: {:.2f}ms {:.2f}ms {:.2f}ms",
1048 name,
1049 pf.GetAverageDurationMilliseconds(count1),
1050 pf.GetAverageDurationMilliseconds(count2),
1051 pf.GetAverageDurationMilliseconds(count3));
1052 printed_anything = true;
1053 }
1054
1055 if (!printed_anything) {
1056 IConsolePrint(CC_ERROR, "No performance measurements have been taken yet.");

Callers 1

ConFramerateFunction · 0.85

Calls 5

GetAINameFunction · 0.85
GetRateMethod · 0.80
IConsolePrintFunction · 0.70
formatFunction · 0.50

Tested by

no test coverage detected