1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 12:03:07 +01:00

Implement profiler (#16194)

* Implement profiling API

* Add console commands for the profiler

* Remove accidental line

* Correct csv output

* Add copyright notice

* Add missing override

* Add default virtual destructor

* Explicitly pass template argument

* Use static

* Add plugin API for profiler

* Add more profile calls

* Workaround for GCC hopefully

* Add missing static keyword

* Use uint64 for call count

* Reduce name length see if CI passes

* Improve handling of function names

* Work around (broken) static inline variables

* Fix missing include

* Disable profiler for clang 5 and older

* Update copyright date

* Profile UpdateAllMiscEntities

* Apply review suggestions

Co-authored-by: Ted John <ted@brambles.org>
This commit is contained in:
ζeh Matt
2022-01-18 10:21:20 -08:00
committed by GitHub
parent e78704f48f
commit 993b168bfd
28 changed files with 678 additions and 8 deletions

View File

@@ -45,6 +45,7 @@
#include "../object/ObjectManager.h"
#include "../object/ObjectRepository.h"
#include "../platform/platform.h"
#include "../profiling/Profiling.h"
#include "../ride/Ride.h"
#include "../ride/RideData.h"
#include "../ride/Vehicle.h"
@@ -1725,6 +1726,53 @@ static int32_t cc_add_news_item([[maybe_unused]] InteractiveConsole& console, [[
return 0;
}
static int32_t cc_profiler_reset([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
OpenRCT2::Profiling::ResetData();
return 0;
}
static int32_t cc_profiler_start([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (!OpenRCT2::Profiling::IsEnabled())
console.WriteLine("Started profiler");
OpenRCT2::Profiling::Enable();
return 0;
}
static int32_t cc_profiler_exportcsv([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (argv.size() < 1)
{
console.WriteLineError("Missing argument: <file path>");
return 1;
}
const auto& csvFilePath = argv[0];
if (!OpenRCT2::Profiling::ExportCSV(csvFilePath))
{
console.WriteFormatLine("Unable to export CSV file to %s", csvFilePath.c_str());
return 1;
}
console.WriteFormatLine("Wrote file CSV file: \"%s\"", csvFilePath.c_str());
return 0;
}
static int32_t cc_profiler_stop([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (OpenRCT2::Profiling::IsEnabled())
console.WriteLine("Stopped profiler");
OpenRCT2::Profiling::Disable();
// Export to CSV if argument is provided.
if (argv.size() >= 1)
{
return cc_profiler_exportcsv(console, argv);
}
return 0;
}
using console_command_func = int32_t (*)(InteractiveConsole& console, const arguments_t& argv);
struct console_command
{
@@ -1829,6 +1877,10 @@ static constexpr const console_command console_command_table[] = {
"replay_normalise <input file> <output file>" },
{ "mp_desync", cc_mp_desync, "Forces a multiplayer desync",
"cc_mp_desync [desync_type, 0 = Random t-shirt color on random guest, 1 = Remove random guest ]" },
{ "profiler_reset", cc_profiler_reset, "Resets the profiler data.", "profiler_reset" },
{ "profiler_start", cc_profiler_start, "Starts the profiler.", "profiler_start" },
{ "profiler_stop", cc_profiler_stop, "Stops the profiler.", "profiler_stop [<output file>]" },
{ "profiler_exportcsv", cc_profiler_exportcsv, "Exports the current profiler data.", "profiler_exportcsv <output file>" },
};
static int32_t cc_windows(InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)