diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/common/Profiler.h | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/common/Profiler.h')
-rw-r--r-- | Src/external_dependencies/openmpt-trunk/common/Profiler.h | 128 |
1 files changed, 128 insertions, 0 deletions
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 <string> +#include <vector> + + +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<std::string> GetCategoryNames() + { + std::vector<std::string> 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<double> 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<std::string> GetCategoryNames() { return std::vector<std::string>(); } +public: + static void Update() { } + static std::string DumpProfiles() { return std::string(); } + static std::vector<double> DumpCategories() { return std::vector<double>(); } +}; +#define OPENMPT_PROFILE_SCOPE(cat, name) do { } while(0) +#define OPENMPT_PROFILE_FUNCTION(cat) do { } while(0) + + +#endif // USE_PROFILER + + +OPENMPT_NAMESPACE_END |