- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/include/frost_utils_profiler.h

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*            Profiler header             */
    00005 /*                                        */
    00006 /*                                        */
    00007
    00008
    00009 #ifndef FROST_PROFILER_H
    00010 #define FROST_PROFILER_H
    00011
    00012 #include "frost_utils_types.h"
    00013
    00014 namespace Frost
    00015 {
    00016     /// The profiling class
    00017     /** A profiler should be assigned to a single
    00018     *   function or portion of code. It will accumulate
    00019     *   timings from every Chrono created from it.
    00020     */
    00021     class Profiler
    00022     {
    00023     public :
    00024
    00025         /// Default constructor.
    00026         Profiler();
    00027
    00028         /// Constructor.
    00029         /** \param iGroup  The group to which it belongs (used to group prints later)
    00030         *   \param sName   The name of this Profiler (usualy the name of the function
    00031         *                it profiles)
    00032         *   \param bRecord Store all timings in a list to print them later
    00033         */
    00034         Profiler(const s_uint& iGroup, const s_str& sName, const s_bool& bRecord);
    00035
    00036         /// Adds a timing.
    00037         /** \param dTiming The timing
    00038         */
    00039         void          AddTiming(const s_double& dTiming);
    00040
    00041         /// Prints timing infos.
    00042         /** \param dTotal The total profiling time, used to calculate percentages.
    00043         */
    00044         void          PrintProfile(const s_double& dTotal);
    00045
    00046         /// Switches timings recording.
    00047         void          SetKeepRecords(const s_bool& bRecord);
    00048
    00049         /// Returns this profiler's group.
    00050         /** \return This Profiler's group
    00051         */
    00052         const s_uint& GetGroup();
    00053
    00054         static const s_str CLASS_NAME;
    00055
    00056     private :
    00057
    00058         s_str    sName_;
    00059         s_uint   uiGroup_;
    00060         s_double dStartTime_;
    00061         s_double dTotalTime_;
    00062         s_double dHighestTime_;
    00063         s_double dLowestTime_;
    00064         s_uint   uiCallNbr_;
    00065         s_uint   uiZeroTimings_;
    00066         s_bool   bRecord_;
    00067
    00068         std::vector<s_double> lRecordStack_;
    00069     };
    00070
    00071     /// An automatic timer
    00072     /** This timer starts when you create it and ends
    00073     *   at destruction or when you call Stop().<br>
    00074     *   So, to use it, the simplest way is to call :<br>
    00075     *       Chrono c = Chrono(TimeManager::GetProfiler(...));<br>
    00076     *   And when c will be destroyed, it will add a timing
    00077     *   to the profiler you gave in the constructor.<br>
    00078     *   Note : This class should only be used for profiling
    00079     *   purposes.
    00080     */
    00081     class Chrono
    00082     {
    00083     public :
    00084
    00085         /// Constructor.
    00086         /** \param pProfiler The profiler that will be linked to this Chrono
    00087         *   \param bStart    'true' to make it start immediately
    00088         */
    00089         Chrono(s_ptr<Profiler> pProfiler, const s_bool& bStart = true);
    00090
    00091         /// Destructor.
    00092         ~Chrono();
    00093
    00094         /// Returns the time elapsed since its creation.
    00095         /** \return Elapsed time since its creation
    00096         */
    00097         s_double GetTime();
    00098
    00099         /// Restarts a timer after it has been stopped.
    00100         void     Start();
    00101
    00102         /// Stops this timer and add its timing to the profiler.
    00103         /** \param bSend If set to false, the timer will only be
    00104         *   paused and won't send data to the profiler.
    00105         */
    00106         void     Stop(const s_bool& bSend = true);
    00107
    00108         static const s_str CLASS_NAME;
    00109
    00110     private :
    00111
    00112         s_ptr<Profiler> pParent_;
    00113         s_double        dStart_;
    00114         s_double        dTotal_;
    00115         s_bool          bStopped_;
    00116     };
    00117 }
    00118
    00119 #endif