From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- .../openmpt-trunk/common/Profiler.h | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Src/external_dependencies/openmpt-trunk/common/Profiler.h (limited to 'Src/external_dependencies/openmpt-trunk/common/Profiler.h') diff --git a/Src/external_dependencies/openmpt-trunk/common/Profiler.h b/Src/external_dependencies/openmpt-trunk/common/Profiler.h new file mode 100644 index 00000000..1b429f32 --- /dev/null +++ b/Src/external_dependencies/openmpt-trunk/common/Profiler.h @@ -0,0 +1,128 @@ +/* + * Profiler.h + * ---------- + * Purpose: Performance measuring + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + +#include "openmpt/all/BuildSettings.hpp" + + +#include "mpt/mutex/mutex.hpp" + +#include +#include + + +OPENMPT_NAMESPACE_BEGIN + + +#if defined(MODPLUG_TRACKER) + +//#define USE_PROFILER + +#endif + +#ifdef USE_PROFILER + +class Profiler +{ +public: + enum Category + { + GUI, + Audio, + Notify, + CategoriesCount + }; + static std::vector GetCategoryNames() + { + std::vector ret; + ret.push_back("GUI"); + ret.push_back("Audio"); + ret.push_back("Notify"); + return ret; + } +public: + static void Update(); + static std::string DumpProfiles(); + static std::vector DumpCategories(); +}; + + +class Profile +{ +private: + mutable mpt::mutex datamutex; +public: + struct Data + { + uint64 Calls; + uint64 Sum; + int64 Overhead; + uint64 Start; + }; +public: + Data data; + uint64 EnterTime; + Profiler::Category Category; + const char * const Name; + uint64 GetTime() const; + uint64 GetFrequency() const; +public: + Profile(Profiler::Category category, const char *name); + ~Profile(); + void Reset(); + void Enter(); + void Leave(); + class Scope + { + private: + Profile &profile; + public: + Scope(Profile &p) : profile(p) { profile.Enter(); } + ~Scope() { profile.Leave(); } + }; +public: + Data GetAndResetData(); +}; + + +#define OPENMPT_PROFILE_SCOPE(cat, name) \ + static Profile OPENMPT_PROFILE_VAR(cat, name);\ + Profile::Scope OPENMPT_PROFILE_SCOPE_VAR(OPENMPT_PROFILE_VAR); \ +/**/ + + +#define OPENMPT_PROFILE_FUNCTION(cat) OPENMPT_PROFILE_SCOPE(cat, __func__) + + +#else // !USE_PROFILER + + +class Profiler +{ +public: + enum Category + { + CategoriesCount + }; + static std::vector GetCategoryNames() { return std::vector(); } +public: + static void Update() { } + static std::string DumpProfiles() { return std::string(); } + static std::vector DumpCategories() { return std::vector(); } +}; +#define OPENMPT_PROFILE_SCOPE(cat, name) do { } while(0) +#define OPENMPT_PROFILE_FUNCTION(cat) do { } while(0) + + +#endif // USE_PROFILER + + +OPENMPT_NAMESPACE_END -- cgit