X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fdebug%2Fprofiler.h;h=521ce959c5de7cae234c04ae8de5861ac3f6b42e;hp=7f88dd2c099620189168ed8ed11645d385bed942;hb=292aed8e23ea543b089d5f2a73000de4640befe7;hpb=d16185720fa344263367dbd50c61bfc8183d99a4 diff --git a/source/debug/profiler.h b/source/debug/profiler.h index 7f88dd2..521ce95 100644 --- a/source/debug/profiler.h +++ b/source/debug/profiler.h @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include namespace Msp { namespace Debug { @@ -17,22 +19,32 @@ external profilers, but allows profiling of custom scopes and retrieving the profiling data at run time. An example usage could be showing realtime performance statistics of a game or a simulation. -See also class ProfilingScope. +Data can be recorded by creating a ProfilingScope object in the scope to be +profiled. Note: This is not thread-safe. To profile multiple threads, create a separate Profiler for each thread. */ -class Profiler +class Profiler: private NonCopyable { public: + struct CallInfo + { + Msp::Time::TimeStamp entry_time; + Msp::Time::TimeDelta duration; + }; + struct ScopeInfo { + Time::TimeStamp first_call; unsigned calls; Time::TimeDelta total_time; Time::TimeDelta self_time; Time::TimeDelta avg_time; - std::vector history; + float calls_per_sec; + std::vector history; unsigned hist_pos; + bool hist_full; std::map called_from; ScopeInfo(); @@ -46,40 +58,25 @@ private: public: Profiler(); - /** - Sets the averaging period for timing data, measured in calls. Previous - average timings are cleared. - */ + /** Sets the averaging period for timing data, measured in calls. Previous + average timings are cleared. */ void set_period(unsigned p); - /** - Adds a scope without recording any calls to it. Useful if you might need to - access a scope before it has finished for the first time. - */ + /** Adds a scope without recording any calls to it. Useful if you might + need to access a scope before it has finished for the first time. */ void add_scope(const std::string &name); - /** - Changes the recorded innermost scope pointer and returns the old one. This - is used by ProfilingScope to track child time and should not be called - manually. - */ + /** Changes the recorded innermost scope pointer and returns the old one. + This is used by ProfilingScope to track child time and should not be called + manually. */ ProfilingScope *enter(ProfilingScope *ps); - /** - Records a call to a scope. You'll probably want to use a ProfilingScope - instead of calling this manually. - - @param sn Scope name - @param pn Parent scope name - @param t Time spent in the scope - @param ct Time spent in child scopes - */ - void record(const std::string &sn, const std::string &pn, const Time::TimeDelta &t, const Time::TimeDelta &ct); - - /** - Returns informations about a scope. - */ - const ScopeInfo &scope(const std::string &) const; + /** Records the data from a ProfilingScope. It is not useful to call this + manually. */ + void record(const ProfilingScope &); + + /** Returns informations about a scope. */ + const ScopeInfo &get_scope(const std::string &) const; }; } // namespace Debug