Feature: NewGRF callback profiling (#7868)

Adds a console command newgrf_profile to collect some profiling data about NewGRF action 2 callbacks and produce a CSV file.
This commit is contained in:
Niels Martin Hansen
2020-01-26 13:45:51 +01:00
committed by GitHub
parent f88ac83408
commit c8779fb311
40 changed files with 691 additions and 20 deletions

View File

@@ -11,6 +11,7 @@
#include <algorithm>
#include "debug.h"
#include "newgrf_spritegroup.h"
#include "newgrf_profiling.h"
#include "core/pool_func.hpp"
#include "safeguards.h"
@@ -34,10 +35,23 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
/* static */ const SpriteGroup *SpriteGroup::Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level)
{
if (group == nullptr) return nullptr;
if (top_level) {
const GRFFile *grf = object.grffile;
auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](const NewGRFProfiler &pr) { return pr.grffile == grf; });
if (profiler == _newgrf_profilers.end() || !profiler->active) {
if (top_level) _temp_store.ClearChanges();
return group->Resolve(object);
} else if (top_level) {
profiler->BeginResolve(object);
_temp_store.ClearChanges();
const SpriteGroup *result = group->Resolve(object);
profiler->EndResolve(result);
return result;
} else {
profiler->RecursiveResolve();
return group->Resolve(object);
}
return group->Resolve(object);
}
RealSpriteGroup::~RealSpriteGroup()