1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-27 00:34:46 +01:00
Files
OpenRCT2/src/openrct2/profiling/ProfilingMacros.hpp
ζeh Matt 993b168bfd 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>
2022-01-18 20:21:20 +02:00

43 lines
2.4 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2022 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
namespace OpenRCT2::Profiling
{
#if defined(__clang__) || defined(__GNUC__)
# define PROFILING_FUNC_NAME __PRETTY_FUNCTION__
#elif defined(_MSC_VER)
# define PROFILING_FUNC_NAME __FUNCSIG__
#else
# error "Unsupported compiler"
#endif
#define PROFILED_FUNCTION_NAME(func) \
static constexpr auto _profiling_func_name = func; \
struct Profiler_FunctionLiteral \
{ \
static constexpr const char* Str() \
{ \
return _profiling_func_name; \
} \
};
#if defined(__clang_major__) && __clang_major__ <= 5
// Clang 5 crashes using the profiler, we need to disable it.
# define PROFILED_FUNCTION()
#else
# define PROFILED_FUNCTION() \
PROFILED_FUNCTION_NAME(PROFILING_FUNC_NAME) \
static auto& _profiling_func = ::OpenRCT2::Profiling::Detail::Storage<Profiler_FunctionLiteral>::Data; \
::OpenRCT2::Profiling::ScopedProfiling<decltype(_profiling_func)> _profiling_scope(_profiling_func);
#endif
} // namespace OpenRCT2::Profiling