]> git.tdb.fi Git - libs/core.git/blobdiff - source/debug/profiler.h
Make Profiler able to report number of calls per second
[libs/core.git] / source / debug / profiler.h
index f2d5812da30befafb53914168eeb4237c2966b1c..ad0653c0697f566b31f356974733293277d6e63b 100644 (file)
@@ -1,17 +1,11 @@
-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_DEBUG_PROFILER_H_
 #define MSP_DEBUG_PROFILER_H_
 
 #include <map>
 #include <string>
 #include <vector>
-#include "../time/timedelta.h"
+#include <msp/time/timedelta.h>
+#include <msp/time/timestamp.h>
 
 namespace Msp {
 namespace Debug {
@@ -32,14 +26,23 @@ Profiler for each thread.
 class Profiler
 {
 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<Time::TimeDelta> history;
+               float calls_per_sec;
+               std::vector<CallInfo> history;
                unsigned hist_pos;
+               bool hist_full;
                std::map<std::string, unsigned> called_from;
 
                ScopeInfo();
@@ -72,21 +75,14 @@ public:
        */
        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);
+       /** 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 &scope(const std::string &) const;
+       const ScopeInfo &get_scope(const std::string &) const;
 };
 
 } // namespace Debug