/* * Chronos.hpp * * Created on: Mar 14, 2011 * Author: heber */ #ifndef CHRONOS_HPP_ #define CHRONOS_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "CodePatterns/Singleton.hpp" class ChronosTest; class Chronos : public Singleton{ //!> Singleton pattern needs private access friend class Singleton; //!> unit tests needs access to private members friend class ChronosTest; //!> operator needs to access some internals friend std::ostream& operator<<(std::ostream &ost, const Chronos &_time); public : /** Returns current kept time of function \a _name. * * @param _name name of function * @return current amount of time passed for this function, 0 if unknown, -1 if currently running */ double getTime(const std::string _name) const; /** Resets time counter for this function \a _name to zero. * * @param _name name of function */ void resetTime(const std::string _name); /** Starts Timing for this function \a _name. * * @param _name name of function */ void startTiming(const std::string _name); /** Finishes Timing for this function \a _name. * * @param _name name of function */ void endTiming(const std::string _name); /** Sums up total time accounted for. * * @return total time in seconds */ double SumUpTotalTime() const; /** Sums up all functions accounted. * * @return number of functions */ size_t SumUpTotalFunctions() const; protected: /** Do not call this constructor directly, use getInstance() instead. */ Chronos(); /** Do not call this destructor directly, use purgeInstance() instead. */ ~Chronos(); private: /** Returns the current timer in seconds. * * This function is present to allow for changing of time measurements * without the other functions noticing. * * \note We convert clock() by CLOCKS_PER_SEC. * \note We convert struct tms::tms_utime by _SC_CLK_TCK via sysconf(). * * @return current time in unit of seconds */ double getCurrentTime() const; typedef std::map TimekeepingMap; typedef std::map TimerStatusMap; TimekeepingMap AccountedTime; TimerStatusMap TimeRunning; }; /** Output for Chronos. * * @param ost output stream * @param _time Chronos to print * @return reference to given output stream for concatenation */ std::ostream& operator<<(std::ostream &ost, const Chronos &_time); #endif /* CHRONOS_HPP_ */