1 #ifndef MSP_DEBUG_PROFILER_H_
2 #define MSP_DEBUG_PROFILER_H_
7 #include <msp/time/timedelta.h>
8 #include <msp/time/timestamp.h>
16 A class for collecting timing data from a program. It's not as efficient as
17 external profilers, but allows profiling of custom scopes and retrieving the
18 profiling data at run time. An example usage could be showing realtime
19 performance statistics of a game or a simulation.
21 Data can be recorded by creating a ProfilingScope object in the scope to be
24 Note: This is not thread-safe. To profile multiple threads, create a separate
25 Profiler for each thread.
32 Msp::Time::TimeStamp entry_time;
33 Msp::Time::TimeDelta duration;
38 Time::TimeStamp first_call;
40 Time::TimeDelta total_time;
41 Time::TimeDelta self_time;
42 Time::TimeDelta avg_time;
44 std::vector<CallInfo> history;
47 std::map<std::string, unsigned> called_from;
54 std::map<std::string, ScopeInfo> scopes;
55 ProfilingScope *inner;
60 /** Sets the averaging period for timing data, measured in calls. Previous
61 average timings are cleared. */
62 void set_period(unsigned p);
64 /** Adds a scope without recording any calls to it. Useful if you might
65 need to access a scope before it has finished for the first time. */
66 void add_scope(const std::string &name);
68 /** Changes the recorded innermost scope pointer and returns the old one.
69 This is used by ProfilingScope to track child time and should not be called
71 ProfilingScope *enter(ProfilingScope *ps);
73 /** Records the data from a ProfilingScope. It is not useful to call this
75 void record(const ProfilingScope &);
77 /** Returns informations about a scope. */
78 const ScopeInfo &get_scope(const std::string &) const;