123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- /*
- * 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
|